1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// Copyright Yahoo. 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());
}
}
}
|