HBASE-6606 Test for reconnecting with HBaseAdmin using unmanaged HConnection

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1376711 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-08-23 21:44:51 +00:00
parent b02f807aa3
commit 1e945238f3
1 changed files with 50 additions and 9 deletions

View File

@ -3937,6 +3937,24 @@ public class TestFromClientSide {
} }
} }
/**
* creates an HTable for tableName using an unmanaged HConnection.
*
* @param tableName - table to create
* @return the created HTable object
* @throws IOException
*/
HTable createUnmangedHConnectionHTable(final byte [] tableName) throws IOException {
TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY);
HConnection conn = HConnectionManager.createConnection(TEST_UTIL.getConfiguration());
ExecutorService pool = new ThreadPoolExecutor(1, Integer.MAX_VALUE,
60, TimeUnit.SECONDS,
new SynchronousQueue<Runnable>(),
new DaemonThreadFactory("test-from-client-pool"));
((ThreadPoolExecutor)pool).allowCoreThreadTimeOut(true);
return new HTable(tableName, conn, pool);
}
/** /**
* simple test that just executes parts of the client * simple test that just executes parts of the client
* API that accept a pre-created HConnection instance * API that accept a pre-created HConnection instance
@ -3946,18 +3964,41 @@ public class TestFromClientSide {
@Test @Test
public void testUnmanagedHConnection() throws IOException { public void testUnmanagedHConnection() throws IOException {
final byte[] tableName = Bytes.toBytes("testUnmanagedHConnection"); final byte[] tableName = Bytes.toBytes("testUnmanagedHConnection");
TEST_UTIL.createTable(tableName, HConstants.CATALOG_FAMILY); HTable t = createUnmangedHConnectionHTable(tableName);
HConnection conn = HConnectionManager.createConnection(TEST_UTIL HBaseAdmin ha = new HBaseAdmin(t.getConnection());
.getConfiguration()); assertTrue(ha.tableExists(tableName));
ExecutorService pool = new ThreadPoolExecutor(1, Integer.MAX_VALUE, assertTrue(t.get(new Get(ROW)).isEmpty());
60, TimeUnit.SECONDS, }
new SynchronousQueue<Runnable>(),
new DaemonThreadFactory("test-from-client-pool")); /**
((ThreadPoolExecutor)pool).allowCoreThreadTimeOut(true); * test of that unmanaged HConnections are able to reconnect
HTable t = new HTable(tableName, conn, pool); * properly (see HBASE-5058)
*
* @throws Exception
*/
@Test
public void testUnmanagedHConnectionReconnect() throws Exception {
final byte[] tableName = Bytes.toBytes("testUnmanagedHConnectionReconnect");
HTable t = createUnmangedHConnectionHTable(tableName);
HConnection conn = t.getConnection();
HBaseAdmin ha = new HBaseAdmin(conn); HBaseAdmin ha = new HBaseAdmin(conn);
assertTrue(ha.tableExists(tableName)); assertTrue(ha.tableExists(tableName));
assertTrue(t.get(new Get(ROW)).isEmpty()); assertTrue(t.get(new Get(ROW)).isEmpty());
// stop the master
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
cluster.stopMaster(0, false);
cluster.waitOnMaster(0);
// start up a new master
cluster.startMaster();
assertTrue(cluster.waitForActiveAndReadyMaster());
// test that the same unmanaged connection works with a new
// HBaseAdmin and can connect to the new master;
HBaseAdmin newAdmin = new HBaseAdmin(conn);
assertTrue(newAdmin.tableExists(tableName));
assert(newAdmin.getClusterStatus().getServersSize() == SLAVES);
} }
@Test @Test