Exemplo n.º 1
1
  @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 = new NIOServerCnxn.Factory(new InetSocketAddress(PORT));
    serverFactory.startup(zs);

    Assert.assertTrue(
        "waiting for server up", ClientBase.waitForServerUp(HOSTPORT, CONNECTION_TIMEOUT));
  }
Exemplo n.º 2
0
  /** Verify the ability to start a standalone server instance. */
  @Test
  public void testStandalone() throws Exception {
    LOG.info("STARTING " + getName());
    ClientBase.setupTestEnv();

    final int CLIENT_PORT = 3181;

    MainThread main = new MainThread(CLIENT_PORT);
    main.start();

    assertTrue(
        "waiting for server being up",
        ClientBase.waitForServerUp("localhost:" + CLIENT_PORT, CONNECTION_TIMEOUT));

    ZooKeeper zk = new ZooKeeper("localhost:" + CLIENT_PORT, ClientBase.CONNECTION_TIMEOUT, this);

    zk.create("/foo", "foobar".getBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    assertEquals(new String(zk.getData("/foo", null, null)), "foobar");
    zk.close();

    main.shutdown();

    assertTrue(
        "waiting for server down",
        ClientBase.waitForServerDown("localhost:" + CLIENT_PORT, ClientBase.CONNECTION_TIMEOUT));
  }
Exemplo n.º 3
0
  @Before
  public void setUp() throws Exception {
    /* some useful information - log the number of fds used before
     * and after a test is run. Helps to verify we are freeing resources
     * correctly. Unfortunately this only works on unix systems (the
     * only place sun has implemented as part of the mgmt bean api.
     */
    OSMXBean osMbean = new OSMXBean();
    if (osMbean.getUnix() == true) {
      initialFdCount = osMbean.getOpenFileDescriptorCount();
      LOG.info("Initial fdcount is: " + initialFdCount);
    }

    setupTestEnv();

    JMXEnv.setUp();

    setUpAll();

    tmpDir = createTmpDir(BASETEST);

    startServer();

    LOG.info("Client test setup finished");
  }
Exemplo n.º 4
0
  public void startServer() throws Exception {
    // create a ZooKeeper server(dataDir, dataLogDir, port)
    LOG.debug("Running ZK server");
    // ServerStats.registerAsConcrete();
    ClientBase.setupTestEnv();
    ZkTmpDir = File.createTempFile("zookeeper", "test");
    ZkTmpDir.delete();
    ZkTmpDir.mkdir();

    zks = new ZooKeeperServer(ZkTmpDir, ZkTmpDir, ZooKeeperDefaultPort);
    serverFactory = new NIOServerCnxnFactory();
    serverFactory.configure(zkaddr, 100);
    serverFactory.startup(zks);

    boolean b =
        ClientBase.waitForServerUp(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT);
    LOG.debug("Server up: " + b);

    // create a zookeeper client
    LOG.debug("Instantiate ZK Client");
    final CountDownLatch latch = new CountDownLatch(1);
    zkc =
        new ZooKeeper(
            getZooKeeperConnectString(),
            10000,
            new Watcher() {
              @Override
              public void process(WatchedEvent event) {
                // handle session disconnects and expires
                if (event.getState().equals(Watcher.Event.KeeperState.SyncConnected)) {
                  latch.countDown();
                }
              }
            });
    if (!latch.await(10000, TimeUnit.MILLISECONDS)) {
      zkc.close();
      fail("Could not connect to zookeeper server");
    }

    // initialize the zk client with values
    zkc.create("/ledgers", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
    zkc.create("/ledgers/available", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
  }