ConfigurableResource { public Resource getResource(Resource clusterResource) { if (percentages != null && clusterResource != null) { long memory = (long) (clusterResource.getMemorySize() * percentages[0]); int vcore = (int) (clusterResource.getVirtualCores() * percentages[1]); Resource res = Resource.newInstance(memory, vcore); ResourceInformation[] clusterInfo = clusterResource.getResources(); for (int i = 2; i < clusterInfo.length; i++) { res.setResourceValue(i, (long)(clusterInfo[i].getValue() * percentages[i])); } return res; } else { return resource; } } ConfigurableResource();   ConfigurableResource(double[] percentages);   ConfigurableResource(long value);  ConfigurableResource(Resource resource); Resource getResource(Resource clusterResource); Resource getResource();  }
@Test public void testGetResourceWithPercentage() { ConfigurableResource configurableResource = new ConfigurableResource(new double[] {0.5, 0.5}); assertEquals( configurableResource.getResource(clusterResource).getMemorySize(), 1024); assertEquals( configurableResource.getResource(clusterResource).getVirtualCores(), 1); assertNull("The absolute resource should be null since object" + " configurableResource is initialized with percentages", configurableResource.getResource()); assertNull("The absolute resource should be null since cluster resource" + " is null", configurableResource.getResource(null)); }
@Test public void testGetResourceWithAbsolute() { ConfigurableResource configurableResource = new ConfigurableResource(Resources.createResource(3072, 3)); assertEquals(configurableResource.getResource().getMemorySize(), 3072); assertEquals(configurableResource.getResource().getVirtualCores(), 3); assertEquals( configurableResource.getResource(clusterResource).getMemorySize(), 3072); assertEquals( configurableResource.getResource(clusterResource).getVirtualCores(), 3); assertEquals(configurableResource.getResource(null).getMemorySize(), 3072); assertEquals(configurableResource.getResource(null).getVirtualCores(), 3); }