}
@Test
public void testShouldNotCompeleteOpenedEntityGroupSuccessfullyIfVersionMismatches()
throws Exception {
EntityGroup entityGroup = null;
try {
int testIndex = 0;
TEST_UTIL.getHBaseTestingUtility().startMiniZKCluster();
TEST_UTIL.getConfiguration().set(FConstants.ZOOKEEPER_QUORUM,
TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_QUORUM));
TEST_UTIL.getConfiguration().set(FConstants.ZOOKEEPER_CLIENT_PORT,
TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT));
final Server server = new MockServer(TEST_UTIL);
FTable htd = FMetaTestUtil
.makeTable("testShouldNotCompeleteOpenedEntityGroupSuccessfullyIfVersionMismatches");
EntityGroupInfo egi = new EntityGroupInfo(Bytes.toBytes(htd
.getTableName()), Bytes.toBytes(testIndex),
Bytes.toBytes(testIndex + 1));
entityGroup = EntityGroup.createEntityGroup(egi,
TEST_UTIL.getConfiguration(), htd, null);
assertNotNull(entityGroup);
AssignmentManager am = Mockito.mock(AssignmentManager.class);
EntityGroupStates rsm = Mockito.mock(EntityGroupStates.class);
Mockito.doReturn(rsm).when(am).getEntityGroupStates();
when(rsm.isEntityGroupInTransition(egi)).thenReturn(false);
when(rsm.getEntityGroupState(egi)).thenReturn(
new EntityGroupState(entityGroup.getEntityGroupInfo(),
EntityGroupState.State.OPEN, System.currentTimeMillis(), server
.getServerName()));
// create a node with OPENED state
zkw = WaspTestingUtility.createAndForceNodeToOpenedState(TEST_UTIL,
entityGroup, server.getServerName());
when(am.getZKTable()).thenReturn(new ZKTable(zkw));
Stat stat = new Stat();
String nodeName = ZKAssign.getNodeName(zkw, entityGroup
.getEntityGroupInfo().getEncodedName());
ZKUtil.getDataAndWatch(zkw, nodeName, stat);
// use the version for the OpenedEntityGroupHandler
OpenedEntityGroupHandler handler = new OpenedEntityGroupHandler(server,
am, entityGroup.getEntityGroupInfo(), server.getServerName(),
stat.getVersion());
// Once again overwrite the same znode so that the version changes.
ZKAssign.transitionNode(zkw, entityGroup.getEntityGroupInfo(),
server.getServerName(), EventType.FSERVER_ZK_ENTITYGROUP_OPENED,
EventType.FSERVER_ZK_ENTITYGROUP_OPENED, stat.getVersion());
// Should not invoke assignmentmanager.entityGroupOnline. If it is
// invoked as per current mocking it will throw null pointer exception.
boolean expectedException = false;
try {
handler.process();
} catch (Exception e) {
expectedException = true;
}
assertFalse("The process method should not throw any exception.",
expectedException);
List<String> znodes = ZKUtil.listChildrenAndWatchForNewChildren(zkw,
zkw.assignmentZNode);
String entityGroupName = znodes.get(0);
assertEquals("The entityGroup should not be opened successfully.",
entityGroupName, entityGroup.getEntityGroupInfo().getEncodedName());
} finally {
EntityGroup.closeEntityGroup(entityGroup);
TEST_UTIL.getHBaseTestingUtility().shutdownMiniZKCluster();
}
}