use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class LoadFromLogTest method testReloadSnapshotWithMissingParent.
/**
* ZOOKEEPER-1573: test restoring a snapshot with deleted txns ahead of the
* snapshot file's zxid.
*/
@Test
public void testReloadSnapshotWithMissingParent() throws Exception {
// create transactions to create the snapshot with create/delete pattern
ZooKeeper zk = createZKClient(hostPort);
zk.create("/a", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
Stat stat = zk.exists("/a", false);
long createZxId = stat.getMzxid();
zk.create("/a/b", "".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
zk.delete("/a/b", -1);
zk.delete("/a", -1);
// force the zxid to be behind the content
ZooKeeperServer zks = serverFactory.getZooKeeperServer();
zks.getZKDatabase().setlastProcessedZxid(createZxId);
LOG.info("Set lastProcessedZxid to {}", zks.getZKDatabase().getDataTreeLastProcessedZxid());
// Force snapshot and restore
zks.takeSnapshot();
zks.shutdown();
stopServer();
startServer();
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class InvalidSnapshotTest method testSnapshot.
/**
* test the snapshot
* @throws Exception an exception could be expected
*/
@Test
public void testSnapshot() throws Exception {
File origSnapDir = new File(testData, "invalidsnap");
// This test otherwise updates the resources directory.
File snapDir = ClientBase.createTmpDir();
FileUtils.copyDirectory(origSnapDir, snapDir);
ZooKeeperServer zks = new ZooKeeperServer(snapDir, snapDir, 3000);
SyncRequestProcessor.setSnapCount(1000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
LOG.info("starting up the zookeeper server .. waiting");
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up");
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
// we know this from the data files
// this node is the last node in the snapshot
assertTrue(zk.exists("/9/9/8", false) != null);
} finally {
zk.close();
}
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class ACLTest method testNullACL.
@Test
public void testNullACL() throws Exception {
File tmpDir = ClientBase.createTmpDir();
ClientBase.setupTestEnv();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
ZooKeeper zk = ClientBase.createZKClient(HOSTPORT);
try {
// case 1 : null ACL with create
try {
zk.create("/foo", "foo".getBytes(), null, CreateMode.PERSISTENT);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 2 : null ACL with other create API
try {
zk.create("/foo", "foo".getBytes(), null, CreateMode.PERSISTENT, null);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
// case 3 : null ACL with setACL
try {
zk.setACL("/foo", null, 0);
fail("Expected InvalidACLException for null ACL parameter");
} catch (InvalidACLException e) {
// Expected. Do nothing
}
} finally {
zk.close();
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, ClientBase.CONNECTION_TIMEOUT), "waiting for server down");
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class ACLTest method testNettyIpAuthDefault.
@Test
public void testNettyIpAuthDefault() throws Exception {
String HOSTPORT = "127.0.0.1:" + PortAssignment.unique();
System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
ClientBase.setupTestEnv();
File tmpDir = ClientBase.createTmpDir();
ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
SyncRequestProcessor.setSnapCount(1000);
final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
ServerCnxnFactory f = ServerCnxnFactory.createFactory(PORT, -1);
f.startup(zks);
try {
LOG.info("starting up the zookeeper server .. waiting");
assertTrue(ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server being up");
ClientBase.createZKClient(HOSTPORT);
for (ServerCnxn cnxn : f.getConnections()) {
boolean foundID = false;
for (Id id : cnxn.getAuthInfo()) {
if (id.getScheme().equals("ip")) {
foundID = true;
break;
}
}
assertTrue(foundID);
}
} finally {
f.shutdown();
zks.shutdown();
assertTrue(ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT), "waiting for server down");
System.clearProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY);
}
}
use of org.apache.zookeeper.server.ZooKeeperServer in project zookeeper by apache.
the class CommandsTest method testStatCommandSecureOnly.
/**
* testing Stat command, when only SecureClientPort is defined by the user and there is no
* regular (non-SSL port) open. In this case zkServer.getServerCnxnFactory === null
* see: ZOOKEEPER-3633
*/
@Test
public void testStatCommandSecureOnly() {
Commands.StatCommand cmd = new Commands.StatCommand();
ZooKeeperServer zkServer = mock(ZooKeeperServer.class);
ServerCnxnFactory cnxnFactory = mock(ServerCnxnFactory.class);
ServerStats serverStats = mock(ServerStats.class);
ZKDatabase zkDatabase = mock(ZKDatabase.class);
when(zkServer.getSecureServerCnxnFactory()).thenReturn(cnxnFactory);
when(zkServer.serverStats()).thenReturn(serverStats);
when(zkServer.getZKDatabase()).thenReturn(zkDatabase);
when(zkDatabase.getNodeCount()).thenReturn(0);
CommandResponse response = cmd.run(zkServer, null);
assertThat(response.toMap().containsKey("connections"), is(true));
assertThat(response.toMap().containsKey("secure_connections"), is(true));
}
Aggregations