diff options
author | Ola Aunronning <olaa@yahooinc.com> | 2023-09-20 16:12:38 +0200 |
---|---|---|
committer | Ola Aunronning <olaa@yahooinc.com> | 2023-09-20 16:12:38 +0200 |
commit | ffe7fd17d2d24b00ee01b5e8f26d07bff8f4bbe2 (patch) | |
tree | 561f0a180f7bc5b99ea2e79a7393aa13fd828b00 /config-provisioning | |
parent | 16050559773b552387bc702aa15c24ab30ece982 (diff) |
Add unit test for adding/subtracting resources
Diffstat (limited to 'config-provisioning')
-rw-r--r-- | config-provisioning/src/test/java/com/yahoo/config/provision/NodeResourcesTest.java | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/NodeResourcesTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/NodeResourcesTest.java index 230d28e04aa..71d20e5bbd2 100644 --- a/config-provisioning/src/test/java/com/yahoo/config/provision/NodeResourcesTest.java +++ b/config-provisioning/src/test/java/com/yahoo/config/provision/NodeResourcesTest.java @@ -67,19 +67,46 @@ public class NodeResourcesTest { @Test void benchmark() { - NodeResources [] resouces = new NodeResources[100]; - for (int i = 0; i < resouces.length; i++) { - resouces[i] = new NodeResources(1 / 3., 10 / 3., 100 / 3., 0.3); + NodeResources [] resources = new NodeResources[100]; + for (int i = 0; i < resources.length; i++) { + resources[i] = new NodeResources(1 / 3., 10 / 3., 100 / 3., 0.3); } int NUM_ITER = 100; // Use at least 100000 for proper benchmarking - long warmup = runTest(resouces, NUM_ITER); + long warmup = runTest(resources, NUM_ITER); long start = System.nanoTime(); - long benchmark = runTest(resouces, NUM_ITER); + long benchmark = runTest(resources, NUM_ITER); long duration = System.nanoTime() - start; System.out.println("NodeResources.toString() took " + duration / 1000000 + " ms"); assertEquals(warmup, benchmark); } + @Test + public void testJoiningResources() { + var resources = new NodeResources(1, 2, 3, 1, + NodeResources.DiskSpeed.fast, + NodeResources.StorageType.local, + NodeResources.Architecture.x86_64, + new NodeResources.GpuResources(4, 16)); + + assertNotInterchangeable(resources, resources.with(NodeResources.DiskSpeed.slow)); + assertNotInterchangeable(resources, resources.with(NodeResources.StorageType.remote)); + assertNotInterchangeable(resources, resources.with(NodeResources.Architecture.arm64)); + + var other = resources.with(new NodeResources.GpuResources(4, 32)); + var expected = resources.withVcpu(2) + .withMemoryGb(4) + .withDiskGb(6) + .withBandwidthGbps(2) + .with(new NodeResources.GpuResources(1, 192)); + var actual = resources.add(other); + assertEquals(expected, actual); + + // Subtracted back to original resources - but GPU is flattened to count=1 + expected = resources.with(new NodeResources.GpuResources(1, 64)); + actual = actual.subtract(other); + assertEquals(expected, actual); + } + private void assertInvalid(String valueName, Supplier<NodeResources> nodeResources) { try { nodeResources.get(); @@ -100,4 +127,14 @@ public class NodeResourcesTest { return sum; } + private void assertNotInterchangeable(NodeResources a, NodeResources b) { + try { + a.add(b); + fail(); + } + catch (IllegalArgumentException e) { + assertEquals(a + " and " + b + " are not interchangeable", e.getMessage()); + } + } + } |