private void testCaseWithPartiallyDisabledState(TableState state, boolean opening)
throws KeeperException, IOException, NodeExistsException {
// Create and startup an executor. This is used by AssignmentManager
// handling zk callbacks.
ExecutorService executor = startupMasterExecutor("testSSHWhenDisableTableInProgress");
// We need a mocked catalog tracker.
CatalogTracker ct = Mockito.mock(CatalogTracker.class);
LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server.getConfiguration());
// Create an AM.
AssignmentManager am = new AssignmentManager(this.server, this.serverManager, ct, balancer,
executor);
if (opening) {
am.regionsInTransition.put(REGIONINFO.getEncodedName(), new RegionState(REGIONINFO,
State.OPENING, System.currentTimeMillis(), SERVERNAME_A));
} else {
// adding region to regions and servers maps.
am.regionOnline(REGIONINFO, SERVERNAME_A);
// adding region in pending close.
am.regionsInTransition.put(REGIONINFO.getEncodedName(), new RegionState(REGIONINFO,
State.PENDING_CLOSE, System.currentTimeMillis(), SERVERNAME_A));
}
if (state == TableState.DISABLING) {
am.getZKTable().setDisablingTable(REGIONINFO.getTableNameAsString());
} else {
am.getZKTable().setDisabledTable(REGIONINFO.getTableNameAsString());
}
RegionTransitionData data = null;
if (opening) {
data =
new RegionTransitionData(EventType.RS_ZK_REGION_OPENING, REGIONINFO.getRegionName(),
SERVERNAME_A);
} else {
data =
new RegionTransitionData(EventType.M_ZK_REGION_CLOSING, REGIONINFO.getRegionName(),
SERVERNAME_A);
}
String node = ZKAssign.getNodeName(this.watcher, REGIONINFO.getEncodedName());
// create znode in M_ZK_REGION_CLOSING state.
ZKUtil.createAndWatch(this.watcher, node, data.getBytes());
try {
processServerShutdownHandler(ct, am, false, null);
// check znode deleted or not.
// In both cases the znode should be deleted.
assertTrue("The znode should be deleted.",ZKUtil.checkExists(this.watcher, node) == -1);
assertTrue("Region state of region in pending close should be removed from rit.",
am.regionsInTransition.isEmpty());
} finally {
executor.shutdown();
am.shutdown();
// Clean up all znodes
ZKAssign.deleteAllNodes(this.watcher);
}
}