diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-11 16:50:08 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-03-11 16:50:08 +0100 |
commit | 0916a5a1ac78a0ade76a86dee551ab2583a4ab4a (patch) | |
tree | 95b614550c7b1c3e76e420195438ce8ff3e328b3 /vdslib | |
parent | 9f67253858a7ffaf452f6f8d456bf8b73e103dd6 (diff) |
GC use of void DiskState.
Diffstat (limited to 'vdslib')
3 files changed, 18 insertions, 63 deletions
diff --git a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java index e3b65c88f59..c6b3149639a 100644 --- a/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java +++ b/vdslib/src/main/java/com/yahoo/vdslib/state/NodeState.java @@ -257,29 +257,6 @@ public class NodeState implements Cloneable { return sb.toString(); } - public NodeState setDiskCount(int count) { - if (count < 0) { - throw new IllegalArgumentException("Count must be positive. Was "+count+"."); - } - diskStates.clear(); - for(int i=0;i<count;i++) { - diskStates.add(new DiskState(State.UP, "", 1.0)); - } - return this; - } - - public NodeState setDiskState(int disk, DiskState state) throws IndexOutOfBoundsException { - diskStates.set(disk, state); - return this; - } - - public DiskState getDiskState(int disk) throws IndexOutOfBoundsException { - if (diskStates.isEmpty()) { // Zero disks, means unknown amount of disks, but all are up, - return new DiskState(); // in which case we don't need to know amount of disks. - } - return diskStates.get(disk); - } - public String serialize() { return serialize(-1, false); } public String serialize(boolean verbose) { return serialize(-1, verbose); } public String serialize(int nodeIdx, boolean verbose) { 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 cd0b1484748..258a79f5362 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/state/ClusterStateTestCase.java @@ -24,10 +24,10 @@ public class ClusterStateTestCase{ assertEquals("distributor:2 .0.s:d", state.toString()); state.setNodeState(new Node(NodeType.DISTRIBUTOR, 4), new NodeState(NodeType.DISTRIBUTOR, State.UP)); assertEquals("distributor:5 .0.s:d .2.s:d .3.s:d", state.toString()); - state.setNodeState(new Node(NodeType.STORAGE, 0), new NodeState(NodeType.STORAGE, State.UP).setDiskCount(4)); + state.setNodeState(new Node(NodeType.STORAGE, 0), new NodeState(NodeType.STORAGE, State.UP)); assertEquals("distributor:5 .0.s:d .2.s:d .3.s:d storage:1", state.toString()); - state.setNodeState(new Node(NodeType.STORAGE, 0), new NodeState(NodeType.STORAGE, State.UP).setDiskCount(4).setDiskState(1, new DiskState(State.DOWN))); - assertEquals("distributor:5 .0.s:d .2.s:d .3.s:d storage:1 .0.d:4 .0.d.1.s:d", state.toString()); + state.setNodeState(new Node(NodeType.STORAGE, 0), new NodeState(NodeType.STORAGE, State.DOWN)); + assertEquals("distributor:5 .0.s:d .2.s:d .3.s:d", state.toString()); } @Test @@ -35,7 +35,7 @@ public class ClusterStateTestCase{ ClusterState state = new ClusterState(""); state.setNodeState(new Node(NodeType.DISTRIBUTOR, 1), new NodeState(NodeType.DISTRIBUTOR, State.UP).setDescription("available")); state.setNodeState(new Node(NodeType.STORAGE, 0), new NodeState(NodeType.STORAGE, State.UP).setCapacity(1.2f)); - state.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.UP).setDiskCount(2).setDiskState(1, new DiskState(State.DOWN))); + state.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.UP)); ClusterState other = state.clone(); assertEquals(state.toString(true), other.toString(true)); assertEquals(state.toString(false), other.toString(false)); @@ -187,10 +187,10 @@ public class ClusterStateTestCase{ state2.setDistributionBits(21); state1.setVersion(123); - state1.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0.2f).setDiskCount(2).setDescription("Booting")); + state1.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0.2f).setDescription("Booting")); state2.setOfficial(true); - assertEquals("version: 123 => 0, bits: 16 => 21, official: false => true, storage: [2: [Initializing => Up, disks: 2 => 0, 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, official: false => true, storage: [2: [Initializing => Up, description: Booting => ], 4: Down => Up, 5: Down => Up], distributor: [7: Up => Down, 8: Up => Down]", state1.getTextualDifference(state2)); } @Test @@ -219,12 +219,12 @@ public class ClusterStateTestCase{ "]", state2.getHtmlDifference(state3)); state1.setVersion(123); - state1.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0.2f).setDiskCount(2).setDescription("Booting")); + state1.setNodeState(new Node(NodeType.STORAGE, 2), new NodeState(NodeType.STORAGE, State.INITIALIZING).setInitProgress(0.2f).setDescription("Booting")); state2.setDistributionBits(21); state2.setOfficial(true); - assertEquals("version: 123 => 0, bits: 16 => 21, official: false => true, storage: [2: [Initializing => Up, disks: 2 => 0, 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, official: false => true, 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, official: false => true, storage: [<br>\n" + - " 2: [<b>Initializing</b> => <b>Up</b>, disks: 2 => 0, description: Booting => ], <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" + 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 f217e2fef4e..a6d9778cdd3 100644 --- a/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java +++ b/vdslib/src/test/java/com/yahoo/vdslib/state/NodeStateTestCase.java @@ -92,13 +92,12 @@ public class NodeStateTestCase { assertEquals("m:Foo\\x20bar", ns.serialize(false)); assertEquals("m:Foo\\x20bar", ns.serialize(true)); - ns = new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Foo bar").setCapacity(1.2f).setDiskCount(4) - .setMinUsedBits(12).setStartTimestamp(5).setDiskState(1, new DiskState(State.DOWN, "bad disk", 1)) - .setDiskState(3, new DiskState(State.UP, "", 2)); - assertEquals(".2.s:m .2.c:1.2 .2.t:5 .2.d:4 .2.d.1.s:d .2.d.3.c:2.0", ns.serialize(2, false)); - assertEquals("s:m c:1.2 t:5 b:12 d:4 d.1.s:d d.3.c:2.0 m:Foo\\x20bar", ns.serialize(false)); - assertEquals("s:m c:1.2 t:5 b:12 d:4 d.1.s:d d.1.m:bad\\x20disk d.3.c:2.0 m:Foo\\x20bar", ns.serialize(true)); - NodeState ns2 = NodeState.deserialize(NodeType.STORAGE, "s:m c:1.2 t:5 b:12 d:4 d.1.s:d d.1.m:bad\\x20disk d.3.c:2.0 m:Foo\\x20bar"); + ns = new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Foo bar").setCapacity(1.2f) + .setMinUsedBits(12).setStartTimestamp(5); + assertEquals(".2.s:m .2.c:1.2 .2.t:5", ns.serialize(2, false)); + assertEquals("s:m c:1.2 t:5 b:12 m:Foo\\x20bar", ns.serialize(false)); + assertEquals("s:m c:1.2 t:5 b:12 m:Foo\\x20bar", ns.serialize(true)); + NodeState ns2 = NodeState.deserialize(NodeType.STORAGE, "s:m c:1.2 t:5 b:12 m:Foo\\x20bar"); assertEquals(ns, ns2); NodeState copy1 = NodeState.deserialize(NodeType.STORAGE, ns.serialize(false)); @@ -142,22 +141,6 @@ public class NodeStateTestCase { assertTrue(ns1.similarToIgnoringInitProgress(ns2)); assertFalse(ns1.equals(ns2)); } - { - NodeState ns = new NodeState(NodeType.STORAGE, State.MAINTENANCE); - NodeState ns2Disks = new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDiskCount(2); - assertEquals(ns, ns2Disks); - assertEquals(ns2Disks, ns); - assertTrue(ns.similarTo(ns2Disks)); - assertTrue(ns.similarToIgnoringInitProgress(ns2Disks)); - assertTrue(ns2Disks.similarTo(ns)); - - ns2Disks.getDiskState(0).setState(State.DOWN); - assertFalse(ns.equals(ns2Disks)); - assertFalse(ns2Disks.equals(ns)); - assertFalse(ns.similarTo(ns2Disks)); - assertFalse(ns.similarToIgnoringInitProgress(ns2Disks)); - assertFalse(ns2Disks.similarTo(ns)); - } } @Test @@ -168,12 +151,11 @@ public class NodeStateTestCase { String expected = "Maintenance => Up"; assertEquals(expected, ns.getTextualDifference(new NodeState(NodeType.STORAGE, State.UP)).substring(0, expected.length())); - NodeState ns1 = new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Foo bar").setCapacity(1.2f).setDiskCount(4) - .setMinUsedBits(12).setStartTimestamp(5).setDiskState(1, new DiskState(State.DOWN, "bad disk", 1)) - .setDiskState(3, new DiskState(State.UP, "", 2)); + NodeState ns1 = new NodeState(NodeType.STORAGE, State.MAINTENANCE).setDescription("Foo bar").setCapacity(1.2f) + .setMinUsedBits(12).setStartTimestamp(5); ns1.toString(); ns1.toString(true); - expected = "Maintenance => Up, capacity: 1.2 => 1.0, minUsedBits: 12 => 16, startTimestamp: 5 => 0, disks: 4 => 0, description: Foo bar => "; + expected = "Maintenance => Up, capacity: 1.2 => 1.0, minUsedBits: 12 => 16, startTimestamp: 5 => 0, description: Foo bar => "; assertEquals(expected, ns1.getTextualDifference(new NodeState(NodeType.STORAGE, State.UP)).substring(0, expected.length())); } @@ -187,10 +169,6 @@ public class NodeStateTestCase { new NodeState(NodeType.DISTRIBUTOR, State.UP).setCapacity(3).verifyValidInSystemState(NodeType.DISTRIBUTOR); assertTrue("Should not be valid", false); } catch (Exception e) {} - try{ - new NodeState(NodeType.DISTRIBUTOR, State.UP).setDiskCount(2).verifyValidInSystemState(NodeType.DISTRIBUTOR); - assertTrue("Should not be valid", false); - } catch (Exception e) {} } } |