Search in sources :

Example 71 with ZooKeeperServer

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();
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) Stat(org.apache.zookeeper.data.Stat) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 72 with ZooKeeperServer

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");
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 73 with ZooKeeperServer

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");
    }
}
Also used : ZooKeeper(org.apache.zookeeper.ZooKeeper) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) InvalidACLException(org.apache.zookeeper.KeeperException.InvalidACLException) Test(org.junit.jupiter.api.Test)

Example 74 with ZooKeeperServer

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);
    }
}
Also used : ServerCnxn(org.apache.zookeeper.server.ServerCnxn) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) Id(org.apache.zookeeper.data.Id) File(java.io.File) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Example 75 with ZooKeeperServer

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));
}
Also used : ServerStats(org.apache.zookeeper.server.ServerStats) ServerCnxnFactory(org.apache.zookeeper.server.ServerCnxnFactory) ZKDatabase(org.apache.zookeeper.server.ZKDatabase) ZooKeeperServer(org.apache.zookeeper.server.ZooKeeperServer) Test(org.junit.jupiter.api.Test)

Aggregations

ZooKeeperServer (org.apache.zookeeper.server.ZooKeeperServer)96 File (java.io.File)39 Test (org.junit.jupiter.api.Test)33 ZooKeeper (org.apache.zookeeper.ZooKeeper)31 InetSocketAddress (java.net.InetSocketAddress)28 IOException (java.io.IOException)27 ServerCnxnFactory (org.apache.zookeeper.server.ServerCnxnFactory)26 NIOServerCnxnFactory (org.apache.zookeeper.server.NIOServerCnxnFactory)25 FileTxnSnapLog (org.apache.zookeeper.server.persistence.FileTxnSnapLog)10 Stat (org.apache.zookeeper.data.Stat)9 ZKDatabase (org.apache.zookeeper.server.ZKDatabase)8 ArrayList (java.util.ArrayList)6 ServerConfig (org.apache.zookeeper.server.ServerConfig)6 InterruptedIOException (java.io.InterruptedIOException)4 BindException (java.net.BindException)4 KeeperException (org.apache.zookeeper.KeeperException)4 Test (org.junit.Test)4 Field (java.lang.reflect.Field)3 ACL (org.apache.zookeeper.data.ACL)3 Proposal (org.apache.zookeeper.server.quorum.Leader.Proposal)3