Package com.alibaba.wasp.zookeeper

Examples of com.alibaba.wasp.zookeeper.ZooKeeperWatcher


   */
  public static ZooKeeperWatcher createAndForceNodeToOpenedState(
      WaspTestingUtility TEST_UTIL, EntityGroup entityGroup,
      ServerName serverName) throws ZooKeeperConnectionException, IOException,
      KeeperException, NodeExistsException {
    ZooKeeperWatcher zkw = getZooKeeperWatcher(TEST_UTIL);
    ZKAssign.createNodeOffline(zkw, entityGroup.getEntityGroupInfo(),
        serverName);
    int version = ZKAssign.transitionNodeOpening(zkw,
        entityGroup.getEntityGroupInfo(), serverName);
    ZKAssign.transitionNodeOpened(zkw, entityGroup.getEntityGroupInfo(),
View Full Code Here


   * @param TEST_UTIL
   */
  public static ZooKeeperWatcher getZooKeeperWatcher(
      WaspTestingUtility TEST_UTIL) throws ZooKeeperConnectionException,
      IOException {
    ZooKeeperWatcher zkw = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
        "unittest", new Abortable() {
          boolean aborted = false;

          @Override
          public void abort(String why, Throwable e) {
View Full Code Here

   * @throws java.io.IOException
   */
  public MockServer(final WaspTestingUtility htu, final boolean zkw)
      throws ZooKeeperConnectionException, IOException {
    this.htu = htu;
    this.zk = zkw ? new ZooKeeperWatcher(htu.getConfiguration(),
        NAME.toString(), this, true) : null;
  }
View Full Code Here

    Mockito.when(server.getConfiguration()).thenReturn(HTU.getConfiguration());
    HTU.getConfiguration().set(FConstants.ZOOKEEPER_QUORUM,
        HTU.getConfiguration().get(HConstants.ZOOKEEPER_QUORUM));
    HTU.getConfiguration().set(FConstants.ZOOKEEPER_CLIENT_PORT,
        HTU.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT));
    this.watcher = new ZooKeeperWatcher(HTU.getConfiguration(), "mockedServer",
        this.server, true);
    Mockito.when(server.getZooKeeper()).thenReturn(this.watcher);
    Mockito.doThrow(new RuntimeException("Aborted")).when(server)
        .abort(Mockito.anyString(), (Throwable) Mockito.anyObject());
View Full Code Here

    TEST_UTIL.getHBaseTestingUtility().shutdownMiniZKCluster();
  }

  @Test
  public void testRestartMaster() throws IOException, KeeperException {
    ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
        "testActiveMasterManagerFromZK", null, true);
    try {
      ZKUtil.deleteNode(zk, zk.getMasterAddressZNode());
      ZKUtil.deleteNode(zk, zk.clusterStateZNode);
    } catch (KeeperException.NoNodeException nne) {
    }

    // Create the master node with a dummy address
View Full Code Here

   * rather acts directly on ZK.
   * @throws Exception
   */
  @Test
  public void testActiveMasterManagerFromZK() throws Exception {
    ZooKeeperWatcher zk = new ZooKeeperWatcher(TEST_UTIL.getConfiguration(),
        "testActiveMasterManagerFromZK", null, true);
    try {
      ZKUtil.deleteNode(zk, zk.getMasterAddressZNode());
      ZKUtil.deleteNode(zk, zk.clusterStateZNode);
    } catch (KeeperException.NoNodeException nne) {
    }

    // Create the master node with a dummy address
    ServerName firstMasterAddress = new ServerName("localhost", 1,
        System.currentTimeMillis());
    ServerName secondMasterAddress = new ServerName("localhost", 2,
        System.currentTimeMillis());

    // Should not have a master yet
    DummyMaster ms1 = new DummyMaster(zk, firstMasterAddress);
    ActiveMasterManager activeMasterManager = ms1.getActiveMasterManager();
    assertFalse(activeMasterManager.clusterHasActiveMaster.get());

    // First test becoming the active master uninterrupted
    ClusterStatusTracker clusterStatusTracker = ms1.getClusterStatusTracker();
    clusterStatusTracker.setClusterUp();
    activeMasterManager.blockUntilBecomingActiveMaster(
        Mockito.mock(MonitoredTask.class), clusterStatusTracker);
    assertTrue(activeMasterManager.clusterHasActiveMaster.get());
    assertMaster(zk, firstMasterAddress);

    // New manager will now try to become the active master in another thread
    WaitToBeMasterThread t = new WaitToBeMasterThread(zk, secondMasterAddress);
    t.start();
    // Wait for this guy to figure out there is another active master
    // Wait for 1 second at most
    int sleeps = 0;
    while (!t.manager.clusterHasActiveMaster.get() && sleeps < 100) {
      Thread.sleep(10);
      sleeps++;
    }

    // Both should see that there is an active master
    assertTrue(activeMasterManager.clusterHasActiveMaster.get());
    assertTrue(t.manager.clusterHasActiveMaster.get());
    // But secondary one should not be the active master
    assertFalse(t.isActiveMaster);

    // Close the first server and delete it's master node
    ms1.stop("stopping first server");

    // Use a listener to capture when the node is actually deleted
    NodeDeletionListener listener = new NodeDeletionListener(zk,
        zk.getMasterAddressZNode());
    zk.registerListener(listener);

    LOG.info("Deleting master node");
    ZKUtil.deleteNode(zk, zk.getMasterAddressZNode());

    // Wait for the node to be deleted
    LOG.info("Waiting for active master manager to be notified");
    listener.waitForDeletion();
    LOG.info("Master node deleted");

    // Now we expect the secondary manager to have and be the active master
    // Wait for 1 second at most
    sleeps = 0;
    while (!t.isActiveMaster && sleeps < 100) {
      Thread.sleep(10);
      sleeps++;
    }
    LOG.debug("Slept " + sleeps + " times");

    assertTrue(t.manager.clusterHasActiveMaster.get());
    assertTrue(t.isActiveMaster);

    LOG.info("Deleting master node");
    ZKUtil.deleteNode(zk, zk.getMasterAddressZNode());
  }
View Full Code Here

    return fserver.getClusterId();
  }

  @Override
  public String getZookeeperQuorum() {
    ZooKeeperWatcher zk = fserver.getZooKeeper();
    if (zk == null) {
      return "";
    }
    return zk.getQuorum();
  }
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.zookeeper.ZooKeeperWatcher

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.