Java 类org.apache.zookeeper.server.ServerCnxnFactory 实例源码

项目:hadoop-oss    文件:ClientBaseWithFixes.java   
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
项目:hadoop-oss    文件:ClientBaseWithFixes.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);

            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:fuck_zookeeper    文件:QuorumPeer.java   
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        boolean quorumListenOnAllIPs,
        ServerCnxnFactory cnxnFactory, 
        QuorumVerifier quorumConfig) throws IOException {
    this();
    this.cnxnFactory = cnxnFactory;
    this.quorumPeers = quorumPeers;
    this.electionType = electionType;
    this.myid = myid;
    this.tickTime = tickTime;
    this.initLimit = initLimit;
    this.syncLimit = syncLimit;        
    this.quorumListenOnAllIPs = quorumListenOnAllIPs;
    this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
    this.zkDb = new ZKDatabase(this.logFactory);
    if(quorumConfig == null)
        this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
    else this.quorumConfig = quorumConfig;
}
项目:fuck_zookeeper    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:fuck_zookeeper    文件:ClientBase.java   
/**
 * Starting the given server instance
 */
public static void startServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort) throws IOException,
        InterruptedException {
    final int port = getPort(hostPort);
    LOG.info("STARTING server instance 127.0.0.1:{}", port);
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    factory.startup(zks);
    Assert.assertTrue("waiting for server up", ClientBase.waitForServerUp(
            "127.0.0.1:" + port, CONNECTION_TIMEOUT));
}
项目:fuck_zookeeper    文件:ClientBase.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb = null;
        {
            ZooKeeperServer zs = getServer(factory);
            if (zs != null) {
                zkDb = zs.getZKDatabase();
            }
        }
        factory.shutdown();
        try {
            if (zkDb != null) {
                zkDb.close();
            }
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:https-github.com-apache-zookeeper    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:https-github.com-apache-zookeeper    文件:SSLAuthTest.java   
@Before
public void setUp() throws Exception {
    String testDataPath = System.getProperty("test.data.dir", "build/test/data");
    System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
    System.setProperty(ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
    System.setProperty(ZKClientConfig.SECURE_CLIENT, "true");
    System.setProperty(ZKConfig.SSL_AUTHPROVIDER, "x509");
    System.setProperty(ZKConfig.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testKeyStore.jks");
    System.setProperty(ZKConfig.SSL_KEYSTORE_PASSWD, "testpass");
    System.setProperty(ZKConfig.SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/testTrustStore.jks");
    System.setProperty(ZKConfig.SSL_TRUSTSTORE_PASSWD, "testpass");
    System.setProperty("javax.net.debug", "ssl");
    System.setProperty("zookeeper.authProvider.x509", "org.apache.zookeeper.server.auth.X509AuthenticationProvider");

    String host = "localhost";
    int port = PortAssignment.unique();
    hostPort = host + ":" + port;

    serverFactory = ServerCnxnFactory.createFactory();
    serverFactory.configure(new InetSocketAddress(host, port), maxCnxns, true);

    super.setUp();
}
项目:hadoop    文件:ClientBaseWithFixes.java   
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
项目:hadoop    文件:ClientBaseWithFixes.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);

            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:ZooKeeper    文件:QuorumPeer.java   
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        boolean quorumListenOnAllIPs,
        ServerCnxnFactory cnxnFactory, 
        QuorumVerifier quorumConfig) throws IOException {
    this();
    this.cnxnFactory = cnxnFactory;
    this.quorumPeers = quorumPeers;
    this.electionType = electionType;
    this.myid = myid;
    this.tickTime = tickTime;
    this.initLimit = initLimit;
    this.syncLimit = syncLimit;        
    this.quorumListenOnAllIPs = quorumListenOnAllIPs;
    this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
    this.zkDb = new ZKDatabase(this.logFactory);
    if(quorumConfig == null)
        this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
    else this.quorumConfig = quorumConfig;
}
项目:ZooKeeper    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:ZooKeeper    文件:ClientBase.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb = null;
        {
            ZooKeeperServer zs = getServer(factory);
            if (zs != null) {
                zkDb = zs.getZKDatabase();
            }
        }
        factory.shutdown();
        try {
            if (zkDb != null) {
                zkDb.close();
            }
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:aliyun-oss-hadoop-fs    文件:ClientBaseWithFixes.java   
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
项目:aliyun-oss-hadoop-fs    文件:ClientBaseWithFixes.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);

            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:StreamProcessingInfrastructure    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:SecureKeeper    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:StreamProcessingInfrastructure    文件:ClientBase.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb = null;
        {
            ZooKeeperServer zs = getServer(factory);
            if (zs != null) {
                zkDb = zs.getZKDatabase();
            }
        }
        factory.shutdown();
        try {
            if (zkDb != null) {
                zkDb.close();
            }
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:zookeeper-junit    文件:ZKInstanceImpl.java   
@Override
public Future<Unit> start() {
    return Future(() -> {
        ZooKeeperServer zkServer = new ZooKeeperServer();
        FileTxnSnapLog log = new FileTxnSnapLog(new File(rootZooDir, "dataDir"), new File(rootZooDir, "snapDir"));
        zkServer.setTxnLogFactory(log);
        zkServer.setTickTime(2000);
        zkServer.setMinSessionTimeout(10000);
        zkServer.setMaxSessionTimeout(10000);
        ServerCnxnFactory cnxnFactory = ServerCnxnFactory.createFactory();
        cnxnFactory.configure(new InetSocketAddress(cfgPort), maxClientConnections);
        cnxnFactory.startup(zkServer);
           zkInstanceHolder = Some(new ZKInstanceHolder(log, cnxnFactory));
        //remember the port. if 0 was provided then ZK will pick a free port
        //it must be remembered for the scenario of restarting this instance
        //in such case we want to get the same port again
        cfgPort = cnxnFactory.getLocalPort();
    });
}
项目:bigstreams    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:bigstreams    文件:SessionTest.java   
@Before
public void setUp() throws Exception {
    if (tmpDir == null) {
        tmpDir = ClientBase.createTmpDir();
    }

    ClientBase.setupTestEnv();
    ZooKeeperServer zs = new ZooKeeperServer(tmpDir, tmpDir, TICK_TIME);

    final int PORT = Integer.parseInt(HOSTPORT.split(":")[1]);
    serverFactory = ServerCnxnFactory.createFactory(PORT, -1);
    serverFactory.startup(zs);

    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp(HOSTPORT,
                                          CONNECTION_TIMEOUT));
}
项目:bigstreams    文件:ClientBase.java   
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
项目:SecureKeeper    文件:SSLAuthTest.java   
@Before
public void setUp() throws Exception {
    String testDataPath = System.getProperty("test.data.dir", "build/test/data");
    System.setProperty(ServerCnxnFactory.ZOOKEEPER_SERVER_CNXN_FACTORY, "org.apache.zookeeper.server.NettyServerCnxnFactory");
    System.setProperty(ZooKeeper.ZOOKEEPER_CLIENT_CNXN_SOCKET, "org.apache.zookeeper.ClientCnxnSocketNetty");
    System.setProperty(ZooKeeper.SECURE_CLIENT, "true");
    System.setProperty(X509Util.SSL_AUTHPROVIDER, "x509");
    System.setProperty(X509Util.SSL_KEYSTORE_LOCATION, testDataPath + "/ssl/testKeyStore.jks");
    System.setProperty(X509Util.SSL_KEYSTORE_PASSWD, "testpass");
    System.setProperty(X509Util.SSL_TRUSTSTORE_LOCATION, testDataPath + "/ssl/testTrustStore.jks");
    System.setProperty(X509Util.SSL_TRUSTSTORE_PASSWD, "testpass");
    System.setProperty("javax.net.debug", "ssl");

    String host = "localhost";
    int port = PortAssignment.unique();
    hostPort = host + ":" + port;

    serverFactory = ServerCnxnFactory.createFactory();
    serverFactory.configure(new InetSocketAddress(host, port), maxCnxns, true);

    super.setUp();
}
项目:big-c    文件:ClientBaseWithFixes.java   
static ServerCnxnFactory createNewServerInstance(File dataDir,
        ServerCnxnFactory factory, String hostPort, int maxCnxns)
    throws IOException, InterruptedException
{
    ZooKeeperServer zks = new ZooKeeperServer(dataDir, dataDir, 3000);
    final int PORT = getPort(hostPort);
    if (factory == null) {
        factory = ServerCnxnFactory.createFactory(PORT, maxCnxns);
    }
    factory.startup(zks);
    Assert.assertTrue("waiting for server up",
               ClientBaseWithFixes.waitForServerUp("127.0.0.1:" + PORT,
                                          CONNECTION_TIMEOUT));

    return factory;
}
项目:big-c    文件:ClientBaseWithFixes.java   
static void shutdownServerInstance(ServerCnxnFactory factory,
        String hostPort)
{
    if (factory != null) {
        ZKDatabase zkDb;
        {
            ZooKeeperServer zs = getServer(factory);

            zkDb = zs.getZKDatabase();
        }
        factory.shutdown();
        try {
            zkDb.close();
        } catch (IOException ie) {
            LOG.warn("Error closing logs ", ie);
        }
        final int PORT = getPort(hostPort);

        Assert.assertTrue("waiting for server down",
                   ClientBaseWithFixes.waitForServerDown("127.0.0.1:" + PORT,
                                                CONNECTION_TIMEOUT));
    }
}
项目:zookeeper    文件:QuorumPeer.java   
public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        boolean quorumListenOnAllIPs,
        ServerCnxnFactory cnxnFactory, 
        QuorumVerifier quorumConfig) throws IOException {
    this();
    this.cnxnFactory = cnxnFactory;
    this.quorumPeers = quorumPeers;
    this.electionType = electionType;
    this.myid = myid;
    this.tickTime = tickTime;
    this.initLimit = initLimit;
    this.syncLimit = syncLimit;        
    this.quorumListenOnAllIPs = quorumListenOnAllIPs;
    this.logFactory = new FileTxnSnapLog(dataLogDir, dataDir);
    this.zkDb = new ZKDatabase(this.logFactory);
    if(quorumConfig == null)
        this.quorumConfig = new QuorumMaj(countParticipants(quorumPeers));
    else this.quorumConfig = quorumConfig;
}
项目:fuck_zookeeper    文件:QuorumPeer.java   
/**
 * For backward compatibility purposes, we instantiate QuorumMaj by default.
 */

public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        ServerCnxnFactory cnxnFactory) throws IOException {
    this(quorumPeers, dataDir, dataLogDir, electionType, myid, tickTime, 
            initLimit, syncLimit, false, cnxnFactory, 
            new QuorumMaj(countParticipants(quorumPeers)));
}
项目:fuck_zookeeper    文件:QuorumPeer.java   
/**
 * This constructor is only used by the existing unit test code.
 * It defaults to FileLogProvider persistence provider.
 */
