HBASE-22787 Cleaned up tests in hbase-zookeeper
Signed-off-by: Peter Somogyi <psomogyi@apache.org>
This commit is contained in:
parent
a6f065396a
commit
abb60faa6c
|
@ -32,7 +32,6 @@ import org.apache.yetus.audience.InterfaceAudience;
|
|||
*/
|
||||
@InterfaceAudience.Public
|
||||
public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
|
||||
|
||||
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
|
||||
* exist already. A subdir of {@link #getBaseTestDir()}
|
||||
* @see #getTestFileSystem()
|
||||
* exist already. A subdir of {@code HBaseCommonTestingUtility#getBaseTestDir()}
|
||||
*/
|
||||
Path getClusterTestDir() {
|
||||
if (clusterTestDir == null) {
|
||||
|
@ -124,8 +122,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
|
|||
|
||||
if (clientPortList != null) {
|
||||
// Ignore extra client ports
|
||||
int clientPortListSize = (clientPortList.length <= zooKeeperServerNum) ? clientPortList.length
|
||||
: zooKeeperServerNum;
|
||||
int clientPortListSize = Math.min(clientPortList.length, zooKeeperServerNum);
|
||||
for (int i = 0; i < clientPortListSize; i++) {
|
||||
this.zkCluster.addClientPort(clientPortList[i]);
|
||||
}
|
||||
|
@ -182,7 +179,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
|
|||
* Gets a ZKWatcher.
|
||||
*/
|
||||
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;
|
||||
|
||||
@Override
|
||||
|
@ -196,7 +193,6 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
|
|||
return aborted;
|
||||
}
|
||||
});
|
||||
return zkw;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -207,7 +203,7 @@ public class HBaseZKTestingUtility extends HBaseCommonTestingUtility {
|
|||
boolean ret = super.cleanupTestDir();
|
||||
if (deleteDir(this.clusterTestDir)) {
|
||||
this.clusterTestDir = null;
|
||||
return ret & true;
|
||||
return ret;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.apache.hadoop.hbase.zookeeper;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
@ -41,7 +42,6 @@ import org.junit.experimental.categories.Category;
|
|||
*/
|
||||
@Category({ ZKTests.class, MediumTests.class })
|
||||
public class TestHQuorumPeer {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestHQuorumPeer.class);
|
||||
|
@ -75,7 +75,7 @@ public class TestHQuorumPeer {
|
|||
assertEquals(Integer.valueOf(PORT_NO),
|
||||
Integer.valueOf(properties.getProperty("clientPort")));
|
||||
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);
|
||||
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("b.foo.bar:2888:3888", properties.get("server.1"));
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -72,8 +72,6 @@ public class TestReadOnlyZKClient {
|
|||
|
||||
private static HBaseZKTestingUtility UTIL = new HBaseZKTestingUtility();
|
||||
|
||||
private static int PORT;
|
||||
|
||||
private static String PATH = "/test";
|
||||
|
||||
private static byte[] DATA;
|
||||
|
@ -84,9 +82,9 @@ public class TestReadOnlyZKClient {
|
|||
|
||||
@BeforeClass
|
||||
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];
|
||||
ThreadLocalRandom.current().nextBytes(DATA);
|
||||
zk.create(PATH, DATA, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
|
||||
|
@ -95,7 +93,7 @@ public class TestReadOnlyZKClient {
|
|||
}
|
||||
zk.close();
|
||||
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_INTERVAL_MILLIS, 100);
|
||||
conf.setInt(ReadOnlyZKClient.KEEPALIVE_MILLIS, 3000);
|
||||
|
@ -116,12 +114,12 @@ public class TestReadOnlyZKClient {
|
|||
UTIL.waitFor(10000, new ExplainingPredicate<Exception>() {
|
||||
|
||||
@Override
|
||||
public boolean evaluate() throws Exception {
|
||||
public boolean evaluate() {
|
||||
return RO_ZK.zookeeper == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String explainFailure() throws Exception {
|
||||
public String explainFailure() {
|
||||
return "Connection to zookeeper is still alive";
|
||||
}
|
||||
});
|
||||
|
|
|
@ -43,17 +43,15 @@ import org.junit.experimental.categories.Category;
|
|||
|
||||
@Category({ ZKTests.class, MediumTests.class })
|
||||
public class TestRecoverableZooKeeper {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestRecoverableZooKeeper.class);
|
||||
|
||||
private final static HBaseZKTestingUtility TEST_UTIL = new HBaseZKTestingUtility();
|
||||
|
||||
Abortable abortable = new Abortable() {
|
||||
private Abortable abortable = new Abortable() {
|
||||
@Override
|
||||
public void abort(String why, Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -94,16 +92,15 @@ public class TestRecoverableZooKeeper {
|
|||
assertTrue(Bytes.equals(opened, data));
|
||||
}
|
||||
|
||||
class ZookeeperStub extends ZooKeeper {
|
||||
|
||||
static class ZookeeperStub extends ZooKeeper {
|
||||
private int throwExceptionInNumOperations;
|
||||
|
||||
public ZookeeperStub(String connectString, int sessionTimeout, Watcher watcher)
|
||||
ZookeeperStub(String connectString, int sessionTimeout, Watcher watcher)
|
||||
throws IOException {
|
||||
super(connectString, sessionTimeout, watcher);
|
||||
}
|
||||
|
||||
public void setThrowExceptionInNumOperations(int throwExceptionInNumOperations) {
|
||||
void setThrowExceptionInNumOperations(int throwExceptionInNumOperations) {
|
||||
this.throwExceptionInNumOperations = throwExceptionInNumOperations;
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ public class TestZKLeaderManager {
|
|||
private AtomicBoolean master = new AtomicBoolean(false);
|
||||
private int index;
|
||||
|
||||
public MockLeader(ZKWatcher watcher, int index) {
|
||||
MockLeader(ZKWatcher watcher, int index) {
|
||||
setDaemon(true);
|
||||
setName("TestZKLeaderManager-leader-" + index);
|
||||
this.index = index;
|
||||
|
@ -113,7 +113,7 @@ public class TestZKLeaderManager {
|
|||
}
|
||||
}
|
||||
|
||||
public void abdicate() {
|
||||
void abdicate() {
|
||||
zkLeader.stepDownAsLeader();
|
||||
master.set(false);
|
||||
}
|
||||
|
@ -214,9 +214,9 @@ public class TestZKLeaderManager {
|
|||
assertNotNull("New leader should exist", currentLeader);
|
||||
}
|
||||
|
||||
private MockLeader getCurrentLeader() throws Exception {
|
||||
private MockLeader getCurrentLeader() {
|
||||
MockLeader currentLeader = null;
|
||||
outer:
|
||||
|
||||
// Wait up to 10 secs for initial leader
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
for (int j = 0; j < CANDIDATES.length; j++) {
|
||||
|
@ -229,18 +229,16 @@ public class TestZKLeaderManager {
|
|||
}
|
||||
}
|
||||
if (currentLeader != null) {
|
||||
break outer;
|
||||
break;
|
||||
}
|
||||
Threads.sleep(100);
|
||||
}
|
||||
return currentLeader;
|
||||
}
|
||||
|
||||
private static ZKWatcher 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);
|
||||
ZKWatcher zk = new ZKWatcher(copy, name, abort);
|
||||
return zk;
|
||||
return new ZKWatcher(copy, name, abort);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.junit.experimental.categories.Category;
|
|||
|
||||
@Category({ ZKTests.class, SmallTests.class })
|
||||
public class TestZKMainServer {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
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
|
||||
protected static class ExitException extends SecurityException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final int status;
|
||||
public ExitException(int status) {
|
||||
|
||||
ExitException() {
|
||||
super("There is no escape!");
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +63,7 @@ public class TestZKMainServer {
|
|||
@Override
|
||||
public void checkExit(int status) {
|
||||
super.checkExit(status);
|
||||
throw new ExitException(status);
|
||||
throw new ExitException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +114,7 @@ public class TestZKMainServer {
|
|||
// 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");
|
||||
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
|
||||
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
|
||||
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");
|
||||
ensemble = parser.parse(c);
|
||||
parser.parse(c);
|
||||
Assert.fail("IPv6 address should be 8 groups.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
package org.apache.hadoop.hbase.zookeeper;
|
||||
|
||||
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 java.util.ArrayList;
|
||||
|
@ -48,11 +48,10 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Test ZooKeeper multi-update functionality
|
||||
* Test ZooKeeper multi-update functionality.
|
||||
*/
|
||||
@Category({ ZKTests.class, MediumTests.class })
|
||||
public class TestZKMulti {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestZKMulti.class);
|
||||
|
@ -113,7 +112,7 @@ public class TestZKMulti {
|
|||
LinkedList<ZKUtilOp> singleDelete = new LinkedList<>();
|
||||
singleDelete.add(ZKUtilOp.deleteNodeFailSilent(path));
|
||||
ZKUtil.multiOrSequential(zkw, singleDelete, false);
|
||||
assertTrue(ZKUtil.checkExists(zkw, path) == -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, path), -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,8 +151,8 @@ public class TestZKMulti {
|
|||
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
|
||||
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path2),
|
||||
Bytes.add(Bytes.toBytes(path2), Bytes.toBytes(path2))));
|
||||
assertTrue(ZKUtil.checkExists(zkw, path3) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, path4) == -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, path3), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, path4), -1);
|
||||
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path5), Bytes.toBytes(path5)));
|
||||
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path6), Bytes.toBytes(path6)));
|
||||
}
|
||||
|
@ -214,9 +213,9 @@ public class TestZKMulti {
|
|||
}
|
||||
assertTrue(caughtNoNode);
|
||||
// assert that none of the operations succeeded
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathA) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathB) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathC) == -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathA), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathB), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathC), -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -247,11 +246,11 @@ public class TestZKMulti {
|
|||
}
|
||||
assertTrue(caughtNodeExists);
|
||||
// check that no modifications were made
|
||||
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1);
|
||||
assertNotEquals(ZKUtil.checkExists(zkw, pathX), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathY), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathZ), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathW), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathV), -1);
|
||||
|
||||
// test that with multiple failures, throws an exception corresponding to first failure in list
|
||||
ops = new LinkedList<>();
|
||||
|
@ -266,11 +265,11 @@ public class TestZKMulti {
|
|||
}
|
||||
assertTrue(caughtNoNode);
|
||||
// check that no modifications were made
|
||||
assertFalse(ZKUtil.checkExists(zkw, pathX) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathY) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathZ) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathW) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, pathV) == -1);
|
||||
assertNotEquals(ZKUtil.checkExists(zkw, pathX), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathY), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathZ), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathW), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, pathV), -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -297,9 +296,9 @@ public class TestZKMulti {
|
|||
ZKUtil.multiOrSequential(zkw, ops, true);
|
||||
assertTrue(Bytes.equals(ZKUtil.getData(zkw, path1),
|
||||
Bytes.add(Bytes.toBytes(path1), Bytes.toBytes(path1))));
|
||||
assertTrue(ZKUtil.checkExists(zkw, path2) == -1);
|
||||
assertTrue(ZKUtil.checkExists(zkw, path3) == -1);
|
||||
assertFalse(ZKUtil.checkExists(zkw, path4) == -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, path2), -1);
|
||||
assertEquals(ZKUtil.checkExists(zkw, path3), -1);
|
||||
assertNotEquals(ZKUtil.checkExists(zkw, path4), -1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,7 +316,7 @@ public class TestZKMulti {
|
|||
ZKUtil.checkExists(zkw, parentZNode) > -1);
|
||||
List<String> children = zkw.getRecoverableZooKeeper().getChildren(
|
||||
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);
|
||||
|
||||
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
|
||||
|
@ -344,9 +343,9 @@ public class TestZKMulti {
|
|||
|
||||
ZKUtil.deleteNodeRecursivelyMultiOrSequential(zkw, false, parentZNode1, parentZNode2,
|
||||
parentZNode3);
|
||||
assertTrue("Parent znode 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1) == -1);
|
||||
assertTrue("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 1 should be deleted.", ZKUtil.checkExists(zkw, parentZNode1), -1);
|
||||
assertEquals("Parent znode 2 should be deleted.", ZKUtil.checkExists(zkw, parentZNode2), -1);
|
||||
assertEquals("Parent znode 3 should be deleted.", ZKUtil.checkExists(zkw, parentZNode3), -1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -363,15 +362,15 @@ public class TestZKMulti {
|
|||
|
||||
assertTrue("Wrongly deleted parent znode 1!", ZKUtil.checkExists(zkw, parentZNode1) > -1);
|
||||
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);
|
||||
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);
|
||||
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
|
||||
|
@ -427,17 +426,18 @@ public class TestZKMulti {
|
|||
|
||||
// Each gets its own bucket
|
||||
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));
|
||||
|
||||
// Test internal boundary
|
||||
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));
|
||||
|
||||
// Plenty of space for one partition
|
||||
assertEquals(
|
||||
Arrays.asList(Arrays.asList(tenByteOp, tenByteOp, tenByteOp)),
|
||||
Collections.singletonList(Arrays.asList(tenByteOp, tenByteOp, tenByteOp)),
|
||||
ZKUtil.partitionOps(Arrays.asList(tenByteOp, tenByteOp, tenByteOp), 50));
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
@Category({ ZKTests.class, MediumTests.class })
|
||||
public class TestZKNodeTracker {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestZKNodeTracker.class);
|
||||
|
@ -75,16 +74,13 @@ public class TestZKNodeTracker {
|
|||
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);
|
||||
}
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
tracker.blockUntilAvailable();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Interrupted", e);
|
||||
}
|
||||
};
|
||||
});
|
||||
t.start();
|
||||
while (!t.isAlive()) {
|
||||
Threads.sleep(1);
|
||||
|
@ -165,7 +161,7 @@ public class TestZKNodeTracker {
|
|||
|
||||
// Create a new thread but with the existing thread's tracker to wait
|
||||
TestTracker threadTracker = thread.tracker;
|
||||
thread = new WaitToGetDataThread(zk, node, threadTracker);
|
||||
thread = new WaitToGetDataThread(threadTracker);
|
||||
thread.start();
|
||||
|
||||
// Verify other guys don't have data
|
||||
|
@ -211,19 +207,17 @@ public class TestZKNodeTracker {
|
|||
}
|
||||
|
||||
public static class WaitToGetDataThread extends Thread {
|
||||
|
||||
TestTracker tracker;
|
||||
boolean hasData;
|
||||
|
||||
public WaitToGetDataThread(ZKWatcher zk, String node) {
|
||||
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) {
|
||||
WaitToGetDataThread(TestTracker tracker) {
|
||||
this.tracker = tracker;
|
||||
hasData = false;
|
||||
}
|
||||
|
@ -242,8 +236,7 @@ public class TestZKNodeTracker {
|
|||
}
|
||||
|
||||
public static class TestTracker extends ZKNodeTracker {
|
||||
public TestTracker(ZKWatcher watcher, String node,
|
||||
Abortable abortable) {
|
||||
TestTracker(ZKWatcher watcher, String node, Abortable abortable) {
|
||||
super(watcher, node, abortable);
|
||||
}
|
||||
}
|
||||
|
@ -256,7 +249,7 @@ public class TestZKNodeTracker {
|
|||
private Semaphore changedLock;
|
||||
private String node;
|
||||
|
||||
public TestingZKListener(ZKWatcher watcher, String node) {
|
||||
TestingZKListener(ZKWatcher watcher, String node) {
|
||||
super(watcher);
|
||||
deletedLock = 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();
|
||||
}
|
||||
|
||||
public void waitForCreation() throws InterruptedException {
|
||||
void waitForCreation() throws InterruptedException {
|
||||
createdLock.acquire();
|
||||
}
|
||||
|
||||
public void waitForDataChange() throws InterruptedException {
|
||||
void waitForDataChange() throws InterruptedException {
|
||||
changedLock.acquire();
|
||||
}
|
||||
}
|
||||
|
@ -342,5 +335,4 @@ public class TestZKNodeTracker {
|
|||
// Check that we support the case when the znode does not exist
|
||||
MasterAddressTracker.deleteIfEquals(zkw, sn.toString()); // must not throw an exception
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,7 +53,6 @@ import org.apache.hbase.thirdparty.com.google.common.io.Closeables;
|
|||
|
||||
@Category({ ZKTests.class, MediumTests.class })
|
||||
public class TestZKUtil {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestZKUtil.class);
|
||||
|
@ -69,7 +68,6 @@ public class TestZKUtil {
|
|||
UTIL.startMiniZKCluster().getClientPort();
|
||||
ZKW = new ZKWatcher(new Configuration(UTIL.getConfiguration()), TestZKUtil.class.getName(),
|
||||
new WarnOnlyAbortable());
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -160,8 +158,8 @@ public class TestZKUtil {
|
|||
zk.addAuthInfo("digest", Bytes.toBytes("hbase:rox"));
|
||||
|
||||
// Save the previous ACL
|
||||
Stat s = null;
|
||||
List<ACL> oldACL = null;
|
||||
Stat s;
|
||||
List<ACL> oldACL;
|
||||
while (true) {
|
||||
try {
|
||||
s = new Stat();
|
||||
|
|
|
@ -26,7 +26,6 @@ import java.util.List;
|
|||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.HBaseClassTestRule;
|
||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
|
||||
import org.apache.hadoop.hbase.security.Superusers;
|
||||
import org.apache.hadoop.hbase.testclassification.SmallTests;
|
||||
import org.apache.hadoop.hbase.testclassification.ZKTests;
|
||||
|
@ -43,13 +42,12 @@ import org.mockito.Mockito;
|
|||
|
||||
@Category({ ZKTests.class, SmallTests.class })
|
||||
public class TestZKUtilNoServer {
|
||||
|
||||
@ClassRule
|
||||
public static final HBaseClassTestRule CLASS_RULE =
|
||||
HBaseClassTestRule.forClass(TestZKUtilNoServer.class);
|
||||
|
||||
@Test
|
||||
public void testUnsecure() throws ZooKeeperConnectionException, IOException {
|
||||
public void testUnsecure() throws IOException {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
|
||||
String node = "/hbase/testUnsecure";
|
||||
|
@ -60,7 +58,7 @@ public class TestZKUtilNoServer {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSecuritySingleSuperuser() throws ZooKeeperConnectionException, IOException {
|
||||
public void testSecuritySingleSuperuser() throws IOException {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1");
|
||||
String node = "/hbase/testSecuritySingleSuperuser";
|
||||
|
@ -72,7 +70,7 @@ public class TestZKUtilNoServer {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreateACL() throws ZooKeeperConnectionException, IOException {
|
||||
public void testCreateACL() throws IOException {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
conf.set(Superusers.SUPERUSER_CONF_KEY, "user1,@group1,user2,@group2,user3");
|
||||
String node = "/hbase/testCreateACL";
|
||||
|
@ -87,7 +85,7 @@ public class TestZKUtilNoServer {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testCreateACLWithSameUser() throws ZooKeeperConnectionException, IOException {
|
||||
public void testCreateACLWithSameUser() throws IOException {
|
||||
Configuration conf = HBaseConfiguration.create();
|
||||
conf.set(Superusers.SUPERUSER_CONF_KEY, "user4,@group1,user5,user6");
|
||||
UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser("user4"));
|
||||
|
@ -103,7 +101,7 @@ public class TestZKUtilNoServer {
|
|||
|
||||
@Test(expected = KeeperException.SystemErrorException.class)
|
||||
public void testInterruptedDuringAction()
|
||||
throws ZooKeeperConnectionException, IOException, KeeperException, InterruptedException {
|
||||
throws IOException, KeeperException, InterruptedException {
|
||||
final RecoverableZooKeeper recoverableZk = Mockito.mock(RecoverableZooKeeper.class);
|
||||
ZKWatcher zkw = new ZKWatcher(HBaseConfiguration.create(), "unittest", null) {
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue