You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2017/11/17 21:20:38 UTC
[06/13] hbase git commit: HBASE-19114 Split out o.a.h.h.zookeeper
from hbase-server and hbase-client
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java
index a9896ce..2e555a9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestMultiSlaveReplication.java
@@ -28,7 +28,6 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.util.Arrays;
-import java.util.List;
import java.util.concurrent.CountDownLatch;
import org.apache.commons.logging.Log;
@@ -39,20 +38,18 @@ import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Admin;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
import org.apache.hadoop.hbase.coprocessor.CoprocessorHost;
import org.apache.hadoop.hbase.regionserver.HRegion;
-import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.regionserver.wal.WALActionsListener;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -104,7 +101,7 @@ public class TestMultiSlaveReplication {
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
utility1.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf1, "cluster1", null, true);
+ new ZKWatcher(conf1, "cluster1", null, true);
conf2 = new Configuration(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
@@ -114,11 +111,11 @@ public class TestMultiSlaveReplication {
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf2, "cluster2", null, true);
+ new ZKWatcher(conf2, "cluster2", null, true);
utility3 = new HBaseTestingUtility(conf3);
utility3.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf3, "cluster3", null, true);
+ new ZKWatcher(conf3, "cluster3", null, true);
table = new HTableDescriptor(tableName);
HColumnDescriptor fam = new HColumnDescriptor(famName);
@@ -190,7 +187,7 @@ public class TestMultiSlaveReplication {
// Even if the log was rolled in the middle of the replication
// "row" is still replication.
checkRow(row, 1, htable2);
- // Replication thread of cluster 2 may be sleeping, and since row2 is not there in it,
+ // Replication thread of cluster 2 may be sleeping, and since row2 is not there in it,
// we should wait before checking.
checkWithWait(row, 1, htable3);
@@ -244,7 +241,7 @@ public class TestMultiSlaveReplication {
region.getWAL().unregisterWALActionsListener(listener);
}
-
+
private void checkWithWait(byte[] row, int count, Table table) throws Exception {
Get get = new Get(row);
for (int i = 0; i < NB_RETRIES; i++) {
@@ -267,7 +264,7 @@ public class TestMultiSlaveReplication {
}
}
}
-
+
private void checkRow(byte[] row, int count, Table... tables) throws IOException {
Get get = new Get(row);
for (Table table : tables) {
@@ -299,7 +296,7 @@ public class TestMultiSlaveReplication {
if (removedFromAll) {
break;
} else {
- Thread.sleep(SLEEP_TIME);
+ Thread.sleep(SLEEP_TIME);
}
}
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestPerTableCFReplication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestPerTableCFReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestPerTableCFReplication.java
index 6572404..84ce9a3 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestPerTableCFReplication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestPerTableCFReplication.java
@@ -50,7 +50,7 @@ import org.apache.hadoop.hbase.testclassification.FlakeyTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -114,7 +114,7 @@ public class TestPerTableCFReplication {
utility1 = new HBaseTestingUtility(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
- new ZooKeeperWatcher(conf1, "cluster1", null, true);
+ new ZKWatcher(conf1, "cluster1", null, true);
conf2 = new Configuration(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
@@ -124,11 +124,11 @@ public class TestPerTableCFReplication {
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf2, "cluster3", null, true);
+ new ZKWatcher(conf2, "cluster3", null, true);
utility3 = new HBaseTestingUtility(conf3);
utility3.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf3, "cluster3", null, true);
+ new ZKWatcher(conf3, "cluster3", null, true);
table = new HTableDescriptor(tableName);
HColumnDescriptor fam = new HColumnDescriptor(famName);
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java
index 58b97b9..f7d1009 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationBase.java
@@ -40,7 +40,7 @@ import org.apache.hadoop.hbase.client.replication.ReplicationAdmin;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runners.Parameterized.Parameter;
@@ -64,8 +64,8 @@ public class TestReplicationBase {
protected static Configuration conf2;
protected static Configuration CONF_WITH_LOCALFS;
- protected static ZooKeeperWatcher zkw1;
- protected static ZooKeeperWatcher zkw2;
+ protected static ZKWatcher zkw1;
+ protected static ZKWatcher zkw2;
protected static ReplicationAdmin admin;
protected static Admin hbaseAdmin;
@@ -127,8 +127,8 @@ public class TestReplicationBase {
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
// Have to reget conf1 in case zk cluster location different
// than default
- conf1 = utility1.getConfiguration();
- zkw1 = new ZooKeeperWatcher(conf1, "cluster1", null, true);
+ conf1 = utility1.getConfiguration();
+ zkw1 = new ZKWatcher(conf1, "cluster1", null, true);
admin = new ReplicationAdmin(conf1);
LOG.info("Setup first Zk");
@@ -140,7 +140,7 @@ public class TestReplicationBase {
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- zkw2 = new ZooKeeperWatcher(conf2, "cluster2", null, true);
+ zkw2 = new ZKWatcher(conf2, "cluster2", null, true);
LOG.info("Setup second Zk");
CONF_WITH_LOCALFS = HBaseConfiguration.create(conf1);
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java
index cc09751..97daa63 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateHBaseImpl.java
@@ -30,8 +30,8 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.AfterClass;
@@ -54,7 +54,7 @@ public class TestReplicationStateHBaseImpl {
private static Configuration conf;
private static HBaseTestingUtility utility;
- private static ZooKeeperWatcher zkw;
+ private static ZKWatcher zkw;
private static String replicationZNode;
private static ReplicationQueues rq1;
@@ -413,7 +413,7 @@ public class TestReplicationStateHBaseImpl {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return null;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java
index dde7868..bb9f665 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationStateZKImpl.java
@@ -41,8 +41,8 @@ import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
import org.apache.hadoop.hbase.zookeeper.ZKConfig;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.apache.zookeeper.KeeperException;
import org.junit.After;
import org.junit.AfterClass;
@@ -58,7 +58,7 @@ public class TestReplicationStateZKImpl extends TestReplicationStateBasic {
private static Configuration conf;
private static HBaseTestingUtility utility;
- private static ZooKeeperWatcher zkw;
+ private static ZKWatcher zkw;
private static String replicationZNode;
private ReplicationQueuesZKImpl rqZK;
@@ -80,7 +80,7 @@ public class TestReplicationStateZKImpl extends TestReplicationStateBasic {
// Add a dummy region server and set up the cluster id
Configuration testConf = new Configuration(conf);
testConf.set(HConstants.ZOOKEEPER_ZNODE_PARENT, baseZKNode);
- ZooKeeperWatcher zkw1 = new ZooKeeperWatcher(testConf, "test1", null);
+ ZKWatcher zkw1 = new ZKWatcher(testConf, "test1", null);
String fakeRs = ZNodePaths.joinZNode(zkw1.znodePaths.rsZNode, "hostname1.example.org:1234");
ZKUtil.createWithParents(zkw1, fakeRs);
ZKClusterId.setClusterId(zkw1, new ClusterId());
@@ -152,7 +152,7 @@ public class TestReplicationStateZKImpl extends TestReplicationStateBasic {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return zkw;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTableBase.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTableBase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTableBase.java
index 83fdad7..665eedb 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTableBase.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTableBase.java
@@ -23,7 +23,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.ReplicationTests;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -43,7 +43,7 @@ public class TestReplicationTableBase {
private static long TIME_OUT_MILLIS = 3000;
private static Configuration conf;
private static HBaseTestingUtility utility;
- private static ZooKeeperWatcher zkw;
+ private static ZKWatcher zkw;
private static ReplicationTableBase rb;
private static ReplicationQueues rq;
private static ReplicationQueuesClient rqc;
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java
index f6e7b39..2db4f76 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationTrackerZKImpl.java
@@ -43,8 +43,8 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -67,7 +67,7 @@ public class TestReplicationTrackerZKImpl {
private static HBaseTestingUtility utility;
// Each one of the below variables are reinitialized before every test case
- private ZooKeeperWatcher zkw;
+ private ZKWatcher zkw;
private ReplicationPeers rp;
private ReplicationTracker rt;
private AtomicInteger rsRemovedCount;
@@ -82,7 +82,7 @@ public class TestReplicationTrackerZKImpl {
utility = new HBaseTestingUtility();
utility.startMiniZKCluster();
conf = utility.getConfiguration();
- ZooKeeperWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility);
+ ZKWatcher zk = HBaseTestingUtility.getZooKeeperWatcher(utility);
ZKUtil.createWithParents(zk, zk.znodePaths.rsZNode);
}
@@ -193,7 +193,7 @@ public class TestReplicationTrackerZKImpl {
int exists = 0;
int hyphen = 0;
rp.registerPeer("6", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()));
-
+
try{
rp.registerPeer("6", new ReplicationPeerConfig().setClusterKey(utility.getClusterKey()));
}catch(IllegalArgumentException e){
@@ -207,11 +207,11 @@ public class TestReplicationTrackerZKImpl {
}
assertEquals(1, exists);
assertEquals(1, hyphen);
-
+
// clean up
rp.unregisterPeer("6");
}
-
+
private class DummyReplicationListener implements ReplicationListener {
@Override
@@ -252,7 +252,7 @@ public class TestReplicationTrackerZKImpl {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return zkw;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestSerialReplication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestSerialReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestSerialReplication.java
index 7a8e639..1c5aa71 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestSerialReplication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestSerialReplication.java
@@ -54,7 +54,7 @@ import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
@@ -102,14 +102,14 @@ public class TestSerialReplication {
utility1 = new HBaseTestingUtility(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
- new ZooKeeperWatcher(conf1, "cluster1", null, true);
+ new ZKWatcher(conf1, "cluster1", null, true);
conf2 = new Configuration(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf2, "cluster2", null, true);
+ new ZKWatcher(conf2, "cluster2", null, true);
utility1.startMiniCluster(1, 10);
utility2.startMiniCluster(1, 1);
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestTableCFsUpdater.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestTableCFsUpdater.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestTableCFsUpdater.java
index 1a02317..cb895ca 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestTableCFsUpdater.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/master/TestTableCFsUpdater.java
@@ -33,7 +33,7 @@ import org.apache.hadoop.hbase.testclassification.ReplicationTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -55,7 +55,7 @@ public class TestTableCFsUpdater extends TableCFsUpdater {
private static final Log LOG = LogFactory.getLog(TestTableCFsUpdater.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- private static ZooKeeperWatcher zkw = null;
+ private static ZKWatcher zkw = null;
private static Abortable abortable = null;
@Rule
@@ -80,7 +80,7 @@ public class TestTableCFsUpdater extends TableCFsUpdater {
return false;
}
};
- zkw = new ZooKeeperWatcher(conf, "TableCFs", abortable, true);
+ zkw = new ZKWatcher(conf, "TableCFs", abortable, true);
}
@AfterClass
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalThrottler.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalThrottler.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalThrottler.java
index 2469c7c..9b1648f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalThrottler.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestGlobalThrottler.java
@@ -48,7 +48,7 @@ import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -86,14 +86,14 @@ public class TestGlobalThrottler {
utility1 = new HBaseTestingUtility(conf1);
utility1.startMiniZKCluster();
MiniZooKeeperCluster miniZK = utility1.getZkCluster();
- new ZooKeeperWatcher(conf1, "cluster1", null, true);
+ new ZKWatcher(conf1, "cluster1", null, true);
conf2 = new Configuration(conf1);
conf2.set(HConstants.ZOOKEEPER_ZNODE_PARENT, "/2");
utility2 = new HBaseTestingUtility(conf2);
utility2.setZkCluster(miniZK);
- new ZooKeeperWatcher(conf2, "cluster2", null, true);
+ new ZKWatcher(conf2, "cluster2", null, true);
ReplicationAdmin admin1 = new ReplicationAdmin(conf1);
ReplicationPeerConfig rpc = new ReplicationPeerConfig();
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
index dd1e19a..7730100 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/regionserver/TestReplicationSourceManager.java
@@ -83,7 +83,7 @@ import org.apache.hadoop.hbase.wal.WALKey;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -116,7 +116,7 @@ public abstract class TestReplicationSourceManager {
protected static ReplicationSourceManager manager;
- protected static ZooKeeperWatcher zkw;
+ protected static ZKWatcher zkw;
protected static HTableDescriptor htd;
@@ -149,7 +149,7 @@ public abstract class TestReplicationSourceManager {
protected static void setupZkAndReplication() throws Exception {
// The implementing class should set up the conf
assertNotNull(conf);
- zkw = new ZooKeeperWatcher(conf, "test", null);
+ zkw = new ZKWatcher(conf, "test", null);
ZKUtil.createWithParents(zkw, "/hbase/replication");
ZKUtil.createWithParents(zkw, "/hbase/replication/peers/1");
ZKUtil.setData(zkw, "/hbase/replication/peers/1",
@@ -668,7 +668,7 @@ public abstract class TestReplicationSourceManager {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return zkw;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
index ad8cb14..f9d0b1c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java
@@ -56,7 +56,7 @@ import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.TestTableName;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -509,7 +509,7 @@ public class TestAccessController2 extends SecureTestUtil {
// Namespace needs this, as they follow the lazy creation of ACL znode.
grantOnNamespace(TEST_UTIL, TESTGROUP1_USER1.getShortName(), ns, Action.ADMIN);
- ZooKeeperWatcher zkw = TEST_UTIL.getMiniHBaseCluster().getMaster().getZooKeeper();
+ ZKWatcher zkw = TEST_UTIL.getMiniHBaseCluster().getMaster().getZooKeeper();
assertTrue("The acl znode for table should exist", ZKUtil.checkExists(zkw, baseAclZNode +
table.getNameAsString()) != -1);
assertTrue("The acl znode for namespace should exist", ZKUtil.checkExists(zkw, baseAclZNode +
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
index 30e8396..607ea8c 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestTablePermissions.java
@@ -44,7 +44,7 @@ import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.util.Bytes;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -61,7 +61,7 @@ import org.apache.hadoop.hbase.shaded.com.google.common.collect.ListMultimap;
public class TestTablePermissions {
private static final Log LOG = LogFactory.getLog(TestTablePermissions.class);
private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
- private static ZooKeeperWatcher ZKW;
+ private static ZKWatcher ZKW;
private final static Abortable ABORTABLE = new Abortable() {
private final AtomicBoolean abort = new AtomicBoolean(false);
@@ -97,7 +97,7 @@ public class TestTablePermissions {
// Wait for the ACL table to become available
UTIL.waitTableEnabled(AccessControlLists.ACL_TABLE_NAME);
- ZKW = new ZooKeeperWatcher(UTIL.getConfiguration(),
+ ZKW = new ZKWatcher(UTIL.getConfiguration(),
"TestTablePermissions", ABORTABLE);
UTIL.createTable(TEST_TABLE, TEST_FAMILY);
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java
index 76de0c6..18fb15f 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestZKPermissionWatcher.java
@@ -34,7 +34,7 @@ import org.apache.hadoop.hbase.Waiter.Predicate;
import org.apache.hadoop.hbase.security.User;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -75,9 +75,9 @@ public class TestZKPermissionWatcher {
// start minicluster
UTIL.startMiniCluster();
- AUTH_A = TableAuthManager.getOrCreate(new ZooKeeperWatcher(conf,
+ AUTH_A = TableAuthManager.getOrCreate(new ZKWatcher(conf,
"TestZKPermissionsWatcher_1", ABORTABLE), conf);
- AUTH_B = TableAuthManager.getOrCreate(new ZooKeeperWatcher(conf,
+ AUTH_B = TableAuthManager.getOrCreate(new ZKWatcher(conf,
"TestZKPermissionsWatcher_2", ABORTABLE), conf);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java
index 5a0b6bd..3e0bddc 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestTokenAuthentication.java
@@ -76,7 +76,7 @@ import org.apache.hadoop.hbase.util.Threads;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
import org.apache.hadoop.hbase.zookeeper.ZKClusterId;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.net.DNS;
import org.apache.hadoop.security.authorize.PolicyProvider;
import org.apache.hadoop.security.authorize.Service;
@@ -127,7 +127,7 @@ public class TestTokenAuthentication {
private HBaseTestingUtility TEST_UTIL;
private RpcServerInterface rpcServer;
private InetSocketAddress isa;
- private ZooKeeperWatcher zookeeper;
+ private ZKWatcher zookeeper;
private Sleeper sleeper;
private boolean started = false;
private boolean aborted = false;
@@ -220,7 +220,7 @@ public class TestTokenAuthentication {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return zookeeper;
}
@@ -261,7 +261,7 @@ public class TestTokenAuthentication {
// ZK configuration must _not_ have hbase.security.authentication or it will require SASL auth
Configuration zkConf = new Configuration(conf);
zkConf.set(User.HBASE_SECURITY_CONF_KEY, "simple");
- this.zookeeper = new ZooKeeperWatcher(zkConf, TokenServer.class.getSimpleName(),
+ this.zookeeper = new ZKWatcher(zkConf, TokenServer.class.getSimpleName(),
this, true);
this.rpcServer.start();
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcher.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcher.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcher.java
index 857cdd0..ea07338 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcher.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcher.java
@@ -35,7 +35,7 @@ import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -71,13 +71,13 @@ public class TestZKSecretWatcher {
private static class AuthenticationTokenSecretManagerForTest
extends AuthenticationTokenSecretManager {
private CountDownLatch latch = new CountDownLatch(1);
-
+
public AuthenticationTokenSecretManagerForTest(Configuration conf,
- ZooKeeperWatcher zk, String serverName,
- long keyUpdateInterval, long tokenMaxLifetime) {
+ ZKWatcher zk, String serverName,
+ long keyUpdateInterval, long tokenMaxLifetime) {
super(conf, zk, serverName, keyUpdateInterval, tokenMaxLifetime);
}
-
+
@Override
synchronized boolean removeKey(Integer keyId) {
boolean b = super.removeKey(keyId);
@@ -86,19 +86,19 @@ public class TestZKSecretWatcher {
}
return b;
}
-
+
CountDownLatch getLatch() {
return latch;
}
}
-
+
@BeforeClass
public static void setupBeforeClass() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
TEST_UTIL.startMiniZKCluster();
Configuration conf = TEST_UTIL.getConfiguration();
- ZooKeeperWatcher zk = newZK(conf, "server1", new MockAbortable());
+ ZKWatcher zk = newZK(conf, "server1", new MockAbortable());
AuthenticationTokenSecretManagerForTest[] tmp = new AuthenticationTokenSecretManagerForTest[2];
tmp[0] = new AuthenticationTokenSecretManagerForTest(
conf, zk, "server1", 60*60*1000, 60*1000);
@@ -179,7 +179,7 @@ public class TestZKSecretWatcher {
// bring up a new slave
Configuration conf = TEST_UTIL.getConfiguration();
- ZooKeeperWatcher zk = newZK(conf, "server3", new MockAbortable());
+ ZKWatcher zk = newZK(conf, "server3", new MockAbortable());
KEY_SLAVE2 = new AuthenticationTokenSecretManager(
conf, zk, "server3", 60*60*1000, 60*1000);
KEY_SLAVE2.start();
@@ -233,7 +233,7 @@ public class TestZKSecretWatcher {
assertTrue(newCurrent.getKeyId() > current.getKeyId());
// add another slave
- ZooKeeperWatcher zk3 = newZK(conf, "server4", new MockAbortable());
+ ZKWatcher zk3 = newZK(conf, "server4", new MockAbortable());
KEY_SLAVE3 = new AuthenticationTokenSecretManager(
conf, zk3, "server4", 60*60*1000, 60*1000);
KEY_SLAVE3.start();
@@ -275,10 +275,10 @@ public class TestZKSecretWatcher {
assertTrue(newCurrent2.getKeyId() > current2.getKeyId());
}
- private static ZooKeeperWatcher newZK(Configuration conf, String name,
- Abortable abort) throws Exception {
+ private static ZKWatcher newZK(Configuration conf, String name,
+ Abortable abort) throws Exception {
Configuration copy = HBaseConfiguration.create(conf);
- ZooKeeperWatcher zk = new ZooKeeperWatcher(copy, name, abort);
+ ZKWatcher zk = new ZKWatcher(copy, name, abort);
return zk;
}
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcherRefreshKeys.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcherRefreshKeys.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcherRefreshKeys.java
index fcadc9d..1757ddd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcherRefreshKeys.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/token/TestZKSecretWatcherRefreshKeys.java
@@ -28,8 +28,8 @@ import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.hbase.zookeeper.ZKUtil;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.apache.hadoop.hbase.zookeeper.ZNodePaths;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -55,7 +55,7 @@ public class TestZKSecretWatcherRefreshKeys {
return abort;
}
}
-
+
@BeforeClass
public static void setupBeforeClass() throws Exception {
TEST_UTIL = new HBaseTestingUtility();
@@ -67,19 +67,19 @@ public class TestZKSecretWatcherRefreshKeys {
TEST_UTIL.shutdownMiniZKCluster();
}
- private static ZooKeeperWatcher newZK(Configuration conf, String name,
- Abortable abort) throws Exception {
+ private static ZKWatcher newZK(Configuration conf, String name,
+ Abortable abort) throws Exception {
Configuration copy = HBaseConfiguration.create(conf);
- ZooKeeperWatcher zk = new ZooKeeperWatcher(copy, name, abort);
+ ZKWatcher zk = new ZKWatcher(copy, name, abort);
return zk;
}
@Test
public void testRefreshKeys() throws Exception {
Configuration conf = TEST_UTIL.getConfiguration();
- ZooKeeperWatcher zk = newZK(conf, "127.0.0.1", new MockAbortable());
- AuthenticationTokenSecretManager keyManager =
- new AuthenticationTokenSecretManager(conf, zk, "127.0.0.1",
+ ZKWatcher zk = newZK(conf, "127.0.0.1", new MockAbortable());
+ AuthenticationTokenSecretManager keyManager =
+ new AuthenticationTokenSecretManager(conf, zk, "127.0.0.1",
60 * 60 * 1000, 60 * 1000);
ZKSecretWatcher watcher = new ZKSecretWatcher(conf, zk, keyManager);
ZKUtil.deleteChildrenRecursively(zk, watcher.getKeysParentZNode());
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
index e5b1c39..c2da3ec 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelReplicationWithExpAsString.java
@@ -52,7 +52,7 @@ import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.Before;
import org.junit.experimental.categories.Category;
@@ -109,7 +109,7 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
TEST_UTIL = new HBaseTestingUtility(conf);
TEST_UTIL.startMiniZKCluster();
MiniZooKeeperCluster miniZK = TEST_UTIL.getZkCluster();
- zkw1 = new ZooKeeperWatcher(conf, "cluster1", null, true);
+ zkw1 = new ZKWatcher(conf, "cluster1", null, true);
admin = TEST_UTIL.getAdmin();
// Base conf2 on conf1 so it gets the right zk cluster.
@@ -124,7 +124,7 @@ public class TestVisibilityLabelReplicationWithExpAsString extends TestVisibilit
setVisibilityLabelServiceImpl(conf1, ExpAsStringVisibilityLabelServiceImpl.class);
TEST_UTIL1 = new HBaseTestingUtility(conf1);
TEST_UTIL1.setZkCluster(miniZK);
- zkw2 = new ZooKeeperWatcher(conf1, "cluster2", null, true);
+ zkw2 = new ZKWatcher(conf1, "cluster2", null, true);
TEST_UTIL.startMiniCluster(1);
// Wait for the labels table to become available
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
index 513c765..678227b 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/security/visibility/TestVisibilityLabelsReplication.java
@@ -74,7 +74,7 @@ import org.apache.hadoop.hbase.testclassification.SecurityTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.wal.WAL.Entry;
import org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
@@ -109,8 +109,8 @@ public class TestVisibilityLabelsReplication {
public final static byte[] fam = Bytes.toBytes("info");
public final static byte[] qual = Bytes.toBytes("qual");
public final static byte[] value = Bytes.toBytes("value");
- protected static ZooKeeperWatcher zkw1;
- protected static ZooKeeperWatcher zkw2;
+ protected static ZKWatcher zkw1;
+ protected static ZKWatcher zkw2;
protected static int expected[] = { 4, 6, 4, 0, 3 };
private static final String NON_VISIBILITY = "non-visibility";
protected static String[] expectedVisString = {
@@ -160,7 +160,7 @@ public class TestVisibilityLabelsReplication {
TEST_UTIL = new HBaseTestingUtility(conf);
TEST_UTIL.startMiniZKCluster();
MiniZooKeeperCluster miniZK = TEST_UTIL.getZkCluster();
- zkw1 = new ZooKeeperWatcher(conf, "cluster1", null, true);
+ zkw1 = new ZKWatcher(conf, "cluster1", null, true);
admin = TEST_UTIL.getAdmin();
// Base conf2 on conf1 so it gets the right zk cluster.
@@ -176,7 +176,7 @@ public class TestVisibilityLabelsReplication {
USER1 = User.createUserForTesting(conf1, "user1", new String[] {});
TEST_UTIL1 = new HBaseTestingUtility(conf1);
TEST_UTIL1.setZkCluster(miniZK);
- zkw2 = new ZooKeeperWatcher(conf1, "cluster2", null, true);
+ zkw2 = new ZKWatcher(conf1, "cluster2", null, true);
TEST_UTIL.startMiniCluster(1);
// Wait for the labels table to become available
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java
index db44219..4acec76 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/MockServer.java
@@ -31,7 +31,7 @@ import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.zookeeper.MetaTableLocator;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
/**
* Basic mock Server for handler tests.
@@ -39,10 +39,10 @@ import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
public class MockServer implements Server {
private static final Log LOG = LogFactory.getLog(MockServer.class);
final static ServerName NAME = ServerName.valueOf("MockServer", 123, -1);
-
+
boolean stopped;
boolean aborted;
- final ZooKeeperWatcher zk;
+ final ZKWatcher zk;
final HBaseTestingUtility htu;
@SuppressWarnings("unused")
@@ -66,7 +66,7 @@ public class MockServer implements Server {
throws ZooKeeperConnectionException, IOException {
this.htu = htu;
this.zk = zkw?
- new ZooKeeperWatcher(htu.getConfiguration(), NAME.toString(), this, true):
+ new ZKWatcher(htu.getConfiguration(), NAME.toString(), this, true):
null;
}
@@ -94,7 +94,7 @@ public class MockServer implements Server {
}
@Override
- public ZooKeeperWatcher getZooKeeper() {
+ public ZKWatcher getZooKeeper() {
return this.zk;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java
index 7463da1..ba3475e 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/util/TestHBaseFsckOneRS.java
@@ -86,7 +86,7 @@ import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.util.hbck.HFileCorruptionChecker;
import org.apache.hadoop.hbase.util.hbck.HbckTestingUtil;
-import org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher;
+import org.apache.hadoop.hbase.zookeeper.ZKWatcher;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
@@ -1493,7 +1493,7 @@ public class TestHBaseFsckOneRS extends BaseTestHBaseFsck {
Assert.assertEquals(1, replicationAdmin.getPeersCount());
// create replicator
- ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "Test Hbase Fsck", connection);
+ ZKWatcher zkw = new ZKWatcher(conf, "Test Hbase Fsck", connection);
ReplicationQueues repQueues =
ReplicationFactory.getReplicationQueues(new ReplicationQueuesArguments(conf, connection,
zkw));
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java
index e71210d..6fa99fd 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestRecoverableZooKeeper.java
@@ -71,7 +71,7 @@ public class TestRecoverableZooKeeper {
public void testSetDataVersionMismatchInLoop() throws Exception {
String znode = "/hbase/splitWAL/9af7cfc9b15910a0b3d714bf40a3248f";
Configuration conf = TEST_UTIL.getConfiguration();
- ZooKeeperWatcher zkw = new ZooKeeperWatcher(conf, "testSetDataVersionMismatchInLoop",
+ ZKWatcher zkw = new ZKWatcher(conf, "testSetDataVersionMismatchInLoop",
abortable, true);
String ensemble = ZKConfig.getZKQuorumServersString(conf);
RecoverableZooKeeper rzk = ZKUtil.connect(conf, ensemble, zkw);
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java
index 1faf8e5..69915a5 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKLeaderManager.java
@@ -61,12 +61,12 @@ public class TestZKLeaderManager {
private static class MockLeader extends Thread implements Stoppable {
private boolean stopped;
- private ZooKeeperWatcher watcher;
+ private ZKWatcher watcher;
private ZKLeaderManager zkLeader;
private AtomicBoolean master = new AtomicBoolean(false);
private int index;
- public MockLeader(ZooKeeperWatcher watcher, int index) {
+ public MockLeader(ZKWatcher watcher, int index) {
setDaemon(true);
setName("TestZKLeaderManager-leader-" + index);
this.index = index;
@@ -83,7 +83,7 @@ public class TestZKLeaderManager {
return index;
}
- public ZooKeeperWatcher getWatcher() {
+ public ZKWatcher getWatcher() {
return watcher;
}
@@ -132,7 +132,7 @@ public class TestZKLeaderManager {
MockAbortable abortable = new MockAbortable();
CANDIDATES = new MockLeader[3];
for (int i = 0; i < 3; i++) {
- ZooKeeperWatcher watcher = newZK(conf, "server"+i, abortable);
+ ZKWatcher watcher = newZK(conf, "server"+i, abortable);
CANDIDATES[i] = new MockLeader(watcher, i);
CANDIDATES[i].start();
}
@@ -225,10 +225,10 @@ public class TestZKLeaderManager {
return currentLeader;
}
- private static ZooKeeperWatcher newZK(Configuration conf, String name,
- Abortable abort) throws Exception {
+ private static ZKWatcher newZK(Configuration conf, String name,
+ Abortable abort) throws Exception {
Configuration copy = HBaseConfiguration.create(conf);
- ZooKeeperWatcher zk = new ZooKeeperWatcher(copy, name, abort);
+ ZKWatcher zk = new ZKWatcher(copy, name, abort);
return zk;
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java
new file mode 100644
index 0000000..c99bd05
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMainServer.java
@@ -0,0 +1,118 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.security.Permission;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({MiscTests.class, SmallTests.class})
+public class TestZKMainServer {
+ // ZKMS calls System.exit. Catch the call and prevent exit using trick described up in
+ // http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit
+ protected static class ExitException extends SecurityException {
+ private static final long serialVersionUID = 1L;
+ public final int status;
+ public ExitException(int status) {
+ super("There is no escape!");
+ this.status = status;
+ }
+ }
+
+ private static class NoExitSecurityManager extends SecurityManager {
+ @Override
+ public void checkPermission(Permission perm) {
+ // allow anything.
+ }
+
+ @Override
+ public void checkPermission(Permission perm, Object context) {
+ // allow anything.
+ }
+
+ @Override
+ public void checkExit(int status) {
+ super.checkExit(status);
+ throw new ExitException(status);
+ }
+ }
+
+ /**
+ * We need delete of a znode to work at least.
+ * @throws Exception
+ */
+ @Test
+ public void testCommandLineWorks() throws Exception {
+ System.setSecurityManager(new NoExitSecurityManager());
+ HBaseTestingUtility htu = new HBaseTestingUtility();
+ htu.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
+ htu.startMiniZKCluster();
+ try {
+ ZKWatcher zkw = htu.getZooKeeperWatcher();
+ String znode = "/testCommandLineWorks";
+ ZKUtil.createWithParents(zkw, znode, HConstants.EMPTY_BYTE_ARRAY);
+ ZKUtil.checkExists(zkw, znode);
+ boolean exception = false;
+ try {
+ ZKMainServer.main(new String [] {"-server",
+ "localhost:" + htu.getZkCluster().getClientPort(), "delete", znode});
+ } catch (ExitException ee) {
+ // ZKMS calls System.exit which should trigger this exception.
+ exception = true;
+ }
+ assertTrue(exception);
+ assertEquals(-1, ZKUtil.checkExists(zkw, znode));
+ } finally {
+ htu.shutdownMiniZKCluster();
+ System.setSecurityManager(null); // or save and restore original
+ }
+ }
+
+ @Test
+ public void testHostPortParse() {
+ ZKMainServer parser = new ZKMainServer();
+ Configuration c = HBaseConfiguration.create();
+ assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
+ final String port = "1234";
+ c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
+ c.set("hbase.zookeeper.quorum", "example.com");
+ assertEquals("example.com:" + port, parser.parse(c));
+ c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
+ String ensemble = parser.parse(c);
+ assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));
+
+ // multiple servers with its own port
+ c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456");
+ ensemble = parser.parse(c);
+ assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456");
+
+ // some servers without its own port, which will be assigned the default client port
+ c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com");
+ ensemble = parser.parse(c);
+ assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port);
+ }
+}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMulti.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMulti.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMulti.java
index 7971417..614d4be 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMulti.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKMulti.java
@@ -53,7 +53,7 @@ import org.junit.experimental.categories.Category;
public class TestZKMulti {
private static final Log LOG = LogFactory.getLog(TestZKMulti.class);
private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
- private static ZooKeeperWatcher zkw = null;
+ private static ZKWatcher zkw = null;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
@@ -70,7 +70,7 @@ public class TestZKMulti {
return false;
}
};
- zkw = new ZooKeeperWatcher(conf,
+ zkw = new ZKWatcher(conf,
"TestZKMulti", abortable, true);
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKNodeTracker.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKNodeTracker.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKNodeTracker.java
new file mode 100644
index 0000000..ac5c11a
--- /dev/null
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZKNodeTracker.java
@@ -0,0 +1,351 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.Random;
+import java.util.concurrent.Semaphore;
+
+import junit.framework.Assert;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.*;
+import org.apache.hadoop.hbase.master.TestActiveMasterManager.NodeDeletionListener;
+import org.apache.hadoop.hbase.testclassification.MediumTests;
+import org.apache.hadoop.hbase.testclassification.MiscTests;
+import org.apache.hadoop.hbase.util.Bytes;
+import org.apache.hadoop.hbase.util.Threads;
+import org.apache.zookeeper.CreateMode;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.apache.zookeeper.ZooDefs.Ids;
+import org.apache.zookeeper.ZooKeeper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category({MiscTests.class, MediumTests.class})
+public class TestZKNodeTracker {
+ private static final Log LOG = LogFactory.getLog(TestZKNodeTracker.class);
+ private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
+
+ private final static Random rand = new Random();
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ TEST_UTIL.startMiniZKCluster();
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ TEST_UTIL.shutdownMiniZKCluster();
+ }
+
+ /**
+ * Test that we can interrupt a node that is blocked on a wait.
+ * @throws IOException
+ * @throws InterruptedException
+ */
+ @Test public void testInterruptible() throws IOException, InterruptedException {
+ Abortable abortable = new StubAbortable();
+ ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(),
+ "testInterruptible", abortable);
+ final TestTracker tracker = new TestTracker(zk, "/xyz", abortable);
+ tracker.start();
+ Thread t = new Thread() {
+ @Override
+ public void run() {
+ try {
+ tracker.blockUntilAvailable();
+ } catch (InterruptedException e) {
+ throw new RuntimeException("Interrupted", e);
+ }
+ }
+ };
+ t.start();
+ while (!t.isAlive()) Threads.sleep(1);
+ tracker.stop();
+ t.join();
+ // If it wasn't interruptible, we'd never get to here.
+ }
+
+ @Test
+ public void testNodeTracker() throws Exception {
+ Abortable abortable = new StubAbortable();
+ ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(),
+ "testNodeTracker", abortable);
+ ZKUtil.createAndFailSilent(zk, zk.znodePaths.baseZNode);
+
+ final String node =
+ ZNodePaths.joinZNode(zk.znodePaths.baseZNode, new Long(rand.nextLong()).toString());
+
+ final byte [] dataOne = Bytes.toBytes("dataOne");
+ final byte [] dataTwo = Bytes.toBytes("dataTwo");
+
+ // Start a ZKNT with no node currently available
+ TestTracker localTracker = new TestTracker(zk, node, abortable);
+ localTracker.start();
+ zk.registerListener(localTracker);
+
+ // Make sure we don't have a node
+ assertNull(localTracker.getData(false));
+
+ // Spin up a thread with another ZKNT and have it block
+ WaitToGetDataThread thread = new WaitToGetDataThread(zk, node);
+ thread.start();
+
+ // Verify the thread doesn't have a node
+ assertFalse(thread.hasData);
+
+ // Now, start a new ZKNT with the node already available
+ TestTracker secondTracker = new TestTracker(zk, node, null);
+ secondTracker.start();
+ zk.registerListener(secondTracker);
+
+ // Put up an additional zk listener so we know when zk event is done
+ TestingZKListener zkListener = new TestingZKListener(zk, node);
+ zk.registerListener(zkListener);
+ assertEquals(0, zkListener.createdLock.availablePermits());
+
+ // Create a completely separate zk connection for test triggers and avoid
+ // any weird watcher interactions from the test
+ final ZooKeeper zkconn = new ZooKeeper(
+ ZKConfig.getZKQuorumServersString(TEST_UTIL.getConfiguration()), 60000,
+ new StubWatcher());
+
+ // Add the node with data one
+ zkconn.create(node, dataOne, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+
+ // Wait for the zk event to be processed
+ zkListener.waitForCreation();
+ thread.join();
+
+ // Both trackers should have the node available with data one
+ assertNotNull(localTracker.getData(false));
+ assertNotNull(localTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(localTracker.getData(false), dataOne));
+ assertTrue(thread.hasData);
+ assertTrue(Bytes.equals(thread.tracker.getData(false), dataOne));
+ LOG.info("Successfully got data one");
+
+ // Make sure it's available and with the expected data
+ assertNotNull(secondTracker.getData(false));
+ assertNotNull(secondTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(secondTracker.getData(false), dataOne));
+ LOG.info("Successfully got data one with the second tracker");
+
+ // Drop the node
+ zkconn.delete(node, -1);
+ zkListener.waitForDeletion();
+
+ // Create a new thread but with the existing thread's tracker to wait
+ TestTracker threadTracker = thread.tracker;
+ thread = new WaitToGetDataThread(zk, node, threadTracker);
+ thread.start();
+
+ // Verify other guys don't have data
+ assertFalse(thread.hasData);
+ assertNull(secondTracker.getData(false));
+ assertNull(localTracker.getData(false));
+ LOG.info("Successfully made unavailable");
+
+ // Create with second data
+ zkconn.create(node, dataTwo, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
+
+ // Wait for the zk event to be processed
+ zkListener.waitForCreation();
+ thread.join();
+
+ // All trackers should have the node available with data two
+ assertNotNull(localTracker.getData(false));
+ assertNotNull(localTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(localTracker.getData(false), dataTwo));
+ assertNotNull(secondTracker.getData(false));
+ assertNotNull(secondTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(secondTracker.getData(false), dataTwo));
+ assertTrue(thread.hasData);
+ assertTrue(Bytes.equals(thread.tracker.getData(false), dataTwo));
+ LOG.info("Successfully got data two on all trackers and threads");
+
+ // Change the data back to data one
+ zkconn.setData(node, dataOne, -1);
+
+ // Wait for zk event to be processed
+ zkListener.waitForDataChange();
+
+ // All trackers should have the node available with data one
+ assertNotNull(localTracker.getData(false));
+ assertNotNull(localTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(localTracker.getData(false), dataOne));
+ assertNotNull(secondTracker.getData(false));
+ assertNotNull(secondTracker.blockUntilAvailable());
+ assertTrue(Bytes.equals(secondTracker.getData(false), dataOne));
+ assertTrue(thread.hasData);
+ assertTrue(Bytes.equals(thread.tracker.getData(false), dataOne));
+ LOG.info("Successfully got data one following a data change on all trackers and threads");
+ }
+
+ public static class WaitToGetDataThread extends Thread {
+
+ TestTracker tracker;
+ boolean hasData;
+
+ public WaitToGetDataThread(ZKWatcher zk, String node) {
+ tracker = new TestTracker(zk, node, null);
+ tracker.start();
+ zk.registerListener(tracker);
+ hasData = false;
+ }
+
+ public WaitToGetDataThread(ZKWatcher zk, String node,
+ TestTracker tracker) {
+ this.tracker = tracker;
+ hasData = false;
+ }
+
+ @Override
+ public void run() {
+ LOG.info("Waiting for data to be available in WaitToGetDataThread");
+ try {
+ tracker.blockUntilAvailable();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ LOG.info("Data now available in tracker from WaitToGetDataThread");
+ hasData = true;
+ }
+ }
+
+ public static class TestTracker extends ZKNodeTracker {
+ public TestTracker(ZKWatcher watcher, String node,
+ Abortable abortable) {
+ super(watcher, node, abortable);
+ }
+ }
+
+ public static class TestingZKListener extends ZKListener {
+ private static final Log LOG = LogFactory.getLog(NodeDeletionListener.class);
+
+ private Semaphore deletedLock;
+ private Semaphore createdLock;
+ private Semaphore changedLock;
+ private String node;
+
+ public TestingZKListener(ZKWatcher watcher, String node) {
+ super(watcher);
+ deletedLock = new Semaphore(0);
+ createdLock = new Semaphore(0);
+ changedLock = new Semaphore(0);
+ this.node = node;
+ }
+
+ @Override
+ public void nodeDeleted(String path) {
+ if(path.equals(node)) {
+ LOG.debug("nodeDeleted(" + path + ")");
+ deletedLock.release();
+ }
+ }
+
+ @Override
+ public void nodeCreated(String path) {
+ if(path.equals(node)) {
+ LOG.debug("nodeCreated(" + path + ")");
+ createdLock.release();
+ }
+ }
+
+ @Override
+ public void nodeDataChanged(String path) {
+ if(path.equals(node)) {
+ LOG.debug("nodeDataChanged(" + path + ")");
+ changedLock.release();
+ }
+ }
+
+ public void waitForDeletion() throws InterruptedException {
+ deletedLock.acquire();
+ }
+
+ public void waitForCreation() throws InterruptedException {
+ createdLock.acquire();
+ }
+
+ public void waitForDataChange() throws InterruptedException {
+ changedLock.acquire();
+ }
+ }
+
+ public static class StubAbortable implements Abortable {
+ @Override
+ public void abort(final String msg, final Throwable t) {}
+
+ @Override
+ public boolean isAborted() {
+ return false;
+ }
+
+ }
+
+ public static class StubWatcher implements Watcher {
+ @Override
+ public void process(WatchedEvent event) {}
+ }
+
+ @Test
+ public void testCleanZNode() throws Exception {
+ ZKWatcher zkw = new ZKWatcher(TEST_UTIL.getConfiguration(),
+ "testNodeTracker", new TestZKNodeTracker.StubAbortable());
+
+ final ServerName sn = ServerName.valueOf("127.0.0.1:52", 45L);
+
+ ZKUtil.createAndFailSilent(zkw,
+ TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_ZNODE_PARENT,
+ HConstants.DEFAULT_ZOOKEEPER_ZNODE_PARENT));
+
+ final String nodeName = zkw.znodePaths.masterAddressZNode;
+
+ // Check that we manage the case when there is no data
+ ZKUtil.createAndFailSilent(zkw, nodeName);
+ MasterAddressTracker.deleteIfEquals(zkw, sn.toString());
+ Assert.assertFalse(ZKUtil.getData(zkw, nodeName) == null);
+
+ // Check that we don't delete if we're not supposed to
+ ZKUtil.setData(zkw, nodeName, MasterAddressTracker.toByteArray(sn, 0));
+ MasterAddressTracker.deleteIfEquals(zkw, ServerName.valueOf("127.0.0.2:52", 45L).toString());
+ Assert.assertFalse(ZKUtil.getData(zkw, nodeName) == null);
+
+ // Check that we delete when we're supposed to
+ ZKUtil.setData(zkw, nodeName,MasterAddressTracker.toByteArray(sn, 0));
+ MasterAddressTracker.deleteIfEquals(zkw, sn.toString());
+ Assert.assertTrue( ZKUtil.getData(zkw, nodeName)== null );
+
+ // Check that we support the case when the znode does not exist
+ MasterAddressTracker.deleteIfEquals(zkw, sn.toString()); // must not throw an exception
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperACL.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperACL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperACL.java
index 05ad73e..c5bce00 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperACL.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperACL.java
@@ -49,9 +49,9 @@ public class TestZooKeeperACL {
private final static HBaseTestingUtility TEST_UTIL =
new HBaseTestingUtility();
- private static ZooKeeperWatcher zkw;
+ private static ZKWatcher zkw;
private static boolean secureZKAvailable;
-
+
@BeforeClass
public static void setUpBeforeClass() throws Exception {
File saslConfFile = File.createTempFile("tmp", "jaas.conf");
@@ -76,7 +76,7 @@ public class TestZooKeeperACL {
TEST_UTIL.getConfiguration().setInt("hbase.zookeeper.property.maxClientCnxns", 1000);
// If Hadoop is missing HADOOP-7070 the cluster will fail to start due to
- // the JAAS configuration required by ZK being clobbered by Hadoop
+ // the JAAS configuration required by ZK being clobbered by Hadoop
try {
TEST_UTIL.startMiniCluster();
} catch (IOException e) {
@@ -84,7 +84,7 @@ public class TestZooKeeperACL {
secureZKAvailable = false;
return;
}
- zkw = new ZooKeeperWatcher(
+ zkw = new ZKWatcher(
new Configuration(TEST_UTIL.getConfiguration()),
TestZooKeeper.class.getName(), null);
}
@@ -112,7 +112,7 @@ public class TestZooKeeperACL {
}
/**
- * Create a node and check its ACL. When authentication is enabled on
+ * Create a node and check its ACL. When authentication is enabled on
* ZooKeeper, all nodes (except /hbase/root-region-server, /hbase/master
* and /hbase/hbaseid) should be created so that only the hbase server user
* (master or region server user) that created them can access them, and
@@ -285,7 +285,7 @@ public class TestZooKeeperACL {
assertEquals(testJaasConfig, false);
saslConfFile.delete();
}
-
+
/**
* Check if Programmatic way of setting zookeeper security settings is valid.
*/
http://git-wip-us.apache.org/repos/asf/hbase/blob/330b0d05/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServer.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServer.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServer.java
deleted file mode 100644
index 368919c..0000000
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/zookeeper/TestZooKeeperMainServer.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.hadoop.hbase.zookeeper;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.security.Permission;
-
-import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.*;
-import org.apache.hadoop.hbase.testclassification.MiscTests;
-import org.apache.hadoop.hbase.testclassification.SmallTests;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-@Category({MiscTests.class, SmallTests.class})
-public class TestZooKeeperMainServer {
- // ZKMS calls System.exit. Catch the call and prevent exit using trick described up in
- // http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit
- protected static class ExitException extends SecurityException {
- private static final long serialVersionUID = 1L;
- public final int status;
- public ExitException(int status) {
- super("There is no escape!");
- this.status = status;
- }
- }
-
- private static class NoExitSecurityManager extends SecurityManager {
- @Override
- public void checkPermission(Permission perm) {
- // allow anything.
- }
-
- @Override
- public void checkPermission(Permission perm, Object context) {
- // allow anything.
- }
-
- @Override
- public void checkExit(int status) {
- super.checkExit(status);
- throw new ExitException(status);
- }
- }
-
- /**
- * We need delete of a znode to work at least.
- * @throws Exception
- */
- @Test
- public void testCommandLineWorks() throws Exception {
- System.setSecurityManager(new NoExitSecurityManager());
- HBaseTestingUtility htu = new HBaseTestingUtility();
- htu.getConfiguration().setInt(HConstants.ZK_SESSION_TIMEOUT, 1000);
- htu.startMiniZKCluster();
- try {
- ZooKeeperWatcher zkw = htu.getZooKeeperWatcher();
- String znode = "/testCommandLineWorks";
- ZKUtil.createWithParents(zkw, znode, HConstants.EMPTY_BYTE_ARRAY);
- ZKUtil.checkExists(zkw, znode);
- boolean exception = false;
- try {
- ZooKeeperMainServer.main(new String [] {"-server",
- "localhost:" + htu.getZkCluster().getClientPort(), "delete", znode});
- } catch (ExitException ee) {
- // ZKMS calls System.exit which should trigger this exception.
- exception = true;
- }
- assertTrue(exception);
- assertEquals(-1, ZKUtil.checkExists(zkw, znode));
- } finally {
- htu.shutdownMiniZKCluster();
- System.setSecurityManager(null); // or save and restore original
- }
- }
-
- @Test
- public void testHostPortParse() {
- ZooKeeperMainServer parser = new ZooKeeperMainServer();
- Configuration c = HBaseConfiguration.create();
- assertEquals("localhost:" + c.get(HConstants.ZOOKEEPER_CLIENT_PORT), parser.parse(c));
- final String port = "1234";
- c.set(HConstants.ZOOKEEPER_CLIENT_PORT, port);
- c.set("hbase.zookeeper.quorum", "example.com");
- assertEquals("example.com:" + port, parser.parse(c));
- c.set("hbase.zookeeper.quorum", "example1.com,example2.com,example3.com");
- String ensemble = parser.parse(c);
- assertTrue(port, ensemble.matches("(example[1-3]\\.com:1234,){2}example[1-3]\\.com:" + port));
-
- // multiple servers with its own port
- c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456");
- ensemble = parser.parse(c);
- assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456");
-
- // some servers without its own port, which will be assigned the default client port
- c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com");
- ensemble = parser.parse(c);
- assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:" + port);
- }
-}