|
@@ -237,15 +237,7 @@ public class TestBlockManagerSafeMode {
|
|
|
BlockInfo blockInfo = mock(BlockInfo.class);
|
|
|
doReturn(false).when(blockInfo).isStriped();
|
|
|
bmSafeMode.incrementSafeBlockCount(1, blockInfo);
|
|
|
- if (i < BLOCK_THRESHOLD) {
|
|
|
- assertEquals(i, getblockSafe());
|
|
|
- assertTrue(bmSafeMode.isInSafeMode());
|
|
|
- } else {
|
|
|
- // block manager leaves safe mode if block threshold is met
|
|
|
- assertFalse(bmSafeMode.isInSafeMode());
|
|
|
- // the increment will be a no-op if safe mode is OFF
|
|
|
- assertEquals(BLOCK_THRESHOLD, getblockSafe());
|
|
|
- }
|
|
|
+ assertSafeModeIsLeftAtThreshold(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -314,14 +306,35 @@ public class TestBlockManagerSafeMode {
|
|
|
bmSafeMode.decrementSafeBlockCount(blockInfo);
|
|
|
bmSafeMode.incrementSafeBlockCount(1, blockInfo);
|
|
|
|
|
|
- if (i < BLOCK_THRESHOLD) {
|
|
|
- assertEquals(i, getblockSafe());
|
|
|
- assertTrue(bmSafeMode.isInSafeMode());
|
|
|
- } else {
|
|
|
- // block manager leaves safe mode if block threshold is met
|
|
|
- assertEquals(BLOCK_THRESHOLD, getblockSafe());
|
|
|
- assertFalse(bmSafeMode.isInSafeMode());
|
|
|
- }
|
|
|
+ assertSafeModeIsLeftAtThreshold(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Test when the block safe increment and decrement interleave
|
|
|
+ * for striped blocks.
|
|
|
+ *
|
|
|
+ * Both the increment and decrement will be a no-op if the safe mode is OFF.
|
|
|
+ * The safe mode status lifecycle: OFF -> PENDING_THRESHOLD -> OFF
|
|
|
+ */
|
|
|
+ @Test(timeout = 30000)
|
|
|
+ public void testIncrementAndDecrementStripedSafeBlockCount() {
|
|
|
+ bmSafeMode.activate(BLOCK_TOTAL);
|
|
|
+ Whitebox.setInternalState(bmSafeMode, "extension", 0);
|
|
|
+
|
|
|
+ // this number is used only by the decrementSafeBlockCount method
|
|
|
+ final int liveReplicasWhenDecrementing = 1;
|
|
|
+ final short realDataBlockNum = 2;
|
|
|
+ mockBlockManagerForStripedBlockSafeDecrement(liveReplicasWhenDecrementing);
|
|
|
+ for (long i = 1; i <= BLOCK_TOTAL; i++) {
|
|
|
+ BlockInfoStriped blockInfo = mock(BlockInfoStriped.class);
|
|
|
+ when(blockInfo.getRealDataBlockNum()).thenReturn(realDataBlockNum);
|
|
|
+
|
|
|
+ bmSafeMode.incrementSafeBlockCount(realDataBlockNum, blockInfo);
|
|
|
+ bmSafeMode.decrementSafeBlockCount(blockInfo);
|
|
|
+ bmSafeMode.incrementSafeBlockCount(realDataBlockNum, blockInfo);
|
|
|
+
|
|
|
+ assertSafeModeIsLeftAtThreshold(i);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -508,10 +521,27 @@ public class TestBlockManagerSafeMode {
|
|
|
*/
|
|
|
private void mockBlockManagerForBlockSafeDecrement() {
|
|
|
BlockInfo storedBlock = mock(BlockInfo.class);
|
|
|
+ mockBlockManagerForBlockSafeDecrement(storedBlock, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Mock block manager internal state for decrement safe block
|
|
|
+ * in case of striped block.
|
|
|
+ */
|
|
|
+ private void mockBlockManagerForStripedBlockSafeDecrement(int liveReplicas) {
|
|
|
+ BlockInfo storedBlock = mock(BlockInfoStriped.class);
|
|
|
+ mockBlockManagerForBlockSafeDecrement(storedBlock, liveReplicas);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Mock block manager internal state for decrement safe block.
|
|
|
+ */
|
|
|
+ private void mockBlockManagerForBlockSafeDecrement(BlockInfo storedBlock,
|
|
|
+ int liveReplicas) {
|
|
|
when(storedBlock.isComplete()).thenReturn(true);
|
|
|
doReturn(storedBlock).when(bm).getStoredBlock(any(Block.class));
|
|
|
NumberReplicas numberReplicas = mock(NumberReplicas.class);
|
|
|
- when(numberReplicas.liveReplicas()).thenReturn(0);
|
|
|
+ when(numberReplicas.liveReplicas()).thenReturn(liveReplicas);
|
|
|
doReturn(numberReplicas).when(bm).countNodes(any(BlockInfo.class));
|
|
|
}
|
|
|
|
|
@@ -552,4 +582,19 @@ public class TestBlockManagerSafeMode {
|
|
|
private long getblockSafe() {
|
|
|
return (long)Whitebox.getInternalState(bmSafeMode, "blockSafe");
|
|
|
}
|
|
|
+
|
|
|
+ private void assertSafeModeIsLeftAtThreshold(long blockIndex) {
|
|
|
+ if (blockIndex < BLOCK_THRESHOLD) {
|
|
|
+ assertEquals("Current block index should be equal to " +
|
|
|
+ "the safe block counter.", blockIndex, getblockSafe());
|
|
|
+ assertTrue("Block Manager should stay in safe mode until " +
|
|
|
+ "the safe block threshold is reached.", bmSafeMode.isInSafeMode());
|
|
|
+ } else {
|
|
|
+ assertEquals("If safe block threshold is reached, safe block " +
|
|
|
+ "counter should not increase further.",
|
|
|
+ BLOCK_THRESHOLD, getblockSafe());
|
|
|
+ assertFalse("Block manager leaves safe mode if block " +
|
|
|
+ "threshold is met.", bmSafeMode.isInSafeMode());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|