use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.
the class TestEndPoint method testHeartbeat.
@Test
public void testHeartbeat() throws Exception {
DatanodeDetails dataNode = randomDatanodeDetails();
try (EndpointStateMachine rpcEndPoint = createEndpoint(SCMTestUtils.getConf(), serverAddress, 1000)) {
SCMHeartbeatRequestProto request = SCMHeartbeatRequestProto.newBuilder().setDatanodeDetails(dataNode.getProtoBufMessage()).setNodeReport(HddsTestUtils.createNodeReport(Arrays.asList(getStorageReports(dataNode.getUuid())), Arrays.asList(getMetadataStorageReports(dataNode.getUuid())))).build();
SCMHeartbeatResponseProto responseProto = rpcEndPoint.getEndPoint().sendHeartbeat(request);
Assert.assertNotNull(responseProto);
Assert.assertEquals(0, responseProto.getCommandsCount());
}
}
use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.
the class TestEndPoint method testRegister.
@Test
public void testRegister() throws Exception {
DatanodeDetails nodeToRegister = randomDatanodeDetails();
try (EndpointStateMachine rpcEndPoint = createEndpoint(SCMTestUtils.getConf(), serverAddress, 1000)) {
SCMRegisteredResponseProto responseProto = rpcEndPoint.getEndPoint().register(nodeToRegister.getExtendedProtoBufMessage(), HddsTestUtils.createNodeReport(Arrays.asList(getStorageReports(nodeToRegister.getUuid())), Arrays.asList(getMetadataStorageReports(nodeToRegister.getUuid()))), HddsTestUtils.getRandomContainerReports(10), HddsTestUtils.getRandomPipelineReports(), defaultLayoutVersionProto());
Assert.assertNotNull(responseProto);
Assert.assertEquals(nodeToRegister.getUuidString(), responseProto.getDatanodeUUID());
Assert.assertNotNull(responseProto.getClusterID());
Assert.assertEquals(10, scmServerImpl.getContainerCountsForDatanode(nodeToRegister));
Assert.assertEquals(1, scmServerImpl.getNodeReportsCount(nodeToRegister));
}
}
use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.
the class TestEndPoint method testGetVersionAssertRpcTimeOut.
@Test
public /**
* This test makes a getVersionRPC call, but the DummyStorageServer is
* going to respond little slowly. We will assert that we are still in the
* GETVERSION state after the timeout.
*/
void testGetVersionAssertRpcTimeOut() throws Exception {
final long rpcTimeout = 1000;
final long tolerance = 100;
OzoneConfiguration conf = SCMTestUtils.getConf();
try (EndpointStateMachine rpcEndPoint = createEndpoint(conf, serverAddress, (int) rpcTimeout)) {
rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
DatanodeDetails datanodeDetails = randomDatanodeDetails();
OzoneContainer ozoneContainer = new OzoneContainer(datanodeDetails, conf, getContext(datanodeDetails), null);
VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint, conf, ozoneContainer);
scmServerImpl.setRpcResponseDelay(1500);
long start = Time.monotonicNow();
EndpointStateMachine.EndPointStates newState = versionTask.call();
long end = Time.monotonicNow();
scmServerImpl.setRpcResponseDelay(0);
Assert.assertThat(end - start, lessThanOrEqualTo(rpcTimeout + tolerance));
Assert.assertEquals(EndpointStateMachine.EndPointStates.GETVERSION, newState);
}
}
use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.
the class TestMiniOzoneCluster method testDNstartAfterSCM.
/**
* Test that a DN can register with SCM even if it was started before the SCM.
* @throws Exception
*/
@Test(timeout = 100000)
public void testDNstartAfterSCM() throws Exception {
// Start a cluster with 3 DN
cluster = MiniOzoneCluster.newBuilder(conf).setNumDatanodes(3).build();
cluster.waitForClusterToBeReady();
// Stop the SCM
StorageContainerManager scm = cluster.getStorageContainerManager();
scm.stop();
// Restart DN
cluster.restartHddsDatanode(0, false);
// DN should be in GETVERSION state till the SCM is restarted.
// Check DN endpoint state for 20 seconds
DatanodeStateMachine dnStateMachine = cluster.getHddsDatanodes().get(0).getDatanodeStateMachine();
for (int i = 0; i < 20; i++) {
for (EndpointStateMachine endpoint : dnStateMachine.getConnectionManager().getValues()) {
Assert.assertEquals(EndpointStateMachine.EndPointStates.GETVERSION, endpoint.getState());
}
Thread.sleep(1000);
}
// DN should successfully register with the SCM after SCM is restarted.
// Restart the SCM
cluster.restartStorageContainerManager(true);
// Wait for DN to register
cluster.waitForClusterToBeReady();
// DN should be in HEARTBEAT state after registering with the SCM
for (EndpointStateMachine endpoint : dnStateMachine.getConnectionManager().getValues()) {
Assert.assertEquals(EndpointStateMachine.EndPointStates.HEARTBEAT, endpoint.getState());
}
}
use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.
the class TestRunningDatanodeState method testAwait.
@Test
public void testAwait() throws InterruptedException {
SCMConnectionManager connectionManager = Mockito.mock(SCMConnectionManager.class);
List<EndpointStateMachine> stateMachines = new ArrayList<>();
when(connectionManager.getValues()).thenReturn(stateMachines);
RunningDatanodeState state = new RunningDatanodeState(null, connectionManager, null);
int threadPoolSize = 2;
ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
ExecutorCompletionService ecs = new ExecutorCompletionService<>(executorService);
state.setExecutorCompletionService(ecs);
for (int i = 0; i < threadPoolSize; i++) {
stateMachines.add(new EndpointStateMachine(null, null, null));
}
CompletableFuture<EndpointStateMachine.EndPointStates> futureOne = new CompletableFuture<>();
for (int i = 0; i < threadPoolSize; i++) {
ecs.submit(() -> futureOne.get());
}
long startTime = Time.monotonicNow();
state.await(500, TimeUnit.MILLISECONDS);
long endTime = Time.monotonicNow();
Assert.assertTrue((endTime - startTime) >= 500);
futureOne.complete(SHUTDOWN);
CompletableFuture<EndpointStateMachine.EndPointStates> futureTwo = new CompletableFuture<>();
for (int i = 0; i < threadPoolSize; i++) {
ecs.submit(() -> futureTwo.get());
}
futureTwo.complete(SHUTDOWN);
startTime = Time.monotonicNow();
state.await(500, TimeUnit.MILLISECONDS);
endTime = Time.monotonicNow();
Assert.assertTrue((endTime - startTime) < 500);
executorService.shutdown();
}
Aggregations