Пример #1
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));
  }
Пример #2
0
  public void killServer() throws Exception {
    if (zkc != null) {
      zkc.close();
    }

    // shutdown ZK server
    if (serverFactory != null) {
      serverFactory.shutdown();
      assertTrue(
          ClientBase.waitForServerDown(getZooKeeperConnectString(), ClientBase.CONNECTION_TIMEOUT),
          "waiting for server down");
    }
    // ServerStats.unregister();
    FileUtils.deleteDirectory(ZkTmpDir);
  }
  @After
  @Override
  protected void tearDown() throws Exception {
    LOG.info("TearDown started");
    shutdownServers();

    for (String hp : hostPort.split(",")) {
      assertTrue(
          "waiting for server down",
          ClientBase.waitForServerDown(hp, ClientBase.CONNECTION_TIMEOUT));
      LOG.info(hp + " is no longer accepting client connections");
    }

    JMXEnv.tearDown();

    LOG.info("FINISHED " + getName());
  }
Пример #4
0
  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));
    }
  }
Пример #5
0
 @After
 public void tearDown() throws Exception {
   serverFactory.shutdown();
   Assert.assertTrue(
       "waiting for server down", ClientBase.waitForServerDown(HOSTPORT, CONNECTION_TIMEOUT));
 }