Package com.xiaomi.infra.chronos.zookeeper

Examples of com.xiaomi.infra.chronos.zookeeper.HostPort


    TEST_UTIL.shutdownMiniZKCluster();
  }

  @Before
  public void resetZooKeeper() throws IOException, KeeperException {
    FailoverWatcher failoverWatcher = createFailoverWatcher(new HostPort("127.0.0.1", 10086));
    ZooKeeperUtil.deleteNodeRecursively(failoverWatcher, failoverWatcher.getBaseZnode());
    failoverWatcher.close();
  }
View Full Code Here


    return new FailoverWatcher(properties);
  }

  @Test
  public void testInitZnode() throws IOException, KeeperException {
    FailoverWatcher failoverWatcher = createFailoverWatcher(new HostPort("127.0.0.1", 10086));

    assertTrue(ZooKeeperUtil.watchAndCheckExists(failoverWatcher, failoverWatcher.getBaseZnode()));
    assertTrue(ZooKeeperUtil.watchAndCheckExists(failoverWatcher,
      failoverWatcher.getBackupServersZnode()));
View Full Code Here

  }

  @Test
  public void testBlockUntilActive() throws IOException, KeeperException, InterruptedException {
    // the first server, expect to be active master
    HostPort hostPort1 = new HostPort("127.0.0.1", 11111);
    FailoverWatcher failoverWatcher1 = createFailoverWatcher(hostPort1);
    failoverWatcher1.blockUntilActive();

    assertTrue(failoverWatcher1.hasActiveServer());
    String activeServer = new String(ZooKeeperUtil.getDataAndWatch(failoverWatcher1,
      failoverWatcher1.masterZnode));
    assertTrue(activeServer.equals(hostPort1.getHostPort()));

    // the second server, expect to be backup master
    HostPort hostPort2 = new HostPort("127.0.0.1", 22222);
    final FailoverWatcher failoverWatcher2 = createFailoverWatcher(hostPort2);
    Thread thread2 = new Thread() {
      @Override
      public void run() {
        failoverWatcher2.blockUntilActive();
View Full Code Here

  }

  @Test
  public void testRestartActiveMaster() throws IOException, KeeperException {
    // the first server, expect to be active master
    HostPort hostPort1 = new HostPort("127.0.0.1", 11111);
    FailoverWatcher failoverWatcher1 = createFailoverWatcher(hostPort1);
    failoverWatcher1.blockUntilActive();

    assertTrue(failoverWatcher1.hasActiveServer());
    String activeServer = new String(ZooKeeperUtil.getDataAndWatch(failoverWatcher1,
      failoverWatcher1.masterZnode));
    assertTrue(activeServer.equals(hostPort1.getHostPort()));

    // the same server start, expect to restart active master
    FailoverWatcher failoverWatcher2 = createFailoverWatcher(hostPort1);
    failoverWatcher2.blockUntilActive();
    assertTrue(failoverWatcher2.hasActiveServer());
    String activeServer2 = new String(ZooKeeperUtil.getDataAndWatch(failoverWatcher1,
      failoverWatcher1.masterZnode));
    assertTrue(activeServer2.equals(hostPort1.getHostPort()));

    failoverWatcher1.close();
    failoverWatcher2.close();
  }
View Full Code Here

  }

  @Test
  public void testHandleMasterNodeChange() throws IOException, KeeperException,
      InterruptedException {
    HostPort hostPort1 = new HostPort("127.0.0.1", 11111);
    FailoverWatcher failoverWatcher1 = createFailoverWatcher(hostPort1);
    failoverWatcher1.blockUntilActive();

    // hostPort2 is backup master
    HostPort hostPort2 = new HostPort("127.0.0.1", 22222);
    final FailoverWatcher failoverWatcher2 = createFailoverWatcher(hostPort2);
    Thread thread2 = new Thread() {
      @Override
      public void run() {
        failoverWatcher2.blockUntilActive();
      }
    };
    thread2.start();

    // hostPort3 is backup master
    HostPort hostPort3 = new HostPort("127.0.0.1", 33333);
    final FailoverWatcher failoverWatcher3 = createFailoverWatcher(hostPort3);
    Thread thread3 = new Thread() {
      @Override
      public void run() {
        failoverWatcher3.blockUntilActive();
      }
    };
    thread3.start();

    // delete the master node, then one of them will become master, the other will be backup master
    ZooKeeperUtil.deleteNode(failoverWatcher1, failoverWatcher1.masterZnode);
    Thread.sleep(500); // wait for leader election
    String masterZnodeData = new String(ZooKeeperUtil.getDataAndWatch(failoverWatcher1,
      failoverWatcher1.masterZnode));
    String backupMasterNode = ZooKeeperUtil.listChildrenAndWatchForNewChildren(failoverWatcher1,
      failoverWatcher1.backupServersZnode).get(0);

    if (masterZnodeData.equals(hostPort2.getHostPort())) {
      if (!backupMasterNode.equals(hostPort3.getHostPort())) {
        assert false;
      }
    } else if (masterZnodeData.equals(hostPort3.getHostPort())) {
      if (!backupMasterNode.equals(hostPort2.getHostPort())) {
        assert false;
      }
    } else {
      assert false;
View Full Code Here

    failoverWatcher2.close();
  }

  @Test
  public void testCloseMaster() throws KeeperException, IOException {
    HostPort hostPort1 = new HostPort("127.0.0.1", 11111);
    FailoverWatcher failoverWatcher1 = createFailoverWatcher(hostPort1);
    failoverWatcher1.blockUntilActive();

    HostPort hostPort2 = new HostPort("127.0.0.1", 22222);
    final FailoverWatcher failoverWatcher2 = createFailoverWatcher(hostPort2);
    Thread thread2 = new Thread() {
      @Override
      public void run() {
        failoverWatcher2.blockUntilActive();
View Full Code Here

    failoverWatcher2.close();
  }

  @Test
  public void testCloseBackupMaster() throws IOException, KeeperException, InterruptedException {
    HostPort hostPort1 = new HostPort("127.0.0.1", 11111);
    FailoverWatcher failoverWatcher1 = createFailoverWatcher(hostPort1);
    failoverWatcher1.blockUntilActive();

    HostPort hostPort2 = new HostPort("127.0.0.1", 22222);
    final FailoverWatcher failoverWatcher2 = createFailoverWatcher(hostPort2);
    Thread thread2 = new Thread() {
      @Override
      public void run() {
        failoverWatcher2.blockUntilActive();
      }
    };
    thread2.start();

    Thread.sleep(500); // wait for backup master to init
    thread2.interrupt(); // close backup master and failoverWatcher1 is still active master
    ZooKeeperUtil.deleteNode(failoverWatcher1, failoverWatcher1.getBackupServersZnode() + "/"
        + hostPort2.getHostPort());

    String masterZnodeData = new String(ZooKeeperUtil.getDataAndWatch(failoverWatcher1,
      failoverWatcher1.masterZnode));
    List<String> backupMasterList = ZooKeeperUtil.listChildrenAndWatchForNewChildren(
      failoverWatcher1, failoverWatcher1.backupServersZnode);
View Full Code Here

  }

  @Before
  public void resetZooKeeper() throws IOException, KeeperException, TTransportException,
      ChronosException {
    ChronosServer chronosServer = createChronosServer(new HostPort("127.0.0.1", 10086));
    ZooKeeperUtil.deleteNodeRecursively(chronosServer.getFailoverWatcher(), chronosServer
        .getFailoverWatcher().getBaseZnode());
    chronosServer.getFailoverWatcher().close();
  }
View Full Code Here

    return new ChronosServer(new ChronosServerWatcher(properties));
  }

  @Test
  public void testDoAsActiveServer() throws TException, IOException, ChronosException {
    final ChronosServer chronosServer = createChronosServer(new HostPort("127.0.0.1", 2187));
    Thread thread = new Thread() {
      @Override
      public void run() {
        chronosServer.doAsActiveServer();
      }
View Full Code Here

  }

  @Before
  public void resetZooKeeper() throws IOException, KeeperException, FatalChronosException,
      ChronosException {
    ChronosImplement chronosImplement = createChronosImplement(new HostPort("127.0.0.1", 10086));
    ZooKeeperUtil.deleteNodeRecursively(chronosImplement.getChronosServerWatcher(),
      chronosImplement.getChronosServerWatcher().getBaseZnode());
    chronosImplement.getChronosServerWatcher().close();
  }
View Full Code Here

TOP

Related Classes of com.xiaomi.infra.chronos.zookeeper.HostPort

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.