HBASE-22787 Cleaned up tests in hbase-zookeeper

Signed-off-by: Peter Somogyi <psomogyi@apache.org>
This commit is contained in:
Jan Hentschel 2019-08-04 20:49:11 +02:00 committed by GitHub
parent a6f065396a
commit abb60faa6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 83 additions and 109 deletions

View File

@ -32,7 +32,6 @@ import org.apache.yetus.audience.InterfaceAudience;
*/ */
@InterfaceAudience.Public @InterfaceAudience.Public
public class HBaseZKTestingUtility extends HBaseCommonTestingUtility { public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
private MiniZooKeeperCluster zkCluster; private MiniZooKeeperCluster zkCluster;
/** /**
@ -55,8 +54,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
/** /**
* @return Where the cluster will write data on the local subsystem. Creates it if it does not * @return Where the cluster will write data on the local subsystem. Creates it if it does not
* exist already. A subdir of {@link #getBaseTestDir()} * exist already. A subdir of {@code HBaseCommonTestingUtility#getBaseTestDir()}
* @see #getTestFileSystem()
*/ */
Path getClusterTestDir() { Path getClusterTestDir() {
if (clusterTestDir == null) { if (clusterTestDir == null) {
@ -124,8 +122,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
if (clientPortList != null) { if (clientPortList != null) {
// Ignore extra client ports // Ignore extra client ports
int clientPortListSize = (clientPortList.length <= zooKeeperServerNum) ? clientPortList.length int clientPortListSize = Math.min(clientPortList.length, zooKeeperServerNum);
: zooKeeperServerNum;
for (int i = 0; i < clientPortListSize; i++) { for (int i = 0; i < clientPortListSize; i++) {
this.zkCluster.addClientPort(clientPortList[i]); this.zkCluster.addClientPort(clientPortList[i]);
} }
@ -182,7 +179,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
* Gets a ZKWatcher. * Gets a ZKWatcher.
*/ */
public static ZKWatcher getZooKeeperWatcher(HBaseZKTestingUtility testUtil) throws IOException { public static ZKWatcher getZooKeeperWatcher(HBaseZKTestingUtility testUtil) throws IOException {
ZKWatcher zkw = new ZKWatcher(testUtil.getConfiguration(), "unittest", new Abortable() { return new ZKWatcher(testUtil.getConfiguration(), "unittest", new Abortable() {
boolean aborted = false; boolean aborted = false;
@Override @Override
@ -196,7 +193,6 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
return aborted; return aborted;
} }
}); });
return zkw;
} }
/** /**
@ -207,7 +203,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
boolean ret = super.cleanupTestDir(); boolean ret = super.cleanupTestDir();
if (deleteDir(this.clusterTestDir)) { if (deleteDir(this.clusterTestDir)) {
this.clusterTestDir = null; this.clusterTestDir = null;
return ret & true; return ret;
} }
return false; return false;
} }

View File

@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.zookeeper;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.io.IOException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
@ -41,7 +42,6 @@ import org.junit.experimental.categories.Category;
*/ */
@Category({ ZKTests.class, MediumTests.class }) @Category({ ZKTests.class, MediumTests.class })
public class TestHQuorumPeer { public class TestHQuorumPeer {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestHQuorumPeer.class); HBaseClassTestRule.forClass(TestHQuorumPeer.class);
@ -75,7 +75,7 @@ public class TestHQuorumPeer {
assertEquals(Integer.valueOf(PORT_NO), assertEquals(Integer.valueOf(PORT_NO),
Integer.valueOf(properties.getProperty("clientPort"))); Integer.valueOf(properties.getProperty("clientPort")));
assertEquals("localhost:2888:3888", properties.get("server.0")); assertEquals("localhost:2888:3888", properties.get("server.0"));
assertEquals(null, properties.get("server.1")); assertNull(properties.get("server.1"));
String oldValue = conf.get(HConstants.ZOOKEEPER_QUORUM); String oldValue = conf.get(HConstants.ZOOKEEPER_QUORUM);
conf.set(HConstants.ZOOKEEPER_QUORUM, "a.foo.bar,b.foo.bar,c.foo.bar"); conf.set(HConstants.ZOOKEEPER_QUORUM, "a.foo.bar,b.foo.bar,c.foo.bar");
@ -86,7 +86,7 @@ public class TestHQuorumPeer {
assertEquals("a.foo.bar:2888:3888", properties.get("server.0")); assertEquals("a.foo.bar:2888:3888", properties.get("server.0"));
assertEquals("b.foo.bar:2888:3888", properties.get("server.1")); assertEquals("b.foo.bar:2888:3888", properties.get("server.1"));
assertEquals("c.foo.bar:2888:3888", properties.get("server.2")); assertEquals("c.foo.bar:2888:3888", properties.get("server.2"));
assertEquals(null, properties.get("server.3")); assertNull(properties.get("server.3"));
conf.set(HConstants.ZOOKEEPER_QUORUM, oldValue); conf.set(HConstants.ZOOKEEPER_QUORUM, oldValue);
} }

View File

@ -72,8 +72,6 @@ public class TestReadOnlyZKClient {
private static HBaseZKTestingUtility UTIL = new HBaseZKTestingUtility(); private static HBaseZKTestingUtility UTIL = new HBaseZKTestingUtility();
private static int PORT;
private static String PATH = "/test"; private static String PATH = "/test";
private static byte[] DATA; private static byte[] DATA;
@ -84,9 +82,9 @@ public class TestReadOnlyZKClient {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
PORT = UTIL.startMiniZKCluster().getClientPort(); final int port = UTIL.startMiniZKCluster().getClientPort();
ZooKeeper zk = ZooKeeperHelper.getConnectedZooKeeper("localhost:" + PORT, 10000); ZooKeeper zk = ZooKeeperHelper.getConnectedZooKeeper("localhost:" + port, 10000);
DATA = new byte[10]; DATA = new byte[10];
ThreadLocalRandom.current().nextBytes(DATA); ThreadLocalRandom.current().nextBytes(DATA);
zk.create(PATH, DATA, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.create(PATH, DATA, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
@ -95,7 +93,7 @@ public class TestReadOnlyZKClient {
} }
zk.close(); zk.close();
Configuration conf = UTIL.getConfiguration(); Configuration conf = UTIL.getConfiguration();
conf.set(HConstants.ZOOKEEPER_QUORUM, "localhost:" + PORT); conf.set(HConstants.ZOOKEEPER_QUORUM, "localhost:" + port);
conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY, 3); conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY, 3);
conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY_INTERVAL_MILLIS, 100); conf.setInt(ReadOnlyZKClient.RECOVERY_RETRY_INTERVAL_MILLIS, 100);
conf.setInt(ReadOnlyZKClient.KEEPALIVE_MILLIS, 3000); conf.setInt(ReadOnlyZKClient.KEEPALIVE_MILLIS, 3000);
@ -116,12 +114,12 @@ public class TestReadOnlyZKClient {
UTIL.waitFor(10000, new ExplainingPredicate<Exception>() { UTIL.waitFor(10000, new ExplainingPredicate<Exception>() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() {
return RO_ZK.zookeeper == null; return RO_ZK.zookeeper == null;
} }
@Override @Override
public String explainFailure() throws Exception { public String explainFailure() {
return "Connection to zookeeper is still alive"; return "Connection to zookeeper is still alive";
} }
}); });

View File

@ -43,17 +43,15 @@ import org.junit.experimental.categories.Category;
@Category({ ZKTests.class, MediumTests.class }) @Category({ ZKTests.class, MediumTests.class })
public class TestRecoverableZooKeeper { public class TestRecoverableZooKeeper {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRecoverableZooKeeper.class); HBaseClassTestRule.forClass(TestRecoverableZooKeeper.class);
private final static HBaseZKTestingUtility TEST_UTIL = new HBaseZKTestingUtility(); private final static HBaseZKTestingUtility TEST_UTIL = new HBaseZKTestingUtility();
Abortable abortable = new Abortable() { private Abortable abortable = new Abortable() {
@Override @Override
public void abort(String why, Throwable e) { public void abort(String why, Throwable e) {
} }
@Override @Override
@ -94,16 +92,15 @@ public class TestRecoverableZooKeeper {
assertTrue(Bytes.equals(opened, data)); assertTrue(Bytes.equals(opened, data));
} }
class ZookeeperStub extends ZooKeeper { static class ZookeeperStub extends ZooKeeper {
private int throwExceptionInNumOperations; private int throwExceptionInNumOperations;
public ZookeeperStub(String connectString, int sessionTimeout, Watcher watcher) ZookeeperStub(String connectString, int sessionTimeout, Watcher watcher)
throws IOException { throws IOException {
super(connectString, sessionTimeout, watcher); super(connectString, sessionTimeout, watcher);
} }
public void setThrowExceptionInNumOperations(int throwExceptionInNumOperations) { void setThrowExceptionInNumOperations(int throwExceptionInNumOperations) {
this.throwExceptionInNumOperations = throwExceptionInNumOperations; this.throwExceptionInNumOperations = throwExceptionInNumOperations;
} }

View File

@ -77,7 +77,7 @@ public class TestZKLeaderManager {
private AtomicBoolean master = new AtomicBoolean(false); private AtomicBoolean master = new AtomicBoolean(false);
private int index; private int index;
public MockLeader(ZKWatcher watcher, int index) { MockLeader(ZKWatcher watcher, int index) {
setDaemon(true); setDaemon(true);
setName("TestZKLeaderManager-leader-" + index); setName("TestZKLeaderManager-leader-" + index);
this.index = index; this.index = index;
@ -113,7 +113,7 @@ public class TestZKLeaderManager {
} }
} }
public void abdicate() { void abdicate() {
zkLeader.stepDownAsLeader(); zkLeader.stepDownAsLeader();
master.set(false); master.set(false);
} }
@ -214,9 +214,9 @@ public class TestZKLeaderManager {
assertNotNull("New leader should exist", currentLeader); assertNotNull("New leader should exist", currentLeader);
} }
private MockLeader getCurrentLeader() throws Exception { private MockLeader getCurrentLeader() {
MockLeader currentLeader = null; MockLeader currentLeader = null;
outer:
// Wait up to 10 secs for initial leader // Wait up to 10 secs for initial leader
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
for (int j = 0; j < CANDIDATES.length; j++) { for (int j = 0; j < CANDIDATES.length; j++) {
@ -229,18 +229,16 @@ public class TestZKLeaderManager {
} }
} }
if (currentLeader != null) { if (currentLeader != null) {
break outer; break;
} }
Threads.sleep(100); Threads.sleep(100);
} }
return currentLeader; return currentLeader;
} }
private static ZKWatcher newZK(Configuration conf, String name, private static ZKWatcher newZK(Configuration conf, String name, Abortable abort)
Abortable abort) throws Exception { throws Exception {
Configuration copy = HBaseConfiguration.create(conf); Configuration copy = HBaseConfiguration.create(conf);
ZKWatcher zk = new ZKWatcher(copy, name, abort); return new ZKWatcher(copy, name, abort);
return zk;
} }
} }

View File

@ -35,7 +35,6 @@ import org.junit.experimental.categories.Category;
@Category({ ZKTests.class, SmallTests.class }) @Category({ ZKTests.class, SmallTests.class })
public class TestZKMainServer { public class TestZKMainServer {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestZKMainServer.class); HBaseClassTestRule.forClass(TestZKMainServer.class);
@ -44,10 +43,9 @@ public class TestZKMainServer {
// http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit // http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit
protected static class ExitException extends SecurityException { protected static class ExitException extends SecurityException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private final int status;
public ExitException(int status) { ExitException() {
super("There is no escape!"); super("There is no escape!");
this.status = status;
} }
} }
@ -65,7 +63,7 @@ public class TestZKMainServer {
@Override @Override
public void checkExit(int status) { public void checkExit(int status) {
super.checkExit(status); super.checkExit(status);
throw new ExitException(status); throw new ExitException();
} }
} }
@ -116,7 +114,7 @@ public class TestZKMainServer {
// multiple servers with its own port // multiple servers with its own port
c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456"); c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com:3456");
ensemble = parser.parse(c); ensemble = parser.parse(c);
assertEquals(ensemble, "example1.com:5678,example2.com:9012,example3.com:3456"); assertEquals("example1.com:5678,example2.com:9012,example3.com:3456", ensemble);
// some servers without its own port, which will be assigned the default client port // 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"); c.set("hbase.zookeeper.quorum", "example1.com:5678,example2.com:9012,example3.com");
@ -142,11 +140,10 @@ public class TestZKMainServer {
// some servers(IPv6) with an invaild Ipv6 address in it // some servers(IPv6) with an invaild Ipv6 address in it
c.set("hbase.zookeeper.quorum", "[1001:db8:1::242:ac11:8], [2001:db8:1::242:df23:2]:9876," + c.set("hbase.zookeeper.quorum", "[1001:db8:1::242:ac11:8], [2001:db8:1::242:df23:2]:9876," +
"[1001:db8:1::242:ac11:8:89:67]:5678"); "[1001:db8:1::242:ac11:8:89:67]:5678");
ensemble = parser.parse(c); parser.parse(c);
Assert.fail("IPv6 address should be 8 groups."); Assert.fail("IPv6 address should be 8 groups.");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
//expected //expected
} }
} }
} }