public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
        File logDir, int clientPort, int electionAlg,
        long myid, int tickTime, int initLimit, int syncLimit)
    throws IOException
{
    this(quorumPeers, snapDir, logDir, electionAlg,
            myid,tickTime, initLimit,syncLimit, false,
            ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1),
            new QuorumMaj(countParticipants(quorumPeers)));
}
项目:fuck_zookeeper    文件:QuorumPeer.java   
/**
 * This constructor is only used by the existing unit test code.
 * It defaults to FileLogProvider persistence provider.
 */
public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
        File logDir, int clientPort, int electionAlg,
        long myid, int tickTime, int initLimit, int syncLimit, 
        QuorumVerifier quorumConfig)
    throws IOException
{
    this(quorumPeers, snapDir, logDir, electionAlg,
            myid,tickTime, initLimit,syncLimit, false,
            ServerCnxnFactory.createFactory(new InetSocketAddress(clientPort), -1),
            quorumConfig);
}
项目:fuck_zookeeper    文件:QuorumPeer.java   
/** Maximum number of connections allowed from particular host (ip) */
public int getMaxClientCnxnsPerHost() {
    ServerCnxnFactory fac = getCnxnFactory();
    if (fac == null) {
        return -1;
    }
    return fac.getMaxClientCnxnsPerHost();
}
项目:fuck_zookeeper    文件:PurgeTxnTest.java   
/**
 * test the purge
 * @throws Exception an exception might be thrown here
 */
