summaryrefslogtreecommitdiffstats
path: root/vdslib/src/test/java/com/yahoo
diff options
context:
space:
mode:
Diffstat (limited to 'vdslib/src/test/java/com/yahoo')
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java4
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/SearchResultTestCase.java18
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java21
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestCase.java23
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java26
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java2
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java107
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java53
-rw-r--r--vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java34
9 files changed, 141 insertions, 147 deletions
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java
index 7257bf0cc7f..59b5a7ae55a 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/BucketDistributionTestCase.java
@@ -25,7 +25,7 @@ public class BucketDistributionTestCase {
BucketDistribution bd = new BucketDistribution(NUM_COLUMNS, numBucketBits);
for (int i = 0; i < bd.getNumBuckets(); ++i) {
if (i % 32 == 0) {
- System.out.println("");
+ System.out.println();
System.out.print(" ");
}
System.out.print(bd.getColumn(new BucketId(16, i)));
@@ -37,7 +37,7 @@ public class BucketDistributionTestCase {
if (numBucketBits < MAX_BUCKETBITS) {
System.out.print(",");
}
- System.out.println("");
+ System.out.println();
}
System.out.println(" };");
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/SearchResultTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/SearchResultTestCase.java
index 3f3e8fd0f8b..b675798b374 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/SearchResultTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/SearchResultTestCase.java
@@ -17,12 +17,12 @@ public class SearchResultTestCase {
SearchResult.Hit b = new SearchResult.Hit("b", 0.1);
SearchResult.Hit c = new SearchResult.Hit("c", 1.0);
SearchResult.Hit bb = new SearchResult.Hit("b2", 0.1);
- assertTrue(a.compareTo(a) == 0);
+ assertEquals(0, a.compareTo(a));
assertTrue(a.compareTo(b) > 0);
assertTrue(a.compareTo(c) > 0);
assertTrue(b.compareTo(a) < 0);
- assertTrue(b.compareTo(bb) == 0);
- assertTrue(bb.compareTo(b) == 0);
+ assertEquals(0, b.compareTo(bb));
+ assertEquals(0, bb.compareTo(b));
assertTrue(b.compareTo(c) > 0);
assertTrue(c.compareTo(a) < 0);
assertTrue(c.compareTo(b) < 0);
@@ -47,7 +47,7 @@ public class SearchResultTestCase {
SearchResult.Hit h5 = new SearchResult.HitWithSortBlob(a, b5);
SearchResult.Hit h6 = new SearchResult.HitWithSortBlob(a, b6);
- assertTrue(h1.compareTo(h1) == 0);
+ assertEquals(0, h1.compareTo(h1));
assertTrue(h1.compareTo(h2) < 0);
assertTrue(h1.compareTo(h3) < 0);
assertTrue(h1.compareTo(h4) < 0);
@@ -55,7 +55,7 @@ public class SearchResultTestCase {
assertTrue(h1.compareTo(h6) < 0);
assertTrue(h2.compareTo(h1) > 0);
- assertTrue(h2.compareTo(h2) == 0);
+ assertEquals(0, h2.compareTo(h2));
assertTrue(h2.compareTo(h3) < 0);
assertTrue(h2.compareTo(h4) < 0);
assertTrue(h2.compareTo(h5) < 0);
@@ -63,7 +63,7 @@ public class SearchResultTestCase {
assertTrue(h3.compareTo(h1) > 0);
assertTrue(h3.compareTo(h2) > 0);
- assertTrue(h3.compareTo(h3) == 0);
+ assertEquals(0, h3.compareTo(h3));
assertTrue(h3.compareTo(h4) < 0);
assertTrue(h3.compareTo(h5) < 0);
assertTrue(h3.compareTo(h6) < 0);
@@ -71,7 +71,7 @@ public class SearchResultTestCase {
assertTrue(h4.compareTo(h1) > 0);
assertTrue(h4.compareTo(h2) > 0);
assertTrue(h4.compareTo(h3) > 0);
- assertTrue(h4.compareTo(h4) == 0);
+ assertEquals(0, h4.compareTo(h4));
assertTrue(h4.compareTo(h5) < 0);
assertTrue(h4.compareTo(h6) < 0);
@@ -79,7 +79,7 @@ public class SearchResultTestCase {
assertTrue(h5.compareTo(h2) > 0);
assertTrue(h5.compareTo(h3) > 0);
assertTrue(h5.compareTo(h4) > 0);
- assertTrue(h5.compareTo(h5) == 0);
+ assertEquals(0, h5.compareTo(h5));
assertTrue(h5.compareTo(h6) < 0);
assertTrue(h6.compareTo(h1) > 0);
@@ -87,6 +87,6 @@ public class SearchResultTestCase {
assertTrue(h6.compareTo(h3) > 0);
assertTrue(h6.compareTo(h4) > 0);
assertTrue(h6.compareTo(h5) > 0);
- assertTrue(h6.compareTo(h6) == 0);
+ assertEquals(0, h6.compareTo(h6));
}
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java
index 70a11ff530f..90128c7c04b 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/CrossPlatformTestFactory.java
@@ -20,36 +20,29 @@ public abstract class CrossPlatformTestFactory {
public String getName() { return name; }
- public boolean loadTestResults() throws Exception {
+ public void loadTestResults() throws Exception {
File reference = new File(directory, name + ".reference.results");
if (!reference.exists()) {
- return false;
+ return;
}
- BufferedReader br = new BufferedReader(new FileReader(reference));
- StringBuilder sb = new StringBuilder();
- try{
- while(true) {
+ try (BufferedReader br = new BufferedReader(new FileReader(reference))) {
+ StringBuilder sb = new StringBuilder();
+ while (true) {
String line = br.readLine();
if (line == null) break;
sb.append(line);
}
parse(sb.toString());
- } finally {
- br.close();
}
- return true;
}
public void recordTestResults() throws Exception {
File results = new File(directory, name + ".java.results");
- FileWriter fw = new FileWriter(results);
- try{
+ try (FileWriter fw = new FileWriter(results)) {
fw.write(serialize());
- } finally {
- fw.close();
}
}
- public abstract String serialize() throws Exception;
+ public abstract String serialize();
public abstract void parse(String serialized) throws Exception;
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestCase.java
index 19c9c79522d..6dfffa23aed 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestCase.java
@@ -30,26 +30,27 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class DistributionTestCase {
+
+ private static final int minUsedBits = 16;
+
private DistributionTestFactory test;
/** Build a set of buckets to test that should represent the entire bucket space well. */
- private static List<BucketId> getTestBuckets() { return getTestBuckets(16); }
- private static List<BucketId> getTestBuckets(int minUsedBits) {
+ private static List<BucketId> getTestBuckets() {
List<BucketId> buckets = new ArrayList<>();
- assertTrue(minUsedBits <= 16);
- // Get a set of buckets from the same split level
- for (int i=16; i<=18; ++i) {
- for (int j=0; j<20; ++j) {
+ // Get a set of buckets from the same split level
+ for (int i = 16; i <= 18; ++ i) {
+ for (int j = 0; j < 20; ++ j) {
buckets.add(new BucketId(i, j));
}
}
- // Get a few random buckets at every split level.
+ // Get a few random buckets at every split level.
Random randomized = new Random(413);
long randValue = randomized.nextLong();
- for (int i=minUsedBits; i<58; ++i) {
+ for (int i = minUsedBits; i < 58; ++ i) {
buckets.add(new BucketId(i, randValue));
}
randValue = randomized.nextLong();
- for (int i=minUsedBits; i<58; ++i) {
+ for (int i = minUsedBits; i < 58; ++ i) {
buckets.add(new BucketId(i, randValue));
}
return Collections.unmodifiableList(buckets);
@@ -230,7 +231,7 @@ public class DistributionTestCase {
}
@Test
- public void testSplitBeyondSplitBitDoesntAffectDistribution() throws Exception {
+ public void testSplitBeyondSplitBitDoesntAffectDistribution() {
Random randomized = new Random(7123161);
long val = randomized.nextLong();
test = new DistributionTestFactory("abovesplitbit");
@@ -325,7 +326,7 @@ public class DistributionTestCase {
}
@Test
- public void testHierarchicalDistribution() throws Exception {
+ public void testHierarchicalDistribution() {
test = new DistributionTestFactory("hierarchical-grouping")
.setDistribution(buildHierarchicalConfig(6, 3, 1, "1|2|*", 3));
for (BucketId bucket : getTestBuckets()) {
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
index 78b548e5925..e94e4f04199 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/DistributionTestFactory.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.assertTrue;
// TODO: Use config builder instead of ConfigGetter to create test config.
public class DistributionTestFactory extends CrossPlatformTestFactory {
- ObjectMapper mapper = new ObjectMapper();
+ final ObjectMapper mapper = new ObjectMapper();
private static final String testDirectory = "src/tests/distribution/testdata";
private int redundancy;
@@ -32,14 +32,14 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
private String upStates;
private int testsRecorded = 0;
- private List<Test> results = new ArrayList<>();
+ private final List<Test> results = new ArrayList<>();
private int testsVerified = 0;
- enum Failure { NONE, TOO_FEW_BITS, NO_DISTRIBUTORS_AVAILABLE };
+ enum Failure { NONE, TOO_FEW_BITS, NO_DISTRIBUTORS_AVAILABLE }
static public class Test {
- private BucketId bucket;
- private List<Integer> nodes;
+ private final BucketId bucket;
+ private final List<Integer> nodes;
private Failure failure;
public Test(BucketId bucket) {
@@ -50,8 +50,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
@Override
public boolean equals(Object other) {
- if (!(other instanceof Test)) return false;
- Test t = (Test) other;
+ if (!(other instanceof Test t)) return false;
return (bucket.equals(t.bucket)
&& nodes.equals(t.nodes)
&& failure.equals(t.failure));
@@ -81,19 +80,14 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
return nodes;
}
- public Test assertFailure(Failure f) {
- assertEquals(f, failure);
- return this;
- }
public Test assertNodeCount(int count) {
if (count > 0) assertEquals(toString(), Failure.NONE, failure);
assertEquals(toString(), count, nodes.size());
return this;
}
- public Test assertNodeUsed(int node) {
+ public void assertNodeUsed(int node) {
assertEquals(toString(), Failure.NONE, failure);
assertTrue(toString(), nodes.contains(node));
- return this;
}
}
@@ -166,9 +160,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
int node = d.getIdealDistributorNode(state, bucket, upStates);
t.nodes.add(node);
} else {
- for (int i : d.getIdealStorageNodes(state, bucket, upStates)) {
- t.nodes.add(i);
- }
+ t.nodes.addAll(d.getIdealStorageNodes(state, bucket, upStates));
}
} catch (Distribution.TooFewBucketBitsInUseException e) {
t.failure = Failure.TOO_FEW_BITS;
@@ -184,7 +176,7 @@ public class DistributionTestFactory extends CrossPlatformTestFactory {
return t;
}
- public String serialize() throws Exception {
+ public String serialize() {
ObjectNode test = new ObjectNode(mapper.getNodeFactory())
.put("cluster-state", state.toString())
.put("distribution", new StorDistributionConfig(distributionConfig).toString())
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
index 353f2bf4ebc..ce9d4dcedff 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/distribution/GroupTestCase.java
@@ -31,7 +31,7 @@ public class GroupTestCase {
private void assertDistributionFailure(String spec, int redundancy, String expectedError) {
try{
- Group.Distribution distribution = new Group.Distribution(spec, redundancy);
+ new Group.Distribution(spec, redundancy);
fail("Failed to fail parsing of spec \"" + spec + "\", redundancy " + redundancy + " with failure: " + expectedError);
} catch (Exception e) {
assertEquals(expectedError, e.getMessage());
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java
index 77dd37b3ebf..c4ff28b75b1 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java
@@ -9,7 +9,9 @@ import java.util.function.BiFunction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class ClusterStateTestCase{
@@ -55,16 +57,16 @@ public class ClusterStateTestCase{
assertEquals(state, new ClusterState("storage:0"));
assertEquals(state, new ClusterState("distributor:0"));
- assertFalse(state.equals(new ClusterState("version:1")));
- assertFalse(state.equals(new ClusterState("cluster:d")));
- assertFalse(state.equals(new ClusterState("bits:20")));
- assertFalse(state.equals(new ClusterState("storage:1")));
- assertFalse(state.equals(new ClusterState("distributor:1")));
+ assertNotEquals(state, new ClusterState("version:1"));
+ assertNotEquals(state, new ClusterState("cluster:d"));
+ assertNotEquals(state, new ClusterState("bits:20"));
+ assertNotEquals(state, new ClusterState("storage:1"));
+ assertNotEquals(state, new ClusterState("distributor:1"));
{
ClusterState state1 = new ClusterState("distributor:3 .1.s:d .2.s:m storage:3 .1.s:i .2.s:r");
ClusterState state2 = new ClusterState("distributor:3 .1.s:d .2.s:m storage:3 .1.s:i .2.s:m");
- assertFalse(state1.equals(state2));
+ assertNotEquals(state1, state2);
assertFalse(state1.similarTo(state2));
assertFalse(state1.similarToIgnoringInitProgress(state2));
}
@@ -72,7 +74,7 @@ public class ClusterStateTestCase{
{
ClusterState state1 = new ClusterState("cluster:d");
ClusterState state2 = new ClusterState("cluster:d version:1 bits:20 distributor:1 storage:1 .0.s:d");
- assertFalse(state1.equals(state2));
+ assertNotEquals(state1, state2);
assertTrue(state1.similarTo(state2));
assertTrue(state1.similarToIgnoringInitProgress(state2));
}
@@ -80,12 +82,12 @@ public class ClusterStateTestCase{
{
ClusterState state1 = new ClusterState("distributor:3 .1.s:d .2.s:m storage:3 .1.s:i .2.s:r");
ClusterState state2 = new ClusterState("distributor:3 storage:3");
- assertFalse(state1.equals(state2));
+ assertNotEquals(state1, state2);
assertFalse(state1.similarTo(state2));
assertFalse(state1.similarToIgnoringInitProgress(state2));
}
- assertFalse(state.equals("class not instance of ClusterState"));
+ assertNotEquals("class not instance of ClusterState", state);
assertFalse(state.similarTo("class not instance of ClusterState"));
assertEquals(state, state);
@@ -200,36 +202,39 @@ public class ClusterStateTestCase{
ClusterState state3 = new ClusterState("distributor:9 storage:2");
assertEquals("storage: [4: Down => Up, 5: Down => Up], distributor: [7: Up => Down, 8: Up => Down]", state1.getTextualDifference(state2));
- assertEquals("storage: [<br>\n" +
- "&nbsp;4: <b>Down</b> =&gt; <b>Up</b>, <br>\n" +
- "&nbsp;5: <b>Down</b> =&gt; <b>Up</b><br>\n" +
- "], distributor: [<br>\n" +
- "&nbsp;7: <b>Up</b> =&gt; <b>Down</b>, <br>\n" +
- "&nbsp;8: <b>Up</b> =&gt; <b>Down</b><br>\n" +
- "]", state1.getHtmlDifference(state2));
+ assertEquals("""
+ storage: [<br>
+ &nbsp;4: <b>Down</b> =&gt; <b>Up</b>, <br>
+ &nbsp;5: <b>Down</b> =&gt; <b>Up</b><br>
+ ], distributor: [<br>
+ &nbsp;7: <b>Up</b> =&gt; <b>Down</b>, <br>
+ &nbsp;8: <b>Up</b> =&gt; <b>Down</b><br>
+ ]""", state1.getHtmlDifference(state2));
assertEquals("storage: [2: Up => Down, 3: Up => Down, 4: Up => Down, 5: Up => Down], distributor: [7: Down => Up, 8: Down => Up]", state2.getTextualDifference(state3));
- assertEquals("storage: [<br>\n" +
- "&nbsp;2: <b>Up</b> =&gt; <b>Down</b>, <br>\n" +
- "&nbsp;3: <b>Up</b> =&gt; <b>Down</b>, <br>\n" +
- "&nbsp;4: <b>Up</b> =&gt; <b>Down</b>, <br>\n" +
- "&nbsp;5: <b>Up</b> =&gt; <b>Down</b><br>\n" +
- "], distributor: [<br>\n" +
- "&nbsp;7: <b>Down</b> =&gt; <b>Up</b>, <br>\n" +
- "&nbsp;8: <b>Down</b> =&gt; <b>Up</b><br>\n" +
- "]", state2.getHtmlDifference(state3));
+ assertEquals("""
+ storage: [<br>
+ &nbsp;2: <b>Up</b> =&gt; <b>Down</b>, <br>
+ &nbsp;3: <b>Up</b> =&gt; <b>Down</b>, <br>
+ &nbsp;4: <b>Up</b> =&gt; <b>Down</b>, <br>
+ &nbsp;5: <b>Up</b> =&gt; <b>Down</b><br>
+ ], distributor: [<br>
+ &nbsp;7: <b>Down</b> =&gt; <b>Up</b>, <br>
+ &nbsp;8: <b>Down</b> =&gt; <b>Up</b><br>
+ ]""", state2.getHtmlDifference(state3));
state1.setVersion(123);
state1.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0.2f).setDescription("Booting"));
state2.setDistributionBits(21);
assertEquals("version: 123 => 0, bits: 16 => 21, storage: [2: [Initializing => Up, description: Booting => ], 4: Down => Up, 5: Down => Up], distributor: [7: Up => Down, 8: Up => Down]", state1.getTextualDifference(state2));
- assertEquals("version: 123 =&gt; 0, bits: 16 =&gt; 21, storage: [<br>\n" +
- "&nbsp;2: [<b>Initializing</b> =&gt; <b>Up</b>, description: Booting =&gt; ], <br>\n" +
- "&nbsp;4: <b>Down</b> =&gt; <b>Up</b>, <br>\n" +
- "&nbsp;5: <b>Down</b> =&gt; <b>Up</b><br>\n" +
- "], distributor: [<br>\n" +
- "&nbsp;7: <b>Up</b> =&gt; <b>Down</b>, <br>\n" +
- "&nbsp;8: <b>Up</b> =&gt; <b>Down</b><br>\n" +
- "]", state1.getHtmlDifference(state2));
+ assertEquals("""
+ version: 123 =&gt; 0, bits: 16 =&gt; 21, storage: [<br>
+ &nbsp;2: [<b>Initializing</b> =&gt; <b>Up</b>, description: Booting =&gt; ], <br>
+ &nbsp;4: <b>Down</b> =&gt; <b>Up</b>, <br>
+ &nbsp;5: <b>Down</b> =&gt; <b>Up</b><br>
+ ], distributor: [<br>
+ &nbsp;7: <b>Up</b> =&gt; <b>Down</b>, <br>
+ &nbsp;8: <b>Up</b> =&gt; <b>Down</b><br>
+ ]""", state1.getHtmlDifference(state2));
}
@Test
@@ -254,40 +259,40 @@ public class ClusterStateTestCase{
try {
new ClusterState("badtokenwithoutcolon");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState(".0.s:d");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("cluster:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("cluster:m");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("version:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("distributor:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("storage:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("distributor:2 .3.s:d");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
new ClusterState("storage:2 .3.s:d");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
}
@Test
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
index 1ce3655b394..3eff07e80b9 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java
@@ -4,11 +4,12 @@ package com.yahoo.vdslib.state;
import org.junit.Test;
import java.text.ParseException;
-import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class NodeStateTestCase {
@@ -56,36 +57,36 @@ public class NodeStateTestCase {
assertEquals(ns, NodeState.deserialize(NodeType.STORAGE, ": s:m sbadkey:u bbadkey:2 cbadkey:2.0 rbadkey:2 ibadkey:0.5 tbadkey:2 mbadkey:message dbadkey:2 unknownkey:somevalue"));
try {
NodeState.deserialize(NodeType.STORAGE, "s:m badtokenwithoutcolon");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m c:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m i:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m t:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m t:-1");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m d:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m d.badkey:badvalue");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
try {
NodeState.deserialize(NodeType.STORAGE, "s:m d.1:badindex");
- assertTrue("Should fail", false);
- } catch (Exception e) {}
+ fail("Should fail");
+ } catch (Exception ignored) {}
ns = new NodeState(NodeType.STORAGE, State.UP).setDescription("Foo bar");
assertEquals("", ns.serialize(2, false));
@@ -127,11 +128,11 @@ public class NodeStateTestCase {
assertTrue(ns1.similarToIgnoringInitProgress(ns4));
assertTrue(ns2.similarToIgnoringInitProgress(ns4));
- assertFalse(ns1.equals(ns2));
- assertFalse(ns2.equals(ns3));
- assertFalse(ns3.equals(ns4));
+ assertNotEquals(ns1, ns2);
+ assertNotEquals(ns2, ns3);
+ assertNotEquals(ns3, ns4);
- assertFalse(ns1.equals("class not instance of NodeState"));
+ assertNotEquals("class not instance of NodeState", ns1);
assertFalse(ns1.similarTo("class not instance of NodeState"));
}
{
@@ -139,7 +140,7 @@ public class NodeStateTestCase {
NodeState ns2 = new NodeState(NodeType.STORAGE, State.UP).setMinUsedBits(18);
assertTrue(ns1.similarTo(ns2));
assertTrue(ns1.similarToIgnoringInitProgress(ns2));
- assertFalse(ns1.equals(ns2));
+ assertNotEquals(ns1, ns2);
}
}
@@ -163,12 +164,12 @@ public class NodeStateTestCase {
public void testValidInClusterState() {
try{
new NodeState(NodeType.DISTRIBUTOR, State.UNKNOWN).verifyValidInSystemState(NodeType.DISTRIBUTOR);
- assertTrue("Should not be valid", false);
- } catch (Exception e) {}
+ fail("Should not be valid");
+ } catch (Exception ignored) {}
try{
new NodeState(NodeType.DISTRIBUTOR, State.UP).setCapacity(3).verifyValidInSystemState(NodeType.DISTRIBUTOR);
- assertTrue("Should not be valid", false);
- } catch (Exception e) {}
+ fail("Should not be valid");
+ } catch (Exception ignored) {}
}
}
diff --git a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
index 971b4782ab0..e3fc0faecd5 100644
--- a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
+++ b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeTest.java
@@ -5,7 +5,9 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
public class NodeTest {
@@ -29,23 +31,23 @@ public class NodeTest {
assertEquals(n3, n3);
assertEquals(n4, n4);
- assertFalse(n1.equals(n2));
- assertFalse(n1.equals(n3));
- assertFalse(n1.equals(n4));
+ assertNotEquals(n1, n2);
+ assertNotEquals(n1, n3);
+ assertNotEquals(n1, n4);
- assertFalse(n2.equals(n1));
- assertFalse(n2.equals(n3));
- assertFalse(n2.equals(n4));
+ assertNotEquals(n2, n1);
+ assertNotEquals(n2, n3);
+ assertNotEquals(n2, n4);
- assertFalse(n3.equals(n1));
- assertFalse(n3.equals(n2));
- assertFalse(n3.equals(n4));
+ assertNotEquals(n3, n1);
+ assertNotEquals(n3, n2);
+ assertNotEquals(n3, n4);
- assertFalse(n4.equals(n1));
- assertFalse(n4.equals(n2));
- assertFalse(n4.equals(n3));
+ assertNotEquals(n4, n1);
+ assertNotEquals(n4, n2);
+ assertNotEquals(n4, n3);
- assertFalse(n1.equals("class not instance of Node"));
+ assertNotEquals("class not instance of Node", n1);
}
@Test
@@ -62,19 +64,19 @@ public class NodeTest {
try {
new Node("nodewithoutdot");
- assertTrue("Method expected to throw IllegalArgumentException", false);
+ fail("Method expected to throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals("Not a legal node string 'nodewithoutdot'.", e.getMessage());
}
try {
new Node("fleetcontroller.0");
- assertTrue("Method expected to throw IllegalArgumentException", false);
+ fail("Method expected to throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals("Unknown node type 'fleetcontroller'. Legal values are 'storage' and 'distributor'.", e.getMessage());
}
try {
new Node("storage.badindex");
- assertTrue("Method expected to throw NumberFormatException", false);
+ fail("Method expected to throw NumberFormatException");
} catch (NumberFormatException e) {
assertEquals("For input string: \"badindex\"", e.getMessage());
}