Containers { public static void addCpuLimit(Container container, float cpuLimit) { final ResourceRequirementsBuilder resourceBuilder; if (container.getResources() != null) { resourceBuilder = new ResourceRequirementsBuilder(container.getResources()); } else { resourceBuilder = new ResourceRequirementsBuilder(); } container.setResources( resourceBuilder.addToLimits("cpu", new Quantity(Float.toString(cpuLimit))).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 testAddContainerCPULimitWhenResourceIsNull() { when(container.getResources()).thenReturn(null); Containers.addCpuLimit(container, CPU_LIMIT); verify(container).setResources(resourceCaptor.capture()); final ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("cpu").getAmount(), String.valueOf(CPU_LIMIT)); }
@Test public void testAddContainerCPULimitWhenResourceDoesNotContainAnyLimits() { when(resource.getLimits()).thenReturn(null); Containers.addCpuLimit(container, CPU_LIMIT); verify(container).setResources(resourceCaptor.capture()); final ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("cpu").getAmount(), String.valueOf(CPU_LIMIT)); }
@Test(dataProvider = "k8sNotionCpuLimitProvider") public void testAddContainerCPULimitInK8sNotion( String cpuLimit, String amount, String format, ResourceRequirements resources) { when(container.getResources()).thenReturn(resources); Containers.addCpuLimit(container, cpuLimit); verify(container).setResources(resourceCaptor.capture()); ResourceRequirements captured = resourceCaptor.getValue(); assertEquals(captured.getLimits().get("cpu").getAmount(), amount); assertEquals(captured.getLimits().get("cpu").getFormat(), format); }