|
@@ -47,17 +47,10 @@ import com.google.common.collect.LinkedListMultimap;
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
|
public class TestBlockManager {
|
|
|
- private final List<DatanodeDescriptor> nodes = ImmutableList.of(
|
|
|
- new DatanodeDescriptor(new DatanodeID("h1", 5020), "/rackA"),
|
|
|
- new DatanodeDescriptor(new DatanodeID("h2", 5020), "/rackA"),
|
|
|
- new DatanodeDescriptor(new DatanodeID("h3", 5020), "/rackA"),
|
|
|
- new DatanodeDescriptor(new DatanodeID("h4", 5020), "/rackB"),
|
|
|
- new DatanodeDescriptor(new DatanodeID("h5", 5020), "/rackB"),
|
|
|
- new DatanodeDescriptor(new DatanodeID("h6", 5020), "/rackB")
|
|
|
- );
|
|
|
- private final List<DatanodeDescriptor> rackA = nodes.subList(0, 3);
|
|
|
- private final List<DatanodeDescriptor> rackB = nodes.subList(3, 6);
|
|
|
-
|
|
|
+ private List<DatanodeDescriptor> nodes;
|
|
|
+ private List<DatanodeDescriptor> rackA;
|
|
|
+ private List<DatanodeDescriptor> rackB;
|
|
|
+
|
|
|
/**
|
|
|
* Some of these tests exercise code which has some randomness involved -
|
|
|
* ie even if there's a bug, they may pass because the random node selection
|
|
@@ -82,6 +75,16 @@ public class TestBlockManager {
|
|
|
fsn = Mockito.mock(FSNamesystem.class);
|
|
|
Mockito.doReturn(true).when(fsn).hasWriteLock();
|
|
|
bm = new BlockManager(fsn, fsn, conf);
|
|
|
+ nodes = ImmutableList.of(
|
|
|
+ new DatanodeDescriptor(new DatanodeID("1.1.1.1", 5020), "/rackA"),
|
|
|
+ new DatanodeDescriptor(new DatanodeID("2.2.2.2", 5020), "/rackA"),
|
|
|
+ new DatanodeDescriptor(new DatanodeID("3.3.3.3", 5020), "/rackA"),
|
|
|
+ new DatanodeDescriptor(new DatanodeID("4.4.4.4", 5020), "/rackB"),
|
|
|
+ new DatanodeDescriptor(new DatanodeID("5.5.5.5", 5020), "/rackB"),
|
|
|
+ new DatanodeDescriptor(new DatanodeID("6.6.6.6", 5020), "/rackB")
|
|
|
+ );
|
|
|
+ rackA = nodes.subList(0, 3);
|
|
|
+ rackB = nodes.subList(3, 6);
|
|
|
}
|
|
|
|
|
|
private void addNodes(Iterable<DatanodeDescriptor> nodesToAdd) {
|
|
@@ -116,7 +119,7 @@ public class TestBlockManager {
|
|
|
}
|
|
|
|
|
|
private void doBasicTest(int testIndex) {
|
|
|
- List<DatanodeDescriptor> origNodes = nodes(0, 1);
|
|
|
+ List<DatanodeDescriptor> origNodes = getNodes(0, 1);
|
|
|
BlockInfo blockInfo = addBlockOnNodes((long)testIndex, origNodes);
|
|
|
|
|
|
DatanodeDescriptor[] pipeline = scheduleSingleReplication(blockInfo);
|
|
@@ -147,7 +150,7 @@ public class TestBlockManager {
|
|
|
|
|
|
private void doTestTwoOfThreeNodesDecommissioned(int testIndex) throws Exception {
|
|
|
// Block originally on A1, A2, B1
|
|
|
- List<DatanodeDescriptor> origNodes = nodes(0, 1, 3);
|
|
|
+ List<DatanodeDescriptor> origNodes = getNodes(0, 1, 3);
|
|
|
BlockInfo blockInfo = addBlockOnNodes(testIndex, origNodes);
|
|
|
|
|
|
// Decommission two of the nodes (A1, A2)
|
|
@@ -157,7 +160,7 @@ public class TestBlockManager {
|
|
|
assertTrue("Source of replication should be one of the nodes the block " +
|
|
|
"was on. Was: " + pipeline[0],
|
|
|
origNodes.contains(pipeline[0]));
|
|
|
- assertEquals("Should have two targets", 3, pipeline.length);
|
|
|
+ assertEquals("Should have three targets", 3, pipeline.length);
|
|
|
|
|
|
boolean foundOneOnRackA = false;
|
|
|
for (int i = 1; i < pipeline.length; i++) {
|
|
@@ -190,7 +193,7 @@ public class TestBlockManager {
|
|
|
|
|
|
private void doTestAllNodesHoldingReplicasDecommissioned(int testIndex) throws Exception {
|
|
|
// Block originally on A1, A2, B1
|
|
|
- List<DatanodeDescriptor> origNodes = nodes(0, 1, 3);
|
|
|
+ List<DatanodeDescriptor> origNodes = getNodes(0, 1, 3);
|
|
|
BlockInfo blockInfo = addBlockOnNodes(testIndex, origNodes);
|
|
|
|
|
|
// Decommission all of the nodes
|
|
@@ -242,7 +245,7 @@ public class TestBlockManager {
|
|
|
|
|
|
private void doTestOneOfTwoRacksDecommissioned(int testIndex) throws Exception {
|
|
|
// Block originally on A1, A2, B1
|
|
|
- List<DatanodeDescriptor> origNodes = nodes(0, 1, 3);
|
|
|
+ List<DatanodeDescriptor> origNodes = getNodes(0, 1, 3);
|
|
|
BlockInfo blockInfo = addBlockOnNodes(testIndex, origNodes);
|
|
|
|
|
|
// Decommission all of the nodes in rack A
|
|
@@ -252,7 +255,7 @@ public class TestBlockManager {
|
|
|
assertTrue("Source of replication should be one of the nodes the block " +
|
|
|
"was on. Was: " + pipeline[0],
|
|
|
origNodes.contains(pipeline[0]));
|
|
|
- assertEquals("Should have 2 targets", 3, pipeline.length);
|
|
|
+ assertEquals("Should have three targets", 3, pipeline.length);
|
|
|
|
|
|
boolean foundOneOnRackB = false;
|
|
|
for (int i = 1; i < pipeline.length; i++) {
|
|
@@ -273,7 +276,8 @@ public class TestBlockManager {
|
|
|
|
|
|
// the block is still under-replicated. Add a new node. This should allow
|
|
|
// the third off-rack replica.
|
|
|
- DatanodeDescriptor rackCNode = new DatanodeDescriptor(new DatanodeID("h7", 100), "/rackC");
|
|
|
+ DatanodeDescriptor rackCNode =
|
|
|
+ new DatanodeDescriptor(new DatanodeID("7.7.7.7", 100), "/rackC");
|
|
|
addNodes(ImmutableList.of(rackCNode));
|
|
|
try {
|
|
|
DatanodeDescriptor[] pipeline2 = scheduleSingleReplication(blockInfo);
|
|
@@ -359,7 +363,7 @@ public class TestBlockManager {
|
|
|
return blockInfo;
|
|
|
}
|
|
|
|
|
|
- private List<DatanodeDescriptor> nodes(int ... indexes) {
|
|
|
+ private List<DatanodeDescriptor> getNodes(int ... indexes) {
|
|
|
List<DatanodeDescriptor> ret = Lists.newArrayList();
|
|
|
for (int idx : indexes) {
|
|
|
ret.add(nodes.get(idx));
|
|
@@ -368,7 +372,7 @@ public class TestBlockManager {
|
|
|
}
|
|
|
|
|
|
private List<DatanodeDescriptor> startDecommission(int ... indexes) {
|
|
|
- List<DatanodeDescriptor> nodes = nodes(indexes);
|
|
|
+ List<DatanodeDescriptor> nodes = getNodes(indexes);
|
|
|
for (DatanodeDescriptor node : nodes) {
|
|
|
node.startDecommission();
|
|
|
}
|
|
@@ -404,8 +408,9 @@ public class TestBlockManager {
|
|
|
|
|
|
LinkedListMultimap<DatanodeDescriptor, BlockTargetPair> repls = getAllPendingReplications();
|
|
|
assertEquals(1, repls.size());
|
|
|
- Entry<DatanodeDescriptor, BlockTargetPair> repl = repls.entries()
|
|
|
- .iterator().next();
|
|
|
+ Entry<DatanodeDescriptor, BlockTargetPair> repl =
|
|
|
+ repls.entries().iterator().next();
|
|
|
+
|
|
|
DatanodeDescriptor[] targets = repl.getValue().targets;
|
|
|
|
|
|
DatanodeDescriptor[] pipeline = new DatanodeDescriptor[1 + targets.length];
|