use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class StandaloneTest method testStandaloneReconfigFails.
/**
* Verify that reconfiguration in standalone mode fails with
* KeeperException.UnimplementedException.
*/
@Test
public void testStandaloneReconfigFails() throws Exception {
ClientBase.setupTestEnv();
final int CLIENT_PORT = PortAssignment.unique();
final String HOSTPORT = "127.0.0.1:" + CLIENT_PORT;
File tmpDir = ClientBase.createTmpDir();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(CLIENT_PORT, -1);
f.startup(zks);
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up ");
CountdownWatcher watcher = new CountdownWatcher();
ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, watcher);
ZooKeeperAdmin zkAdmin = new ZooKeeperAdmin(HOSTPORT, CONNECTION_TIMEOUT, watcher);
watcher.waitForConnected(CONNECTION_TIMEOUT);
List<String> joiners = new ArrayList<String>();
joiners.add("server.2=localhost:1234:1235;1236");
// generate some transactions that will get logged
try {
zkAdmin.addAuthInfo("digest", "super:test".getBytes());
zkAdmin.reconfigure(joiners, null, null, -1, new Stat());
fail("Reconfiguration in standalone should trigger " + "UnimplementedException");
} catch (KeeperException.UnimplementedException ex) {
// expected
}
zk.close();
zks.shutdown();
f.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being down ");
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class ResponseCacheTest method performCacheTest.
public void performCacheTest(ZooKeeper zk, String path, boolean useCache) throws Exception {
ServerMetrics.getMetrics().resetAll();
Stat writeStat = new Stat();
Stat readStat = new Stat();
byte[] readData = null;
int reads = 10;
long expectedHits = 0;
long expectedMisses = 0;
ZooKeeperServer zks = serverFactory.getZooKeeperServer();
zks.setResponseCachingEnabled(useCache);
LOG.info("caching: {}", useCache);
if (useCache) {
assertEquals(zks.getReadResponseCache().getCacheSize(), 32);
assertEquals(zks.getGetChildrenResponseCache().getCacheSize(), 64);
}
byte[] writeData = "test1".getBytes();
zk.create(path, writeData, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, writeStat);
for (int i = 0; i < reads; ++i) {
readData = zk.getData(path, false, readStat);
assertArrayEquals(writeData, readData);
assertEquals(writeStat, readStat);
}
if (useCache) {
expectedMisses += 1;
expectedHits += reads - 1;
}
checkCacheStatus(expectedHits, expectedMisses, "response_packet_cache_hits", "response_packet_cache_misses");
writeData = "test2".getBytes();
writeStat = zk.setData(path, writeData, -1);
for (int i = 0; i < 10; ++i) {
readData = zk.getData(path, false, readStat);
assertArrayEquals(writeData, readData);
assertEquals(writeStat, readStat);
}
if (useCache) {
expectedMisses += 1;
expectedHits += reads - 1;
}
checkCacheStatus(expectedHits, expectedMisses, "response_packet_cache_hits", "response_packet_cache_misses");
// Create a child beneath the tested node. This won't change the data of
// the tested node, but will change it's pzxid. The next read of the tested
// node should miss in the cache. The data should still match what was written
// before, but the stat information should not.
zk.create(path + "/child", "child".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, null);
readData = zk.getData(path, false, readStat);
if (useCache) {
expectedMisses++;
}
assertArrayEquals(writeData, readData);
assertNotSame(writeStat, readStat);
checkCacheStatus(expectedHits, expectedMisses, "response_packet_cache_hits", "response_packet_cache_misses");
ServerMetrics.getMetrics().resetAll();
expectedHits = 0;
expectedMisses = 0;
createPath(path + "/a", zk);
createPath(path + "/a/b", zk);
createPath(path + "/a/c", zk);
createPath(path + "/a/b/d", zk);
createPath(path + "/a/b/e", zk);
createPath(path + "/a/b/e/f", zk);
createPath(path + "/a/b/e/g", zk);
createPath(path + "/a/b/e/h", zk);
checkPath(path + "/a", zk, 2);
checkPath(path + "/a/b", zk, 2);
checkPath(path + "/a/c", zk, 0);
checkPath(path + "/a/b/d", zk, 0);
checkPath(path + "/a/b/e", zk, 3);
checkPath(path + "/a/b/e/h", zk, 0);
if (useCache) {
expectedMisses += 6;
}
checkCacheStatus(expectedHits, expectedMisses, "response_packet_get_children_cache_hits", "response_packet_get_children_cache_misses");
checkPath(path + "/a", zk, 2);
checkPath(path + "/a/b", zk, 2);
checkPath(path + "/a/c", zk, 0);
if (useCache) {
expectedHits += 3;
}
checkCacheStatus(expectedHits, expectedMisses, "response_packet_get_children_cache_hits", "response_packet_get_children_cache_misses");
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class ThrottledOpQuorumTest method testThrottledOpLeader.
@Test
public void testThrottledOpLeader() throws IOException, InterruptedException, KeeperException {
ZooKeeper zk = null;
try {
zk = createClient("localhost:" + getLeaderClientPort());
ZooKeeperServer zs = getLeaderQuorumPeer().getActiveServer();
ThrottledOpHelper test = new ThrottledOpHelper();
test.testThrottledOp(zk, zs);
} finally {
if (zk != null) {
zk.close();
}
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class ThrottledOpQuorumTest method testThrottledAclLeader.
@Test
public void testThrottledAclLeader() throws Exception {
ZooKeeper zk = null;
try {
zk = createClient("localhost:" + getLeaderClientPort());
ZooKeeperServer zs = getLeaderQuorumPeer().getActiveServer();
ThrottledOpHelper test = new ThrottledOpHelper();
test.testThrottledAcl(zk, zs);
} finally {
if (zk != null) {
zk.close();
}
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class LoadFromLogTest method testRestoreWithTransactionErrors.
/**
* Test we can restore a snapshot that has errors and data ahead of the zxid
* of the snapshot file.
*/
@Test
public void testRestoreWithTransactionErrors() throws Exception {
// generate some transactions
ZooKeeper zk = createZKClient(hostPort);
try {
for (int i = 0; i < NUM_MESSAGES; i++) {
try {
zk.create("/invaliddir/test-", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
} catch (NoNodeException e) {
// Expected
}
}
} finally {
zk.close();
}
// force the zxid to be behind the content
ZooKeeperServer zks = serverFactory.getZooKeeperServer();
zks.getZKDatabase().setlastProcessedZxid(zks.getZKDatabase().getDataTreeLastProcessedZxid() - 10);
LOG.info("Set lastProcessedZxid to {}", zks.getZKDatabase().getDataTreeLastProcessedZxid());
// Force snapshot and restore
zks.takeSnapshot();
zks.shutdown();
stopServer();
zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
startServer();
}
Aggregations