@Test
public void testPurge() throws Exception {
    tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    ZooKeeperServer zks = new ZooKeeperServer(tmpDir, tmpDir, 3000);
    SyncRequestProcessor.setSnapCount(100);
    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< 2000; i++) {
            zk.create("/invalidsnap-" + i, new byte[0], Ids.OPEN_ACL_UNSAFE,
                    CreateMode.PERSISTENT);
        }
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.getTxnLogFactory().close();
    Assert.assertTrue("waiting for server to shutdown",
            ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
    // now corrupt the snapshot
    PurgeTxnLog.purge(tmpDir, tmpDir, 3);
    FileTxnSnapLog snaplog = new FileTxnSnapLog(tmpDir, tmpDir);
    List<File> listLogs = snaplog.findNRecentSnapshots(4);
    int numSnaps = 0;
    for (File ff: listLogs) {
        if (ff.getName().startsWith("snapshot")) {
            numSnaps++;
        }
    }
    Assert.assertTrue("exactly 3 snapshots ", (numSnaps == 3));
    snaplog.close();
    zks.shutdown();
}
项目:fuck_zookeeper    文件:LENonTerminateTest.java   
public MockQuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
        File logDir, int clientPort, int electionAlg,
        long myid, int tickTime, int initLimit, int syncLimit)
