public void testAvatarDatanodeRetryRegister() throws Exception {
Configuration conf = new Configuration();
conf.setLong("dfs.heartbeat.interval", 1);
InjectionHandler.set(new TestAvatarDatanodeRetryRegisterHandler());
MiniAvatarCluster.createAndStartZooKeeper();
MiniAvatarCluster cluster = new MiniAvatarCluster(conf, 1, true, null, null);
try {
FSNamesystem ns = cluster.getPrimaryAvatar(0).avatar.namesystem;
// These two lines make sure the datanode is marked as dead and is no longer registered.
ns.setDatanodeDead(ns.getDatanode(cluster.getDataNodes().get(0)
.getDNRegistrationForNS(cluster.getNamespaceId(0))));
ns.removeDatanode(cluster.getDataNodes().get(0)
.getDNRegistrationForNS(cluster.getNamespaceId(0)));
assertEquals(0,
ns.getNameNode().getDatanodeReport(DatanodeReportType.LIVE).length);
int livenodes = ns.getNameNode().getDatanodeReport(DatanodeReportType.LIVE).length;
// Wait for the datanode to register successfully.
while (registrations != 1 || livenodes != 1) {
System.out.println("Waiting for registrations : " + registrations);
Thread.sleep(1000);
livenodes = ns.getNameNode().getDatanodeReport(DatanodeReportType.LIVE).length;
}
assertEquals(1,
ns.getNameNode().getDatanodeReport(DatanodeReportType.LIVE).length);
assertEquals(1, registrations);
} finally {
cluster.shutDown();
MiniAvatarCluster.shutDownZooKeeper();
}
}