View File

@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.zookeeper; package org.apache.hadoop.hbase.zookeeper;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,11 +48,10 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Test ZooKeeper multi-update functionality * Test ZooKeeper multi-update functionality.
*/ */
@Category({ ZKTests.class, MediumTests.class }) @Category({ ZKTests.class, MediumTests.class })
public class TestZKMulti { public class TestZKMulti {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestZKMulti.class); HBaseClassTestRule.forClass(TestZKMulti.class);
@ -113,7 +112,7 @@ public class TestZKMulti {
LinkedList<ZKUtilOp> singleDelete = new LinkedList<>(); LinkedList<ZKUtilOp> singleDelete = new LinkedList<>();
singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path)); singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path));
ZKUtil.multiOrSequential(zkw, singleDelete, false); ZKUtil.multiOrSequential(zkw, singleDelete, false);
assertTrue(ZKUtil.checkExists(zkw, path) == -1); assertEquals(ZKUtil.checkExists(zkw, path), -1);
} }
@Test @Test
@ -152,8 +151,8 @@ public class TestZKMulti {
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1)))); Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path2), assertTrue(Bytes.equals(ZKUtil.getData(zkw, path2),
Bytes.add(Bytes.toBytes(path2), Bytes.toBytes(path2)))); Bytes.add(Bytes.toBytes(path2), Bytes.toBytes(path2))));
assertTrue(ZKUtil.checkExists(zkw, path3) == -1); assertEquals(ZKUtil.checkExists(zkw, path3), -1);
assertTrue(ZKUtil.checkExists(zkw, path4) == -1); assertEquals(ZKUtil.checkExists(zkw, path4), -1);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path5), Bytes.toBytes(path5))); assertTrue(Bytes.equals(ZKUtil.getData(zkw, path5), Bytes.toBytes(path5)));
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path6), Bytes.toBytes(path6))); assertTrue(Bytes.equals(ZKUtil.getData(zkw, path6), Bytes.toBytes(path6)));
} }
@ -214,9 +213,9 @@ public class TestZKMulti {
} }
assertTrue(caughtNoNode); assertTrue(caughtNoNode);
// assert that none of the operations succeeded // assert that none of the operations succeeded
assertTrue(ZKUtil.checkExists(zkw, pathA) == -1); assertEquals(ZKUtil.checkExists(zkw, pathA), -1);
assertTrue(ZKUtil.checkExists(zkw, pathB) == -1); assertEquals(ZKUtil.checkExists(zkw, pathB), -1);
assertTrue(ZKUtil.checkExists(zkw, pathC) == -1); assertEquals(ZKUtil.checkExists(zkw, pathC), -1);
} }
@Test @Test
@ -247,11 +246,11 @@ public class TestZKMulti {
} }
assertTrue(caughtNodeExists); assertTrue(caughtNodeExists);
// check that no modifications were made // check that no modifications were made
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1); assertNotEquals(ZKUtil.checkExists(zkw, pathX), -1);
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1); assertEquals(ZKUtil.checkExists(zkw, pathY), -1);
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1); assertEquals(ZKUtil.checkExists(zkw, pathZ), -1);
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1); assertEquals(ZKUtil.checkExists(zkw, pathW), -1);
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1); assertEquals(ZKUtil.checkExists(zkw, pathV), -1);
// test that with multiple failures, throws an exception corresponding to first failure in list // test that with multiple failures, throws an exception corresponding to first failure in list
ops = new LinkedList<>(); ops = new LinkedList<>();
@ -266,11 +265,11 @@ public class TestZKMulti {
} }
assertTrue(caughtNoNode); assertTrue(caughtNoNode);
// check that no modifications were made // check that no modifications were made
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1); assertNotEquals(ZKUtil.checkExists(zkw, pathX), -1);
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1); assertEquals(ZKUtil.checkExists(zkw, pathY), -1);
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1); assertEquals(ZKUtil.checkExists(zkw, pathZ), -1);
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1); assertEquals(ZKUtil.checkExists(zkw, pathW), -1);
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1); assertEquals(ZKUtil.checkExists(zkw, pathV), -1);
} }
@Test @Test
@ -297,9 +296,9 @@ public class TestZKMulti {
ZKUtil.multiOrSequential(zkw, ops, true); ZKUtil.multiOrSequential(zkw, ops, true);
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1), assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1),
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1)))); Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
assertTrue(ZKUtil.checkExists(zkw, path2) == -1); assertEquals(ZKUtil.checkExists(zkw, path2), -1);
assertTrue(ZKUtil.checkExists(zkw, path3) == -1); assertEquals(ZKUtil.checkExists(zkw, path3), -1);
assertFalse(ZKUtil.checkExists(zkw, path4) == -1); assertNotEquals(ZKUtil.checkExists(zkw, path4), -1);
} }
/** /**
@ -317,7 +316,7 @@ public class TestZKMulti {
ZKUtil.checkExists(zkw, parentZNode) > -1); ZKUtil.checkExists(zkw, parentZNode) > -1);
List<String> children = zkw.getRecoverableZooKeeper().getChildren( List<String> children = zkw.getRecoverableZooKeeper().getChildren(
parentZNode, false); parentZNode, false);
assertTrue("Failed to delete child znodes!", 0 == children.size()); assertEquals("Failed to delete child znodes!", 0, children.size());
} }
/** /**
@ -330,7 +329,7 @@ public class TestZKMulti {
createZNodeTree(parentZNode); createZNodeTree(parentZNode);
ZKUtil.deleteNodeRecursively(zkw, parentZNode); ZKUtil.deleteNodeRecursively(zkw, parentZNode);
assertTrue("Parent znode should be deleted.", ZKUtil.checkExists(zkw, parentZNode) == -1); assertEquals("Parent znode should be deleted.", ZKUtil.checkExists(zkw, parentZNode), -1);
} }
@Test @Test
@ -344,9 +343,9 @@ public class TestZKMulti {
ZKUtil.deleteNodeRecursivelyMultiOrSequential(zkw, false, parentZNode1, parentZNode2, ZKUtil.deleteNodeRecursivelyMultiOrSequential(zkw, false, parentZNode1, parentZNode2,
parentZNode3); parentZNode3);
assertTrue("Parent znode 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1) == -1); assertEquals("Parent znode 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1), -1);
assertTrue("Parent znode 2 should be deleted.", ZKUtil.checkExists(zkw, parentZNode2) == -1); assertEquals("Parent znode 2 should be deleted.", ZKUtil.checkExists(zkw, parentZNode2), -1);
assertTrue("Parent znode 3 should be deleted.", ZKUtil.checkExists(zkw, parentZNode3) == -1); assertEquals("Parent znode 3 should be deleted.", ZKUtil.checkExists(zkw, parentZNode3), -1);
} }
@Test @Test
@ -363,15 +362,15 @@ public class TestZKMulti {
assertTrue("Wrongly deleted parent znode 1!", ZKUtil.checkExists(zkw, parentZNode1) > -1); assertTrue("Wrongly deleted parent znode 1!", ZKUtil.checkExists(zkw, parentZNode1) > -1);
List<String> children = zkw.getRecoverableZooKeeper().getChildren(parentZNode1, false); List<String> children = zkw.getRecoverableZooKeeper().getChildren(parentZNode1, false);
assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size()); assertEquals("Failed to delete child znodes of parent znode 1!", 0, children.size());
assertTrue("Wrongly deleted parent znode 2!", ZKUtil.checkExists(zkw, parentZNode2) > -1); assertTrue("Wrongly deleted parent znode 2!", ZKUtil.checkExists(zkw, parentZNode2) > -1);
children = zkw.getRecoverableZooKeeper().getChildren(parentZNode2, false); children = zkw.getRecoverableZooKeeper().getChildren(parentZNode2, false);
assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size()); assertEquals("Failed to delete child znodes of parent znode 1!", 0, children.size());
assertTrue("Wrongly deleted parent znode 3!", ZKUtil.checkExists(zkw, parentZNode3) > -1); assertTrue("Wrongly deleted parent znode 3!", ZKUtil.checkExists(zkw, parentZNode3) > -1);
children = zkw.getRecoverableZooKeeper().getChildren(parentZNode3, false); children = zkw.getRecoverableZooKeeper().getChildren(parentZNode3, false);
assertTrue("Failed to delete child znodes of parent znode 1!", 0 == children.size()); assertEquals("Failed to delete child znodes of parent znode 1!", 0, children.size());
} }
@Test @Test
@ -427,17 +426,18 @@ public class TestZKMulti {
// Each gets its own bucket // Each gets its own bucket
assertEquals( assertEquals(
Arrays.asList(Arrays.asList(tenByteOp), Arrays.asList(tenByteOp), Arrays.asList(tenByteOp)), Arrays.asList(Collections.singletonList(tenByteOp), Collections.singletonList(tenByteOp),
Collections.singletonList(tenByteOp)),
ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 15)); ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 15));
// Test internal boundary // Test internal boundary
assertEquals( assertEquals(
Arrays.asList(Arrays.asList(tenByteOp,tenByteOp), Arrays.asList(tenByteOp)), Arrays.asList(Arrays.asList(tenByteOp,tenByteOp), Collections.singletonList(tenByteOp)),
ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 20)); ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 20));
// Plenty of space for one partition // Plenty of space for one partition
assertEquals( assertEquals(
Arrays.asList(Arrays.asList(tenByteOp, tenByteOp, tenByteOp)), Collections.singletonList(Arrays.asList(tenByteOp, tenByteOp, tenByteOp)),
ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 50)); ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 50));
} }

View File

@ -48,7 +48,6 @@ import org.slf4j.LoggerFactory;
@Category({ ZKTests.class, MediumTests.class }) @Category({ ZKTests.class, MediumTests.class })
public class TestZKNodeTracker { public class TestZKNodeTracker {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestZKNodeTracker.class); HBaseClassTestRule.forClass(TestZKNodeTracker.class);
@ -75,16 +74,13 @@ public class TestZKNodeTracker {
ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), "testInterruptible", abortable); ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), "testInterruptible", abortable);
final TestTracker tracker = new TestTracker(zk, "/xyz", abortable); final TestTracker tracker = new TestTracker(zk, "/xyz", abortable);
tracker.start(); tracker.start();
Thread t = new Thread() { Thread t = new Thread(() -> {
@Override try {
public void run() { tracker.blockUntilAvailable();
try { } catch (InterruptedException e) {
tracker.blockUntilAvailable(); throw new RuntimeException("Interrupted", e);
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted", e);
}
} }
}; });
t.start(); t.start();
while (!t.isAlive()) { while (!t.isAlive()) {
Threads.sleep(1); Threads.sleep(1);
@ -165,7 +161,7 @@ public class TestZKNodeTracker {
// Create a new thread but with the existing thread's tracker to wait // Create a new thread but with the existing thread's tracker to wait
TestTracker threadTracker = thread.tracker; TestTracker threadTracker = thread.tracker;
thread = new WaitToGetDataThread(zk, node, threadTracker); thread = new WaitToGetDataThread(threadTracker);
thread.start(); thread.start();
// Verify other guys don't have data // Verify other guys don't have data
@ -211,19 +207,17 @@ public class TestZKNodeTracker {
} }
public static class WaitToGetDataThread extends Thread { public static class WaitToGetDataThread extends Thread {
TestTracker tracker; TestTracker tracker;
boolean hasData; boolean hasData;
public WaitToGetDataThread(ZKWatcher zk, String node) { WaitToGetDataThread(ZKWatcher zk, String node) {
tracker = new TestTracker(zk, node, null); tracker = new TestTracker(zk, node, null);
tracker.start(); tracker.start();
zk.registerListener(tracker); zk.registerListener(tracker);
hasData = false; hasData = false;
} }
public WaitToGetDataThread(ZKWatcher zk, String node, WaitToGetDataThread(TestTracker tracker) {
TestTracker tracker) {
this.tracker = tracker; this.tracker = tracker;
hasData = false; hasData = false;
} }
@ -242,8 +236,7 @@ public class TestZKNodeTracker {
} }
public static class TestTracker extends ZKNodeTracker { public static class TestTracker extends ZKNodeTracker {
public TestTracker(ZKWatcher watcher, String node, TestTracker(ZKWatcher watcher, String node, Abortable abortable) {
Abortable abortable) {
super(watcher, node, abortable); super(watcher, node, abortable);
} }
} }
@ -256,7 +249,7 @@ public class TestZKNodeTracker {
private Semaphore changedLock; private Semaphore changedLock;
private String node; private String node;
public TestingZKListener(ZKWatcher watcher, String node) { TestingZKListener(ZKWatcher watcher, String node) {
super(watcher); super(watcher);
deletedLock = new Semaphore(0); deletedLock = new Semaphore(0);
createdLock = new Semaphore(0); createdLock = new Semaphore(0);
@ -288,15 +281,15 @@ public class TestZKNodeTracker {
} }
} }
public void waitForDeletion() throws InterruptedException { void waitForDeletion() throws InterruptedException {
deletedLock.acquire(); deletedLock.acquire();
} }
public void waitForCreation() throws InterruptedException { void waitForCreation() throws InterruptedException {
createdLock.acquire(); createdLock.acquire();
} }
public void waitForDataChange() throws InterruptedException { void waitForDataChange() throws InterruptedException {
changedLock.acquire(); changedLock.acquire();
} }
} }
@ -342,5 +335,4 @@ public class TestZKNodeTracker {
// Check that we support the case when the znode does not exist // Check that we support the case when the znode does not exist
MasterAddressTracker.deleteIfEquals(zkw, sn.toString()); // must not throw an exception MasterAddressTracker.deleteIfEquals(zkw, sn.toString()); // must not throw an exception
} }
} }

View File

@ -53,7 +53,6 @@ import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
@Category({ ZKTests.class, MediumTests.class }) @Category({ ZKTests.class, MediumTests.class })
public class TestZKUtil { public class TestZKUtil {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestZKUtil.class); HBaseClassTestRule.forClass(TestZKUtil.class);
@ -69,7 +68,6 @@ public class TestZKUtil {
UTIL.startMiniZKCluster().getClientPort(); UTIL.startMiniZKCluster().getClientPort();
ZKW = new ZKWatcher(new Configuration(UTIL.getConfiguration()), TestZKUtil.class.getName(), ZKW = new ZKWatcher(new Configuration(UTIL.getConfiguration()), TestZKUtil.class.getName(),
new WarnOnlyAbortable()); new WarnOnlyAbortable());
} }
@AfterClass @AfterClass
@ -160,8 +158,8 @@ public class TestZKUtil {
zk.addAuthInfo("digest", Bytes.toBytes("hbase:rox")); zk.addAuthInfo("digest", Bytes.toBytes("hbase:rox"));
// Save the previous ACL // Save the previous ACL
Stat s = null; Stat s;
List<ACL> oldACL = null; List<ACL> oldACL;
while (true) { while (true) {
try { try {
s = new Stat(); s = new Stat();

View File

@ -26,7 +26,6 @@ import java.util.List;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule; import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.security.Superusers; import org.apache.hadoop.hbase.security.Superusers;
import org.apache.hadoop.hbase.testclassification.SmallTests; import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.testclassification.ZKTests; import org.apache.hadoop.hbase.testclassification.ZKTests;
@ -43,13 +42,12 @@ import org.mockito.Mockito;
@Category({ ZKTests.class, SmallTests.class }) @Category({ ZKTests.class, SmallTests.class })
public class TestZKUtilNoServer { public class TestZKUtilNoServer {
@ClassRule @ClassRule
public static final HBaseClassTestRule CLASS_RULE = public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestZKUtilNoServer.class); HBaseClassTestRule.forClass(TestZKUtilNoServer.class);
@Test @Test
public void testUnsecure() throws ZooKeeperConnectionException, IOException { public void testUnsecure() throws IOException {
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1"); conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
String node = "/hbase/testUnsecure"; String node = "/hbase/testUnsecure";
@ -60,7 +58,7 @@ public class TestZKUtilNoServer {
} }
@Test @Test
public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException { public void testSecuritySingleSuperuser() throws IOException {
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1"); conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
String node = "/hbase/testSecuritySingleSuperuser"; String node = "/hbase/testSecuritySingleSuperuser";
@ -72,7 +70,7 @@ public class TestZKUtilNoServer {
} }
@Test @Test
public void testCreateACL() throws ZooKeeperConnectionException, IOException { public void testCreateACL() throws IOException {
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3"); conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
String node = "/hbase/testCreateACL"; String node = "/hbase/testCreateACL";
@ -87,7 +85,7 @@ public class TestZKUtilNoServer {
} }
@Test @Test
public void testCreateACLWithSameUser() throws ZooKeeperConnectionException, IOException { public void testCreateACLWithSameUser() throws IOException {
Configuration conf = HBaseConfiguration.create(); Configuration conf = HBaseConfiguration.create();
conf.set(Superusers.SUPERUSER_CONF_KEY, "user4,@group1,user5,user6"); conf.set(Superusers.SUPERUSER_CONF_KEY, "user4,@group1,user5,user6");
UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser("user4")); UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser("user4"));
@ -103,7 +101,7 @@ public class TestZKUtilNoServer {
@Test(expected = KeeperException.SystemErrorException.class) @Test(expected = KeeperException.SystemErrorException.class)
public void testInterruptedDuringAction() public void testInterruptedDuringAction()
throws ZooKeeperConnectionException, IOException, KeeperException, InterruptedException { throws IOException, KeeperException, InterruptedException {
final RecoverableZooKeeper recoverableZk = Mockito.mock(RecoverableZooKeeper.class); final RecoverableZooKeeper recoverableZk = Mockito.mock(RecoverableZooKeeper.class);
ZKWatcher zkw = new ZKWatcher(HBaseConfiguration.create(), "unittest", null) { ZKWatcher zkw = new ZKWatcher(HBaseConfiguration.create(), "unittest", null) {
@Override @Override