|
@@ -30,6 +30,7 @@ import static org.apache.hadoop.test.MetricsAsserts.assertCounter;
|
|
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
|
|
import static org.apache.hadoop.test.MetricsAsserts.getLongCounter;
|
|
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
|
import static org.apache.hadoop.test.MetricsAsserts.getMetrics;
|
|
import static org.junit.Assert.assertEquals;
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
+import static org.junit.Assert.assertFalse;
|
|
import static org.junit.Assert.assertNull;
|
|
import static org.junit.Assert.assertNull;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertNotNull;
|
|
import static org.junit.Assert.assertSame;
|
|
import static org.junit.Assert.assertSame;
|
|
@@ -127,7 +128,8 @@ public class TestBPOfferService {
|
|
private final int[] heartbeatCounts = new int[3];
|
|
private final int[] heartbeatCounts = new int[3];
|
|
private DataNode mockDn;
|
|
private DataNode mockDn;
|
|
private FsDatasetSpi<?> mockFSDataset;
|
|
private FsDatasetSpi<?> mockFSDataset;
|
|
-
|
|
|
|
|
|
+ private boolean isSlownode;
|
|
|
|
+
|
|
@Before
|
|
@Before
|
|
public void setupMocks() throws Exception {
|
|
public void setupMocks() throws Exception {
|
|
mockNN1 = setupNNMock(0);
|
|
mockNN1 = setupNNMock(0);
|
|
@@ -216,6 +218,23 @@ public class TestBPOfferService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private class HeartbeatIsSlownodeAnswer implements Answer<HeartbeatResponse> {
|
|
|
|
+ private final int nnIdx;
|
|
|
|
+
|
|
|
|
+ HeartbeatIsSlownodeAnswer(int nnIdx) {
|
|
|
|
+ this.nnIdx = nnIdx;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public HeartbeatResponse answer(InvocationOnMock invocation)
|
|
|
|
+ throws Throwable {
|
|
|
|
+ HeartbeatResponse heartbeatResponse = new HeartbeatResponse(
|
|
|
|
+ datanodeCommands[nnIdx], mockHaStatuses[nnIdx], null,
|
|
|
|
+ 0, isSlownode);
|
|
|
|
+
|
|
|
|
+ return heartbeatResponse;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
private class HeartbeatRegisterAnswer implements Answer<HeartbeatResponse> {
|
|
private class HeartbeatRegisterAnswer implements Answer<HeartbeatResponse> {
|
|
private final int nnIdx;
|
|
private final int nnIdx;
|
|
@@ -1182,6 +1201,44 @@ public class TestBPOfferService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Test(timeout = 15000)
|
|
|
|
+ public void testSetIsSlownode() throws Exception {
|
|
|
|
+ assertEquals(mockDn.isSlownode(), false);
|
|
|
|
+ Mockito.when(mockNN1.sendHeartbeat(
|
|
|
|
+ Mockito.any(DatanodeRegistration.class),
|
|
|
|
+ Mockito.any(StorageReport[].class),
|
|
|
|
+ Mockito.anyLong(),
|
|
|
|
+ Mockito.anyLong(),
|
|
|
|
+ Mockito.anyInt(),
|
|
|
|
+ Mockito.anyInt(),
|
|
|
|
+ Mockito.anyInt(),
|
|
|
|
+ Mockito.any(VolumeFailureSummary.class),
|
|
|
|
+ Mockito.anyBoolean(),
|
|
|
|
+ Mockito.any(SlowPeerReports.class),
|
|
|
|
+ Mockito.any(SlowDiskReports.class)))
|
|
|
|
+ .thenAnswer(new HeartbeatIsSlownodeAnswer(0));
|
|
|
|
+
|
|
|
|
+ BPOfferService bpos = setupBPOSForNNs(mockNN1);
|
|
|
|
+ bpos.start();
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ waitForInitialization(bpos);
|
|
|
|
+
|
|
|
|
+ bpos.triggerHeartbeatForTests();
|
|
|
|
+ assertFalse(bpos.isSlownode());
|
|
|
|
+
|
|
|
|
+ isSlownode = true;
|
|
|
|
+ bpos.triggerHeartbeatForTests();
|
|
|
|
+ assertTrue(bpos.isSlownode());
|
|
|
|
+
|
|
|
|
+ isSlownode = false;
|
|
|
|
+ bpos.triggerHeartbeatForTests();
|
|
|
|
+ assertFalse(bpos.isSlownode());
|
|
|
|
+ } finally {
|
|
|
|
+ bpos.stop();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Test(timeout = 15000)
|
|
@Test(timeout = 15000)
|
|
public void testCommandProcessingThread() throws Exception {
|
|
public void testCommandProcessingThread() throws Exception {
|
|
Configuration conf = new HdfsConfiguration();
|
|
Configuration conf = new HdfsConfiguration();
|