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(); double[] getPercentages();  }
@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)); assertThat(configurableResource.getResource().getMemorySize()). isEqualTo(3072); assertThat(configurableResource.getResource().getVirtualCores()). isEqualTo(3); assertEquals( configurableResource.getResource(clusterResource).getMemorySize(), 3072); assertEquals( configurableResource.getResource(clusterResource).getVirtualCores(), 3); assertThat(configurableResource.getResource(null).getMemorySize()). isEqualTo(3072); assertThat(configurableResource.getResource(null).getVirtualCores()). isEqualTo(3); }