throws IOException
{
    super(quorumPeers, snapDir, logDir, electionAlg,
            myid,tickTime, initLimit,syncLimit, false,
            ServerCnxnFactory.createFactory(clientPort, -1),
            new QuorumMaj(countParticipants(quorumPeers)));
}
项目:fuck_zookeeper    文件:InvalidSnapshotTest.java   
/**
 * test the snapshot
 * @throws Exception an exception could be expected
 */
@Test
public void testSnapshot() throws Exception {
    File snapDir = new File(testData, "invalidsnap");
    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");
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, 20000, this);
    try {
        // we know this from the data files
        // this node is the last node in the snapshot

        Assert.assertTrue(zk.exists("/9/9/8", false) != null);
    } finally {
        zk.close();
    }
    f.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
项目:fuck_zookeeper    文件:ACLTest.java   
@Test
public void testDisconnectedAddAuth() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    ClientBase.setupTestEnv();
    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");
        Assert.assertTrue("waiting for server being up",
                ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
        ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
        try {
            zk.addAuthInfo("digest", "pat:test".getBytes());
            zk.setACL("/", Ids.CREATOR_ALL_ACL, -1);
        } finally {
            zk.close();
        }
    } finally {
        f.shutdown();
        zks.shutdown();
        Assert.assertTrue("waiting for server down",
                ClientBase.waitForServerDown(HOSTPORT,
                        ClientBase.CONNECTION_TIMEOUT));
    }
}
项目:fuck_zookeeper    文件:UpgradeTest.java   
/**
 * test the upgrade
 * @throws Exception
 */
