You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/08/23 23:44:51 UTC

svn commit: r1376711 - /hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Author: stack
Date: Thu Aug 23 21:44:51 2012
New Revision: 1376711

URL: http://svn.apache.org/viewvc?rev=1376711&view=rev
Log:
HBASE-6606 Test for reconnecting with HBaseAdmin using unmanaged HConnection

Modified:
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java?rev=1376711&r1=1376710&r2=1376711&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java Thu Aug 23 21:44:51 2012
@@ -3938,6 +3938,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
    * API that accept a pre-created HConnection instance
    *
@@ -3946,18 +3964,41 @@ public class TestFromClientSide {
   @Test
   public void testUnmanagedHConnection() throws IOException {
     final byte[] tableName = Bytes.toBytes("testUnmanagedHConnection");
-    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);
-    HTable t = new HTable(tableName, conn, pool);
+    HTable t = createUnmangedHConnectionHTable(tableName);
+    HBaseAdmin ha = new HBaseAdmin(t.getConnection());
+    assertTrue(ha.tableExists(tableName));
+    assertTrue(t.get(new Get(ROW)).isEmpty());
+  }
+
+  /**
+   * test of that unmanaged HConnections are able to reconnect
+   * 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);
     assertTrue(ha.tableExists(tableName));
     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