diff options
author | Harald Musum <musum@verizonmedia.com> | 2023-07-07 19:41:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-07 19:41:43 +0200 |
commit | 3168abdd33e16054275719f1c33f3fd474413eac (patch) | |
tree | f0dfe24300135ee4f6e9b6ed413f6686ae4b0b9f | |
parent | 137964b4d4758655141e95e1d4cd32227ba15c7b (diff) | |
parent | 6697ab6cdbc94505f95ce09bc17873e756c19c00 (diff) |
Merge pull request #27676 from vespa-engine/hmusum/vdslib-cleanup-1
Cleanup, simplify, remove dead code. No functional changes
19 files changed, 215 insertions, 333 deletions
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/BucketDistribution.java b/vdslib/src/main/java/com/yahoo/vdslib/BucketDistribution.java index c49fdb93d20..ba17b947bb8 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/BucketDistribution.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/BucketDistribution.java @@ -4,6 +4,7 @@ package com.yahoo.vdslib; import com.yahoo.document.BucketId; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -14,16 +15,16 @@ import java.util.logging.Logger; public class BucketDistribution { // A logger object to enable proper logging. - private static Logger log = Logger.getLogger(BucketDistribution.class.getName()); + private static final Logger log = Logger.getLogger(BucketDistribution.class.getName()); // A map from bucket id to column index. - private int[] bucketToColumn; + private final int[] bucketToColumn; // The number of columns to distribute to. private int numColumns; // The number of bits to use for bucket identification. - private int numBucketBits; + private final int numBucketBits; /** * Constructs a new bucket distribution object with a given number of columns and buckets. @@ -68,7 +69,7 @@ public class BucketDistribution { * @return The bucket distribution. */ private static List<Integer> getBucketCount(int numColumns, int numBucketBits) { - List<Integer> ret = new ArrayList<Integer>(numColumns); + List<Integer> ret = new ArrayList<>(numColumns); int cnt = getNumBuckets(numBucketBits) / numColumns; int rst = getNumBuckets(numBucketBits) % numColumns; for (int i = 0; i < numColumns; ++i) { @@ -100,9 +101,7 @@ public class BucketDistribution { * that it all buckets point to that single column. */ public void reset() { - for (int i = 0; i < bucketToColumn.length; ++i) { - bucketToColumn[i] = 0; - } + Arrays.fill(bucketToColumn, 0); numColumns = 1; } @@ -152,32 +151,6 @@ public class BucketDistribution { } /** - * Sets the number of buckets to use for this document distribution object. This will reset and setup this object - * from scratch. The original number of columns is maintained. - * - * @param numBucketBits The new number of bits to use for bucket id. - */ - public synchronized void setNumBucketBits(int numBucketBits) { - if (numBucketBits == this.numBucketBits) { - return; - } - this.numBucketBits = numBucketBits; - bucketToColumn = new int[getNumBuckets(numBucketBits)]; - int numColumns = this.numColumns; - reset(); - setNumColumns(numColumns); - } - - /** - * Returns the number of bits used for bucket identifiers. - * - * @return The number of bits. - */ - public int getNumBucketBits() { - return numBucketBits; - } - - /** * Returns the number of buckets available using the configured number of bucket bits. * * @return The number of buckets. diff --git a/vdslib/src/main/java/com/yahoo/vdslib/DocumentSummary.java b/vdslib/src/main/java/com/yahoo/vdslib/DocumentSummary.java index ab5fe0d9a86..4371e19d090 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/DocumentSummary.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/DocumentSummary.java @@ -5,7 +5,8 @@ import com.yahoo.vespa.objects.BufferSerializer; import com.yahoo.vespa.objects.Deserializer; import java.nio.ByteOrder; -import java.io.UnsupportedEncodingException; + +import static java.nio.charset.StandardCharsets.UTF_8; public class DocumentSummary { @@ -27,23 +28,14 @@ public class DocumentSummary { int summarySize = buf.getInt(null); int end = start; while (cArr[end++] != 0); - try { - byte [] sb = new byte [summarySize]; - System.arraycopy(cArr, end, sb, 0, summarySize); - summaries[i] = new Summary(new String(cArr, start, end-start-1, "utf-8"), sb); - start = end + summarySize; - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("UTF-8 apparently not supported"); - } + byte [] sb = new byte [summarySize]; + System.arraycopy(cArr, end, sb, 0, summarySize); + summaries[i] = new Summary(new String(cArr, start, end-start-1, UTF_8), sb); + start = end + summarySize; } } } - /** Constructs a new message from a byte buffer. */ - public DocumentSummary(byte[] buffer) { - this(BufferSerializer.wrap(buffer)); - } - final public int getSummaryCount() { return summaries.length; } final public Summary getSummary(int hitNo) { return summaries[hitNo]; } @@ -63,7 +55,6 @@ public class DocumentSummary { final public String getDocId() { return docId; } final public byte [] getSummary() { return summary; } - final public void setSummary(byte [] summary) { this.summary = summary; } public int compareTo(Summary s) { return getDocId().compareTo(s.getDocId()); diff --git a/vdslib/src/main/java/com/yahoo/vdslib/MetaEntry.java b/vdslib/src/main/java/com/yahoo/vdslib/MetaEntry.java deleted file mode 100644 index a05f746fe48..00000000000 --- a/vdslib/src/main/java/com/yahoo/vdslib/MetaEntry.java +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vdslib; - -import com.yahoo.io.GrowableByteBuffer; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; - -public class MetaEntry { - public static int REMOVE_ENTRY = 1; - public static int BODY_STRIPPED = 2; - public static int BODY_IN_HEADER = 4; - public static int UPDATE_ENTRY = 8; - public static int COMPRESSED = 16; - - public static int SIZE = 32; - - public long timestamp = 0; - public int headerPos = 0; - public int headerLen = 0; - public int bodyPos = 0; - public int bodyLen = 0; - public byte flags = 0; - - public MetaEntry() { - } - - public MetaEntry(byte[] buffer, int position) { - ByteBuffer buf = ByteBuffer.wrap(buffer, position, SIZE); - buf.order(ByteOrder.LITTLE_ENDIAN); - - timestamp = buf.getLong(); - headerPos = buf.getInt(); - headerLen = buf.getInt(); - bodyPos = buf.getInt(); - bodyLen = buf.getInt(); - flags = buf.get(); - } - - public void serialize(GrowableByteBuffer buf) { - ByteOrder originalOrder = buf.order(); - buf.order(ByteOrder.LITTLE_ENDIAN); - buf.putLong(timestamp); // 8 - buf.putInt(headerPos); // 12 - buf.putInt(headerLen); // 16 - buf.putInt(bodyPos); // 20 - buf.putInt(bodyLen); // 24 - buf.putInt(flags); // 28 (written as little-endian int, this is on purpose) - buf.putInt(0); // 32 - buf.order(originalOrder); - } -} diff --git a/vdslib/src/main/java/com/yahoo/vdslib/SearchResult.java b/vdslib/src/main/java/com/yahoo/vdslib/SearchResult.java index b7c9b1b71b5..c89abf87970 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/SearchResult.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/SearchResult.java @@ -1,19 +1,22 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vdslib; + import com.yahoo.data.access.helpers.MatchFeatureData; import com.yahoo.vespa.objects.BufferSerializer; import com.yahoo.vespa.objects.Deserializer; -import java.io.UnsupportedEncodingException; import java.nio.ByteOrder; import java.util.ArrayList; import java.util.Map; import java.util.Optional; import java.util.TreeMap; +import static java.nio.charset.StandardCharsets.UTF_8; + public class SearchResult { + public static class Hit implements Comparable<Hit> { - private String docId; + private final String docId; private double rank; private MatchFeatureData.HitValue matchFeatures; public Hit(Hit h) { @@ -40,7 +43,7 @@ public class SearchResult { } } public static class HitWithSortBlob extends Hit { - private byte [] sortBlob; + private final byte [] sortBlob; public HitWithSortBlob(Hit h, byte [] sb) { super(h); sortBlob = sb; @@ -57,12 +60,12 @@ public class SearchResult { return sortBlob.length - b.sortBlob.length; } } - private int totalHits; - private Hit[] hits; - private TreeMap<Integer, byte []> aggregatorList; - private TreeMap<Integer, byte []> groupingList; - private static int EXTENSION_FLAGS_PRESENT = -1; - private static int MATCH_FEATURES_PRESENT_MASK = 1; + private final int totalHits; + private final Hit[] hits; + private final TreeMap<Integer, byte []> aggregatorList; + private final TreeMap<Integer, byte []> groupingList; + private static final int EXTENSION_FLAGS_PRESENT = -1; + private static final int MATCH_FEATURES_PRESENT_MASK = 1; public SearchResult(Deserializer buf) { BufferSerializer bser = (BufferSerializer) buf; // TODO: dirty cast. must do this differently @@ -76,17 +79,13 @@ public class SearchResult { } hits = new Hit[numHits]; if (numHits != 0) { - int docIdBufferLength = buf.getInt(null); + int docIdBufferLength = buf.getInt(null); // Unused, but need to call getInt() to advance buffer byte[] cArr = bser.getBuf().array(); int start = bser.getBuf().arrayOffset() + bser.position(); for(int i=0; i < numHits; i++) { int end = start; while (cArr[end++] != 0); - try { - hits[i] = new Hit(new String(cArr, start, end-start-1, "utf-8"), 0); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("UTF-8 apparently not supported"); - } + hits[i] = new Hit(new String(cArr, start, end-start-1, UTF_8), 0); start = end; } bser.position(start - bser.getBuf().arrayOffset()); @@ -104,8 +103,9 @@ public class SearchResult { hits[i] = new HitWithSortBlob(hits[i], buf.getBytes(null, size[i])); } + // Unused, but need to call getInt() to advance buffer int numAggregators = buf.getInt(null); - aggregatorList = new TreeMap<Integer, byte []>(); + aggregatorList = new TreeMap<>(); for (int i = 0; i < numAggregators; i++) { int aggrId = buf.getInt(null); int aggrLength = buf.getInt(null); @@ -113,7 +113,7 @@ public class SearchResult { } int numGroupings = buf.getInt(null); - groupingList = new TreeMap<Integer, byte []>(); + groupingList = new TreeMap<>(); for (int i = 0; i < numGroupings; i++) { int aggrId = buf.getInt(null); int aggrLength = buf.getInt(null); @@ -159,18 +159,8 @@ public class SearchResult { return featureType == 0; } - /** - * Constructs a new message from a byte buffer. - * - * @param buffer A byte buffer that contains a serialized message. - */ - public SearchResult(byte[] buffer) { - this(BufferSerializer.wrap(buffer)); - } - final public int getHitCount() { return hits.length; } final public int getTotalHitCount() { return (totalHits != 0) ? totalHits : getHitCount(); } final public Hit getHit(int hitNo) { return hits[hitNo]; } - final public Map<Integer, byte []> getAggregatorList() { return aggregatorList; } final public Map<Integer, byte []> getGroupingList() { return groupingList; } } diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/ConfiguredNode.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/ConfiguredNode.java index 92cf8b025e9..965dd018c4f 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/ConfiguredNode.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/ConfiguredNode.java @@ -7,31 +7,28 @@ package com.yahoo.vdslib.distribution; * * @author bratseth */ -public class ConfiguredNode implements Comparable<ConfiguredNode> { +public record ConfiguredNode(int index, boolean retired) implements Comparable<ConfiguredNode> { - private final int index; - - private final boolean retired; - - public ConfiguredNode(int index, boolean retired) { - this.index = index; - this.retired = retired; - } - - /** Return the index (distribution key) of this node */ - public int index() { return index; } + /** + * Return the index (distribution key) of this node + */ + @Override + public int index() {return index;} - /** Returns whether the node is configured to be retired */ - public boolean retired() { return retired; } + /** + * Returns whether the node is configured to be retired + */ + @Override + public boolean retired() {return retired;} @Override - public int hashCode() { return index; } + public int hashCode() {return index;} @Override public boolean equals(Object other) { if (other == this) return true; - if ( ! (other instanceof ConfiguredNode)) return false; - return ((ConfiguredNode)other).index == this.index; + if (! (other instanceof ConfiguredNode)) return false; + return ((ConfiguredNode) other).index == this.index; } @Override diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java index a83e2a4f89c..bfa7e919514 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Distribution.java @@ -26,14 +26,7 @@ import java.util.concurrent.atomic.AtomicReference; public class Distribution { - private static class Config { - Config(Group nodeGraph, int redundancy) { - this.nodeGraph = nodeGraph; - this.redundancy = redundancy; - } - - private final Group nodeGraph; - private final int redundancy; + private record Config(Group nodeGraph, int redundancy) { } private ConfigSubscriber configSub; @@ -197,8 +190,8 @@ public class Distribution { } private static class ScoredGroup implements Comparable<ScoredGroup> { - Group group; - double score; + final Group group; + final double score; ScoredGroup(Group g, double score) { this.group = g; this.score = score; } @@ -266,8 +259,8 @@ public class Distribution { } private static class ResultGroup implements Comparable<ResultGroup> { - Group group; - int redundancy; + final Group group; + final int redundancy; ResultGroup(Group group, int redundancy) { this.group = group; @@ -489,14 +482,11 @@ public class Distribution { public Set<ConfiguredNode> getNodes() { final Set<ConfiguredNode> nodes = new HashSet<>(); - GroupVisitor visitor = new GroupVisitor() { - @Override - public boolean visitGroup(Group g) { - if (g.isLeafGroup()) { - nodes.addAll(g.getNodes()); - } - return true; + GroupVisitor visitor = g -> { + if (g.isLeafGroup()) { + nodes.addAll(g.getNodes()); } + return true; }; visitGroups(visitor); return nodes; diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Group.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Group.java index b926ee3be8d..c1c2eef5c8f 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/Group.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/Group.java @@ -9,13 +9,13 @@ import java.text.ParseException; */ public class Group implements Comparable<Group> { - private String name; + private final String name; private Group parent = null; - private int index; + private final int index; private int distributionHash; - private Distribution distribution = null; + private final Distribution distribution; private double capacity; - private Map<Integer, Group> subgroups; + private final Map<Integer, Group> subgroups; private List<ConfiguredNode> nodes; public Group(int index, String name) { @@ -63,8 +63,7 @@ public class Group implements Comparable<Group> { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof Group)) { return false; } - Group other = (Group) o; + if ( ! (o instanceof Group other)) { return false; } if ( ! name.equals(other.name) || index != other.index || (distribution == null ^ other.distribution == null) @@ -210,7 +209,7 @@ public class Group implements Comparable<Group> { for (int i=0; i<distributionSpec.length; ++i) { String token = st.nextToken(); try{ - distributionSpec[i] = (token.equals("*") ? 0 : Integer.valueOf(token)); + distributionSpec[i] = (token.equals("*") ? 0 : Integer.parseInt(token)); } catch (NumberFormatException e) { throw new ParseException("Illegal distribution spec \"" + serialized + "\". Copy counts must be integer values in the range 1-255.", i); } @@ -243,9 +242,9 @@ public class Group implements Comparable<Group> { int asterixCount = distributionSpec.length - firstAsterix; int[][] preCalculations = new int[maxRedundancy + 1][]; for (int i=1; i<=maxRedundancy; ++i) { - List<Integer> spec = new ArrayList<Integer>(); - for (int j=0; j<distributionSpec.length; ++j) { - spec.add(distributionSpec[j]); + List<Integer> spec = new ArrayList<>(); + for (int k : distributionSpec) { + spec.add(k); } int remainingRedundancy = i; for (int j=0; j<firstAsterix; ++j) { @@ -277,8 +276,7 @@ public class Group implements Comparable<Group> { @Override public boolean equals(Object o) { if (o == this) return true; - if ( ! (o instanceof Distribution)) return false; - Distribution other = (Distribution) o; + if ( ! (o instanceof Distribution other)) return false; return (distributionSpec == other.distributionSpec && preCalculatedResults.length == other.preCalculatedResults.length); } diff --git a/vdslib/src/main/java/com/yahoo/vdslib/distribution/GroupVisitor.java b/vdslib/src/main/java/com/yahoo/vdslib/distribution/GroupVisitor.java index df5a6e5a9d1..1108ce7507d 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/distribution/GroupVisitor.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/distribution/GroupVisitor.java @@ -3,6 +3,6 @@ package com.yahoo.vdslib.distribution; public interface GroupVisitor { - public boolean visitGroup(Group g); + boolean visitGroup(Group g); } diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java b/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java index 4bf305e65e0..30a209b6754 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/state/ClusterState.java @@ -24,7 +24,7 @@ public class ClusterState implements Cloneable { /** * Maintains a bitset where all non-down nodes have a bit set. All nodes that differ from defaultUp - * and defaultDown are store explicit in a hash map. + * and defaultDown are stored explicitly in a hash map. */ private static class Nodes { private int logicalNodeCount; diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/Diff.java b/vdslib/src/main/java/com/yahoo/vdslib/state/Diff.java index f4eb9ff8dde..8a4bedddaeb 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/state/Diff.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/state/Diff.java @@ -8,8 +8,9 @@ import java.util.List; * TODO: document this */ public class Diff { + public static class Entry { - String id; + final String id; // Values set for entries that contain diff themselves String preContent; String postContent; @@ -32,22 +33,22 @@ public class Diff { public Entry bold() { bold = true; return this; } public Entry splitLine() { splitLine = true; return this; } } - private List<Entry> diff = new LinkedList<Entry>(); + private final List<Entry> diff = new LinkedList<>(); public void add(Entry e) { diff.add(e); } public boolean differs() { return (!diff.isEmpty()); } - class PrintProperties { + static class PrintProperties { boolean insertLineBreaks = false; - boolean ommitGroupForSingleEntries = true; + final boolean ommitGroupForSingleEntries = true; String lineBreak = "\n"; - String entrySeparator = ", "; - String idValueSeparator = ": "; + final String entrySeparator = ", "; + final String idValueSeparator = ": "; String keyValueSeparator = " => "; - String singleGroupSeparator = ""; - String groupStart = "["; - String groupStop = "]"; + final String singleGroupSeparator = ""; + final String groupStart = "["; + final String groupStop = "]"; String indent = " "; String boldStart = ""; String boldStop = ""; 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" + - " 4: <b>Down</b> => <b>Up</b>, <br>\n" + - " 5: <b>Down</b> => <b>Up</b><br>\n" + - "], distributor: [<br>\n" + - " 7: <b>Up</b> => <b>Down</b>, <br>\n" + - " 8: <b>Up</b> => <b>Down</b><br>\n" + - "]", state1.getHtmlDifference(state2)); + assertEquals(""" + storage: [<br> + 4: <b>Down</b> => <b>Up</b>, <br> + 5: <b>Down</b> => <b>Up</b><br> + ], distributor: [<br> + 7: <b>Up</b> => <b>Down</b>, <br> + 8: <b>Up</b> => <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" + - " 2: <b>Up</b> => <b>Down</b>, <br>\n" + - " 3: <b>Up</b> => <b>Down</b>, <br>\n" + - " 4: <b>Up</b> => <b>Down</b>, <br>\n" + - " 5: <b>Up</b> => <b>Down</b><br>\n" + - "], distributor: [<br>\n" + - " 7: <b>Down</b> => <b>Up</b>, <br>\n" + - " 8: <b>Down</b> => <b>Up</b><br>\n" + - "]", state2.getHtmlDifference(state3)); + assertEquals(""" + storage: [<br> + 2: <b>Up</b> => <b>Down</b>, <br> + 3: <b>Up</b> => <b>Down</b>, <br> + 4: <b>Up</b> => <b>Down</b>, <br> + 5: <b>Up</b> => <b>Down</b><br> + ], distributor: [<br> + 7: <b>Down</b> => <b>Up</b>, <br> + 8: <b>Down</b> => <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 => 0, bits: 16 => 21, storage: [<br>\n" + - " 2: [<b>Initializing</b> => <b>Up</b>, description: Booting => ], <br>\n" + - " 4: <b>Down</b> => <b>Up</b>, <br>\n" + - " 5: <b>Down</b> => <b>Up</b><br>\n" + - "], distributor: [<br>\n" + - " 7: <b>Up</b> => <b>Down</b>, <br>\n" + - " 8: <b>Up</b> => <b>Down</b><br>\n" + - "]", state1.getHtmlDifference(state2)); + assertEquals(""" + version: 123 => 0, bits: 16 => 21, storage: [<br> + 2: [<b>Initializing</b> => <b>Up</b>, description: Booting => ], <br> + 4: <b>Down</b> => <b>Up</b>, <br> + 5: <b>Down</b> => <b>Up</b><br> + ], distributor: [<br> + 7: <b>Up</b> => <b>Down</b>, <br> + 8: <b>Up</b> => <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()); } |