@Test
public void testUpgrade() throws Exception {
    File upgradeDir = new File(testData, "upgrade");
    UpgradeMain upgrade = new UpgradeMain(upgradeDir, upgradeDir);
    upgrade.runUpgrade();
    ZooKeeperServer zks = new ZooKeeperServer(upgradeDir, upgradeDir, 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");
    Assert.assertTrue("waiting for server being up",
            ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
    ZooKeeper zk = new ZooKeeper(HOSTPORT, CONNECTION_TIMEOUT, this);
    Stat stat = zk.exists("/", false);
    List<String> children = zk.getChildren("/", false);
    Collections.sort(children);
    for (int i = 0; i < 10; i++) {
        Assert.assertTrue("data tree sanity check",
                ("test-" + i).equals(children.get(i)));
    }
    //try creating one node
    zk.create("/upgrade", "upgrade".getBytes(), Ids.OPEN_ACL_UNSAFE,
            CreateMode.PERSISTENT);
    // check if its there
    if (zk.exists("/upgrade", false) == null) {
        Assert.assertTrue(false);
    }

    zk.close();

    // bring down the server
    f.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown(HOSTPORT,
                       ClientBase.CONNECTION_TIMEOUT));

}
项目:fuck_zookeeper    文件:RepeatStartupTest.java   
/** bring up 5 quorum peers and then shut them down
 * and then bring one of the nodes as server
 *
 * @throws Exception might be thrown here
 */
@Test
public void testFail() throws Exception {
    QuorumBase qb = new QuorumBase();
    qb.setUp();

    System.out.println("Comment: the servers are at " + qb.hostPort);
    ZooKeeper zk = qb.createClient();
    zk.create("/test", null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zk.close();
    qb.shutdown(qb.s1);
    qb.shutdown(qb.s2);
    qb.shutdown(qb.s3);
    qb.shutdown(qb.s4);
    qb.shutdown(qb.s5);
    String hp = qb.hostPort.split(",")[0];
    ZooKeeperServer zks = new ZooKeeperServer(qb.s1.getTxnFactory().getSnapDir(),
            qb.s1.getTxnFactory().getDataDir(), 3000);
    final int PORT = Integer.parseInt(hp.split(":")[1]);
    ServerCnxnFactory factory = ServerCnxnFactory.createFactory(PORT, -1);

    factory.startup(zks);
    System.out.println("Comment: starting factory");
    Assert.assertTrue("waiting for server up",
               ClientBase.waitForServerUp("127.0.0.1:" + PORT,
                       QuorumTest.CONNECTION_TIMEOUT));
    factory.shutdown();
    zks.shutdown();
    Assert.assertTrue("waiting for server down",
               ClientBase.waitForServerDown("127.0.0.1:" + PORT,
                                            QuorumTest.CONNECTION_TIMEOUT));
    System.out.println("Comment: shutting down standalone");
}
项目:https-github.com-apache-zookeeper    文件:QuorumPeer.java   
/**
 * For backward compatibility purposes, we instantiate QuorumMaj by default.
 */

public QuorumPeer(Map<Long, QuorumServer> quorumPeers, File dataDir,
        File dataLogDir, int electionType,
        long myid, int tickTime, int initLimit, int syncLimit,
        ServerCnxnFactory cnxnFactory) throws IOException {
    this(quorumPeers, dataDir, dataLogDir, electionType, myid, tickTime,
            initLimit, syncLimit, false, cnxnFactory,
            new QuorumMaj(quorumPeers));
}
项目:https-github.com-apache-zookeeper    文件:QuorumPeer.java   
/**

     * This constructor is only used by the existing unit test code.
     * It defaults to FileLogProvider persistence provider.
     */
    public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
            File logDir, int clientPort, int electionAlg,
            long myid, int tickTime, int initLimit, int syncLimit)
        throws IOException
    {
        this(quorumPeers, snapDir, logDir, electionAlg, myid, tickTime, initLimit, syncLimit, false,
                ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1),
                new QuorumMaj(quorumPeers));
    }
项目:https-github.com-apache-zookeeper    文件:QuorumPeer.java   
/**
 * This constructor is only used by the existing unit test code.
 * It defaults to FileLogProvider persistence provider.
 */
public QuorumPeer(Map<Long,QuorumServer> quorumPeers, File snapDir,
        File logDir, int clientPort, int electionAlg,
        long myid, int tickTime, int initLimit, int syncLimit,
        QuorumVerifier quorumConfig)
    throws IOException
{
    this(quorumPeers, snapDir, logDir, electionAlg,
            myid,tickTime, initLimit,syncLimit, false,
            ServerCnxnFactory.createFactory(getClientAddress(quorumPeers, myid, clientPort), -1),
            quorumConfig);
}
项目:https-github.com-apache-zookeeper    文件:CommandExecutor.java   
/**
 * This class decides which command to be executed and then executes
 */
public boolean execute(ServerCnxn serverCnxn, PrintWriter pwriter,
        final int commandCode, ZooKeeperServer zkServer, ServerCnxnFactory factory) {
    AbstractFourLetterCommand command = getCommand(serverCnxn,pwriter, commandCode);

    if (command == null) {
        return false;
    }

    command.setZkServer(zkServer);
    command.setFactory(factory);
    command.start();
    return true;
}