Containers { public static void addRamLimit(Container container, long ramLimit) { final ResourceRequirementsBuilder resourceBuilder; if (container.getResources() != null) { resourceBuilder = new ResourceRequirementsBuilder(container.getResources()); } else { resourceBuilder = new ResourceRequirementsBuilder(); } container.setResources( resourceBuilder.addToLimits("memory", new Quantity(String.valueOf(ramLimit))).build()); } private  Containers(); static long getRamLimit(Container container); static void addRamLimit(Container container, long ramLimit); static void addRamLimit(Container container, String limitInK8sNotion); static long getRamRequest(Container container); static void addRamRequest(Container container, long ramRequest); static void addRamRequest(Container container, String limitInK8sNotion); static float getCpuLimit(Container container); static void addCpuLimit(Container container, float cpuLimit); static void addCpuLimit(Container container, String limitInK8sNotion); static float getCpuRequest(Container container); static void addCpuRequest(Container container, float cpuRequest); static void addCpuRequest(Container container, String limitInK8sNotion);  }
@Test public void testAddContainerRamLimitWhenResourceIsNull() { when(container.getResources()).thenReturn(null); Containers.addRamLimit(container, RAM_LIMIT); verify(container).setResources(resourceCaptor.capture()); final ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("memory").getAmount(), String.valueOf(RAM_LIMIT)); }
@Test public void testAddContainerRamLimitWhenResourceDoesNotContainAnyLimits() { when(resource.getLimits()).thenReturn(null); Containers.addRamLimit(container, RAM_LIMIT); verify(container).setResources(resourceCaptor.capture()); final ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("memory").getAmount(), String.valueOf(RAM_LIMIT)); }
@Test(dataProvider = "k8sNotionRamLimitProvider") public void testAddContainerRamLimitInK8sNotion( String ramLimit, String amount, String format, ResourceRequirements resources) { when(container.getResources()).thenReturn(resources); Containers.addRamLimit(container, ramLimit); verify(container).setResources(resourceCaptor.capture()); ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("memory").getAmount(), amount); assertEquals(captured.getLimits().get("memory").getFormat(), format); }