HBASE-9287 TestCatalogTracker depends on the execution order

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1516292 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
mbertozzi 2013-08-21 20:21:13 +00:00
parent 4f417a7614
commit a0b240db54
1 changed files with 51 additions and 62 deletions

View File

@ -103,6 +103,17 @@ public class TestCatalogTracker {
} }
@After public void after() { @After public void after() {
try {
// Clean out meta location or later tests will be confused... they presume
// start fresh in zk.
MetaRegionTracker.deleteMetaLocation(this.watcher);
} catch (KeeperException e) {
LOG.warn("Unable to delete META location", e);
}
// Clear out our doctored connection or could mess up subsequent tests.
HConnectionManager.deleteConnection(UTIL.getConfiguration());
this.watcher.close(); this.watcher.close();
} }
@ -124,14 +135,9 @@ public class TestCatalogTracker {
throws IOException, InterruptedException, KeeperException { throws IOException, InterruptedException, KeeperException {
HConnection connection = Mockito.mock(HConnection.class); HConnection connection = Mockito.mock(HConnection.class);
constructAndStartCatalogTracker(connection); constructAndStartCatalogTracker(connection);
try {
MetaRegionTracker.setMetaLocation(this.watcher, MetaRegionTracker.setMetaLocation(this.watcher,
new ServerName("example.com", 1234, System.currentTimeMillis())); new ServerName("example.com", 1234, System.currentTimeMillis()));
} finally {
// Clean out meta location or later tests will be confused... they presume
// start fresh in zk.
MetaRegionTracker.deleteMetaLocation(this.watcher);
}
} }
/** /**
@ -145,33 +151,30 @@ public class TestCatalogTracker {
final ClientProtos.ClientService.BlockingInterface client = final ClientProtos.ClientService.BlockingInterface client =
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
HConnection connection = mockConnection(null, client); HConnection connection = mockConnection(null, client);
try {
Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())). Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())).
thenReturn(GetResponse.newBuilder().build()); thenReturn(GetResponse.newBuilder().build());
final CatalogTracker ct = constructAndStartCatalogTracker(connection); final CatalogTracker ct = constructAndStartCatalogTracker(connection);
ServerName meta = ct.getMetaLocation(); ServerName meta = ct.getMetaLocation();
Assert.assertNull(meta); Assert.assertNull(meta);
Thread t = new Thread() { Thread t = new Thread() {
@Override @Override
public void run() { public void run() {
try { try {
ct.waitForMeta(); ct.waitForMeta();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException("Interrupted", e); throw new RuntimeException("Interrupted", e);
}
} }
}; }
t.start(); };
while (!t.isAlive()) t.start();
Threads.sleep(1); while (!t.isAlive())
Threads.sleep(1); Threads.sleep(1);
assertTrue(t.isAlive()); Threads.sleep(1);
ct.stop(); assertTrue(t.isAlive());
// Join the thread... should exit shortly. ct.stop();
t.join(); // Join the thread... should exit shortly.
} finally { t.join();
HConnectionManager.deleteConnection(UTIL.getConfiguration());
}
} }
private void testVerifyMetaRegionLocationWithException(Exception ex) private void testVerifyMetaRegionLocationWithException(Exception ex)
@ -180,26 +183,17 @@ public class TestCatalogTracker {
final ClientProtos.ClientService.BlockingInterface implementation = final ClientProtos.ClientService.BlockingInterface implementation =
Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
HConnection connection = mockConnection(null, implementation); HConnection connection = mockConnection(null, implementation);
try {
// If a 'get' is called on mocked interface, throw connection refused. // If a 'get' is called on mocked interface, throw connection refused.
Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())). Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())).
thenThrow(new ServiceException(ex)); thenThrow(new ServiceException(ex));
// Now start up the catalogtracker with our doctored Connection. // Now start up the catalogtracker with our doctored Connection.
final CatalogTracker ct = constructAndStartCatalogTracker(connection); final CatalogTracker ct = constructAndStartCatalogTracker(connection);
try {
MetaRegionTracker.setMetaLocation(this.watcher, SN); MetaRegionTracker.setMetaLocation(this.watcher, SN);
long timeout = UTIL.getConfiguration(). long timeout = UTIL.getConfiguration().
getLong("hbase.catalog.verification.timeout", 1000); getLong("hbase.catalog.verification.timeout", 1000);
Assert.assertFalse(ct.verifyMetaRegionLocation(timeout)); Assert.assertFalse(ct.verifyMetaRegionLocation(timeout));
} finally {
// Clean out meta location or later tests will be confused... they
// presume start fresh in zk.
MetaRegionTracker.deleteMetaLocation(this.watcher);
}
} finally {
// Clear out our doctored connection or could mess up subsequent tests.
HConnectionManager.deleteConnection(UTIL.getConfiguration());
}
} }
/** /**
@ -255,15 +249,10 @@ public class TestCatalogTracker {
Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())). Mockito.when(connection.getAdmin(Mockito.any(ServerName.class), Mockito.anyBoolean())).
thenReturn(implementation); thenReturn(implementation);
final CatalogTracker ct = constructAndStartCatalogTracker(connection); final CatalogTracker ct = constructAndStartCatalogTracker(connection);
try {
MetaRegionTracker.setMetaLocation(this.watcher, MetaRegionTracker.setMetaLocation(this.watcher,
new ServerName("example.com", 1234, System.currentTimeMillis())); new ServerName("example.com", 1234, System.currentTimeMillis()));
Assert.assertFalse(ct.verifyMetaRegionLocation(100)); Assert.assertFalse(ct.verifyMetaRegionLocation(100));
} finally {
// Clean out meta location or later tests will be confused... they presume
// start fresh in zk.
MetaRegionTracker.deleteMetaLocation(this.watcher);
}
} }
@Test (expected = NotAllMetaRegionsOnlineException.class) @Test (expected = NotAllMetaRegionsOnlineException.class)