diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-26 11:11:29 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2020-03-26 11:15:28 +0100 |
commit | c70cc1e1e3bbfde0ecbe2b712dc7b65beb228dd3 (patch) | |
tree | d42629e789961172a251911502f97221cbe14450 /config-provisioning/src/test | |
parent | 3e5be1fb5216c057c2d631149cb2cf3a20fde674 (diff) |
Validate size
Diffstat (limited to 'config-provisioning/src/test')
-rw-r--r-- | config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java b/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java new file mode 100644 index 00000000000..326ed7317f6 --- /dev/null +++ b/config-provisioning/src/test/java/com/yahoo/config/provision/CapacityTest.java @@ -0,0 +1,48 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.provision; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * @author bratseth + */ +public class CapacityTest { + + @Test + public void testCapacityValidation() { + // Equal min and max is allowed + Capacity.from(new ClusterResources(4, 2, new NodeResources(1,2,3,4)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4)), + false, true); + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1,2,3,4)), + new ClusterResources(2, 2, new NodeResources(1,2,3,4))); + assertValidationFailure(new ClusterResources(4, 4, new NodeResources(1,2,3,4)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4))); + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(2,2,3,4)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4))); + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1,3,3,4)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4))); + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1,2,4,4)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4))); + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1,2,3,5)), + new ClusterResources(4, 2, new NodeResources(1,2,3,4))); + // It's enough than one dimension is smaller also when the others are larger + assertValidationFailure(new ClusterResources(4, 2, new NodeResources(1,2,3,4)), + new ClusterResources(8, 4, new NodeResources(2,1,6,8))); + } + + private void assertValidationFailure(ClusterResources min, ClusterResources max) { + try { + Capacity.from(min, max, false, true); + fail("Expected exception with min " + min + " and max " + max); + } + catch (IllegalArgumentException e) { + assertEquals("The max capacity must be larger than the min capacity, but got min " + min + " and max " + max, + e.getMessage()); + } + } + +} |