use of org.apache.zookeeper.ZooKeeper in project zookeeper by apache.
the class ChrootClientTest method setUp.
@Override
public void setUp() throws Exception {
String hp = hostPort;
hostPort = hostPort + "/chrootclienttest";
System.out.println(hostPort);
super.setUp();
LOG.info("STARTING " + getTestName());
ZooKeeper zk = createClient(hp);
try {
zk.create("/chrootclienttest", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} finally {
zk.close();
}
}
use of org.apache.zookeeper.ZooKeeper in project zookeeper by apache.
the class ClientBase method verifyUnexpectedBeans.
private void verifyUnexpectedBeans(Set<ObjectName> children) {
if (allClients != null) {
for (ZooKeeper zkc : allClients) {
Iterator<ObjectName> childItr = children.iterator();
while (childItr.hasNext()) {
ObjectName clientBean = childItr.next();
if (clientBean.toString().contains(getHexSessionId(zkc.getSessionId()))) {
LOG.info("found name:" + zkc.getSessionId() + " client bean:" + clientBean.toString());
childItr.remove();
}
}
}
}
for (ObjectName bean : children) {
LOG.info("unexpected:" + bean.toString());
}
Assert.assertEquals("Unexpected bean exists!", 0, children.size());
}
use of org.apache.zookeeper.ZooKeeper in project zookeeper by apache.
the class ClientHammerTest method runHammer.
public void runHammer(final int threadCount, final int childCount) throws Throwable {
try {
HammerThread[] threads = new HammerThread[threadCount];
long start = Time.currentElapsedTime();
for (int i = 0; i < threads.length; i++) {
ZooKeeper zk = createClient();
String prefix = "/test-" + i;
zk.create(prefix, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
prefix += "/";
HammerThread thread = new BasicHammerThread("BasicHammerThread-" + i, zk, prefix, childCount);
thread.start();
threads[i] = thread;
}
verifyHammer(start, threads, childCount);
} catch (Throwable t) {
LOG.error("test Assert.failed", t);
throw t;
}
}
use of org.apache.zookeeper.ZooKeeper in project zookeeper by apache.
the class DisconnectedWatcherTest method testDefaultWatcherAutoResetWithChroot.
@Test
public void testDefaultWatcherAutoResetWithChroot() throws Exception {
ZooKeeper zk1 = createClient();
zk1.create("/ch1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
MyWatcher watcher = new MyWatcher();
ZooKeeper zk2 = createClient(watcher, hostPort + "/ch1");
zk2.getChildren("/", true);
// this call shouldn't trigger any error or watch
zk1.create("/youdontmatter1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
// this should trigger the watch
zk1.create("/ch1/youshouldmatter1", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
WatchedEvent e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertNotNull(e);
Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
Assert.assertEquals("/", e.getPath());
zk2.getChildren("/", true);
stopServer();
watcher.waitForDisconnected(3000);
startServer();
watcher.waitForConnected(3000);
// this should trigger the watch
zk1.create("/ch1/youshouldmatter2", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
e = watcher.events.poll(TIMEOUT, TimeUnit.MILLISECONDS);
Assert.assertNotNull(e);
Assert.assertEquals(EventType.NodeChildrenChanged, e.getType());
Assert.assertEquals("/", e.getPath());
}
use of org.apache.zookeeper.ZooKeeper in project zookeeper by apache.
the class EmptiedSnapshotRecoveryTest method runTest.
public void runTest(boolean leaveEmptyFile) throws Exception {
File tmpSnapDir = ClientBase.createTmpDir();
File tmpLogDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000);
SyncRequestProcessor.setSnapCount(SNAP_COUNT);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
Assert.assertTrue("waiting for server being up ", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
try {
for (int i = 0; i < N_TRANSACTIONS; i++) {
zk.create("/node-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
}
} finally {
zk.close();
}
f.shutdown();
zks.shutdown();
Assert.assertTrue("waiting for server to shutdown", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
// start server again with intact database
zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000);
zks.startdata();
long zxid = zks.getZKDatabase().getDataTreeLastProcessedZxid();
LOG.info("After clean restart, zxid = " + zxid);
Assert.assertTrue("zxid > 0", zxid > 0);
zks.shutdown();
// Make all snapshots empty
FileTxnSnapLog txnLogFactory = zks.getTxnLogFactory();
List<File> snapshots = txnLogFactory.findNRecentSnapshots(10);
Assert.assertTrue("We have a snapshot to corrupt", snapshots.size() > 0);
for (File file : snapshots) {
if (leaveEmptyFile) {
new PrintWriter(file).close();
} else {
file.delete();
}
}
// start server again with corrupted database
zks = new ZooKeeperServer(tmpSnapDir, tmpLogDir, 3000);
try {
zks.startdata();
zxid = zks.getZKDatabase().loadDataBase();
Assert.fail("Should have gotten exception for corrupted database");
} catch (IOException e) {
// expected behavior
}
zks.shutdown();
}
Aggregations