Index: hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java (revision 1424815) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplication.java (working copy) @@ -45,10 +45,10 @@ import org.apache.hadoop.hbase.mapreduce.replication.VerifyReplication; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.apache.hadoop.hbase.util.JVMClusterUtil; import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster; import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher; import org.apache.hadoop.mapreduce.Job; +import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -64,10 +64,8 @@ private static Configuration conf2; private static Configuration CONF_WITH_LOCALFS; - private static ZooKeeperWatcher zkw1; - private static ZooKeeperWatcher zkw2; - private static ReplicationAdmin admin; + private static MiniZooKeeperCluster miniZK; private static HTable htable1; private static HTable htable2; @@ -107,11 +105,15 @@ utility1 = new HBaseTestingUtility(conf1); utility1.startMiniZKCluster(); - MiniZooKeeperCluster miniZK = utility1.getZkCluster(); + miniZK = utility1.getZkCluster(); + // By setting the mini ZK cluster through this method, even though this is + // already utility1's mini ZK cluster, we are telling utility1 not to shut + // the mini ZK cluster when we shut down the HBase cluster. + utility1.setZkCluster(miniZK); // Have to reget conf1 in case zk cluster location different // than default conf1 = utility1.getConfiguration(); - zkw1 = new ZooKeeperWatcher(conf1, "cluster1", null, true); + new ZooKeeperWatcher(conf1, "cluster1", null, true); admin = new ReplicationAdmin(conf1); LOG.info("Setup first Zk"); @@ -124,16 +126,29 @@ utility2 = new HBaseTestingUtility(conf2); utility2.setZkCluster(miniZK); - zkw2 = new ZooKeeperWatcher(conf2, "cluster2", null, true); + new ZooKeeperWatcher(conf2, "cluster2", null, true); admin.addPeer("2", utility2.getClusterKey()); setIsReplication(true); LOG.info("Setup second Zk"); CONF_WITH_LOCALFS = HBaseConfiguration.create(conf1); - utility1.startMiniCluster(3); - utility2.startMiniCluster(3); + } + private static void setIsReplication(boolean rep) throws Exception { + LOG.info("Set rep " + rep); + admin.setReplicating(rep); + Thread.sleep(SLEEP_TIME); + } + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + utility1.startMiniCluster(2); + utility2.startMiniCluster(2); + HTableDescriptor table = new HTableDescriptor(tableName); HColumnDescriptor fam = new HColumnDescriptor(famName); fam.setScope(HConstants.REPLICATION_SCOPE_GLOBAL); @@ -149,57 +164,16 @@ htable2 = new HTable(conf2, tableName); } - private static void setIsReplication(boolean rep) throws Exception { - LOG.info("Set rep " + rep); - admin.setReplicating(rep); - Thread.sleep(SLEEP_TIME); - } - /** * @throws java.lang.Exception */ - @Before - public void setUp() throws Exception { - - // Starting and stopping replication can make us miss new logs, - // rolling like this makes sure the most recent one gets added to the queue - for ( JVMClusterUtil.RegionServerThread r : - utility1.getHBaseCluster().getRegionServerThreads()) { - r.getRegionServer().getWAL().rollWriter(); - } - utility1.truncateTable(tableName); - // truncating the table will send one Delete per row to the slave cluster - // in an async fashion, which is why we cannot just call truncateTable on - // utility2 since late writes could make it to the slave in some way. - // Instead, we truncate the first table and wait for all the Deletes to - // make it to the slave. - Scan scan = new Scan(); - int lastCount = 0; - for (int i = 0; i < NB_RETRIES; i++) { - if (i==NB_RETRIES-1) { - fail("Waited too much time for truncate"); - } - ResultScanner scanner = htable2.getScanner(scan); - Result[] res = scanner.next(NB_ROWS_IN_BIG_BATCH); - scanner.close(); - if (res.length != 0) { - if (res.length < lastCount) { - i--; // Don't increment timeout if we make progress - } - lastCount = res.length; - LOG.info("Still got " + res.length + " rows"); - Thread.sleep(SLEEP_TIME); - } else { - break; - } - } + @AfterClass + public static void tearDownAfterClass() throws Exception { + miniZK.shutdown(); } - /** - * @throws java.lang.Exception - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { + @After + public void tearDown() throws Exception { utility2.shutdownMiniCluster(); utility1.shutdownMiniCluster(); }