TServers tservers = new TServers();
TestTabletLocationObtainer ttlo = new TestTabletLocationObtainer(tservers);
TestInstance testInstance = new TestInstance("instance1", "tserver1");
RootTabletLocator rtl = new RootTabletLocator(testInstance);
TabletLocatorImpl rootTabletCache = new TabletLocatorImpl(new Text(Constants.METADATA_TABLE_ID), rtl, ttlo);
TabletLocatorImpl tab1TabletCache = new TabletLocatorImpl(new Text("tab1"), rootTabletCache, ttlo);
locateTabletTest(tab1TabletCache, "r1", null, null);
KeyExtent tab1e = nke("tab1", null, null);
setLocation(tservers, "tserver1", RTE, MTE, "tserver2");
setLocation(tservers, "tserver2", MTE, tab1e, "tserver3");
locateTabletTest(tab1TabletCache, "r1", tab1e, "tserver3");
locateTabletTest(tab1TabletCache, "r2", tab1e, "tserver3");
// simulate a split
KeyExtent tab1e1 = nke("tab1", "g", null);
KeyExtent tab1e2 = nke("tab1", null, "g");
setLocation(tservers, "tserver2", MTE, tab1e1, "tserver4");
setLocation(tservers, "tserver2", MTE, tab1e2, "tserver5");
locateTabletTest(tab1TabletCache, "r1", tab1e, "tserver3");
tab1TabletCache.invalidateCache(tab1e);
locateTabletTest(tab1TabletCache, "r1", tab1e2, "tserver5");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver4");
locateTabletTest(tab1TabletCache, "a", true, tab1e1, "tserver4");
locateTabletTest(tab1TabletCache, "g", tab1e1, "tserver4");
locateTabletTest(tab1TabletCache, "g", true, tab1e2, "tserver5");
// simulate a partial split
KeyExtent tab1e22 = nke("tab1", null, "m");
setLocation(tservers, "tserver2", MTE, tab1e22, "tserver6");
locateTabletTest(tab1TabletCache, "r1", tab1e2, "tserver5");
tab1TabletCache.invalidateCache(tab1e2);
locateTabletTest(tab1TabletCache, "r1", tab1e22, "tserver6");
locateTabletTest(tab1TabletCache, "h", null, null);
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver4");
KeyExtent tab1e21 = nke("tab1", "m", "g");
setLocation(tservers, "tserver2", MTE, tab1e21, "tserver7");
locateTabletTest(tab1TabletCache, "r1", tab1e22, "tserver6");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver7");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver4");
// simulate a migration
setLocation(tservers, "tserver2", MTE, tab1e21, "tserver8");
tab1TabletCache.invalidateCache(tab1e21);
locateTabletTest(tab1TabletCache, "r1", tab1e22, "tserver6");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver4");
// simulate a server failure
setLocation(tservers, "tserver2", MTE, tab1e21, "tserver9");
tab1TabletCache.invalidateCache("tserver8");
locateTabletTest(tab1TabletCache, "r1", tab1e22, "tserver6");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver9");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver4");
// simulate all servers failing
deleteServer(tservers, "tserver1");
deleteServer(tservers, "tserver2");
tab1TabletCache.invalidateCache("tserver4");
tab1TabletCache.invalidateCache("tserver6");
tab1TabletCache.invalidateCache("tserver9");
locateTabletTest(tab1TabletCache, "r1", null, null);
locateTabletTest(tab1TabletCache, "h", null, null);
locateTabletTest(tab1TabletCache, "a", null, null);
testInstance.setRootTabletLocation("tserver4");
setLocation(tservers, "tserver4", RTE, MTE, "tserver5");
setLocation(tservers, "tserver5", MTE, tab1e1, "tserver1");
setLocation(tservers, "tserver5", MTE, tab1e21, "tserver2");
setLocation(tservers, "tserver5", MTE, tab1e22, "tserver3");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver1");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver2");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver3");
// simulate the !METADATA table splitting
KeyExtent mte1 = new KeyExtent(new Text(Constants.METADATA_TABLE_ID), tab1e21.getMetadataEntry(), RTE.getEndRow());
KeyExtent mte2 = new KeyExtent(new Text(Constants.METADATA_TABLE_ID), null, tab1e21.getMetadataEntry());
setLocation(tservers, "tserver4", RTE, mte1, "tserver5");
setLocation(tservers, "tserver4", RTE, mte2, "tserver6");
deleteServer(tservers, "tserver5");
setLocation(tservers, "tserver5", mte1, tab1e1, "tserver7");
setLocation(tservers, "tserver5", mte1, tab1e21, "tserver8");
setLocation(tservers, "tserver6", mte2, tab1e22, "tserver9");
tab1TabletCache.invalidateCache(tab1e1);
tab1TabletCache.invalidateCache(tab1e21);
tab1TabletCache.invalidateCache(tab1e22);
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver7");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver9");
// simulate metadata and regular server down and the reassigned
deleteServer(tservers, "tserver5");
tab1TabletCache.invalidateCache("tserver7");
locateTabletTest(tab1TabletCache, "a", null, null);
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver9");
setLocation(tservers, "tserver4", RTE, mte1, "tserver10");
setLocation(tservers, "tserver10", mte1, tab1e1, "tserver7");
setLocation(tservers, "tserver10", mte1, tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver7");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver9");
tab1TabletCache.invalidateCache("tserver7");
setLocation(tservers, "tserver10", mte1, tab1e1, "tserver2");
locateTabletTest(tab1TabletCache, "a", tab1e1, "tserver2");
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver8");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver9");
// simulate a hole in the !METADATA table, caused by a partial split
KeyExtent mte11 = new KeyExtent(new Text(Constants.METADATA_TABLE_ID), tab1e1.getMetadataEntry(), RTE.getEndRow());
KeyExtent mte12 = new KeyExtent(new Text(Constants.METADATA_TABLE_ID), tab1e21.getMetadataEntry(), tab1e1.getMetadataEntry());
deleteServer(tservers, "tserver10");
setLocation(tservers, "tserver4", RTE, mte12, "tserver10");
setLocation(tservers, "tserver10", mte12, tab1e21, "tserver12");
// at this point should be no info in !METADATA about tab1e1
tab1TabletCache.invalidateCache(tab1e1);
tab1TabletCache.invalidateCache(tab1e21);
locateTabletTest(tab1TabletCache, "a", null, null);
locateTabletTest(tab1TabletCache, "h", tab1e21, "tserver12");
locateTabletTest(tab1TabletCache, "r", tab1e22, "tserver9");
setLocation(tservers, "tserver4", RTE, mte11, "tserver5");