Package org.apache.hadoop.ha.MiniZKFCCluster

Examples of org.apache.hadoop.ha.MiniZKFCCluster.DummyZKFC


 
  @Test
  public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
    DummyHAService svc = cluster.getService(1);

    DummyZKFC zkfcInOtherCluster = new DummyZKFC(conf, cluster.getService(1)) {
      @Override
      protected String getScopeInsideParentNode() {
        return "other-scope";
      }
    };
   
    // Run without formatting the base dir,
    // should barf
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        runFC(svc));

    // Format the base dir, should succeed
    assertEquals(0, runFC(svc, "-formatZK"));
   
    // Run the other cluster without formatting, should barf because
    // it uses a different parent znode
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        zkfcInOtherCluster.run(new String[]{}));
   
    // Should succeed in formatting the second cluster
    assertEquals(0, zkfcInOtherCluster.run(new String[]{"-formatZK"}));

    // But should not have deleted the original base node from the first
    // cluster
    assertEquals(ZKFailoverController.ERR_CODE_FORMAT_DENIED,
        runFC(svc, "-formatZK", "-nonInteractive"));
View Full Code Here


   */
  @Test(timeout=15000)
  public void testCedeActive() throws Exception {
    try {
      cluster.start();
      DummyZKFC zkfc = cluster.getZkfc(0);
      // It should be in active to start.
      assertEquals(ActiveStandbyElector.State.ACTIVE,
          zkfc.getElectorForTests().getStateForTests());

      // Ask it to cede active for 3 seconds. It should respond promptly
      // (i.e. the RPC itself should not take 3 seconds!)
      ZKFCProtocol proxy = zkfc.getLocalTarget().getZKFCProxy(conf, 5000);
      long st = Time.now();
      proxy.cedeActive(3000);
      long et = Time.now();
      assertTrue("RPC to cedeActive took " + (et - st) + " ms",
          et - st < 1000);
     
      // Should be in "INIT" state since it's not in the election
      // at this point.
      assertEquals(ActiveStandbyElector.State.INIT,
          zkfc.getElectorForTests().getStateForTests());

      // After the prescribed 3 seconds, should go into STANDBY state,
      // since the other node in the cluster would have taken ACTIVE.
      cluster.waitForElectorState(0, ActiveStandbyElector.State.STANDBY);
      long et2 = Time.now();
View Full Code Here

      cluster.stop();
    }
  }

  private int runFC(DummyHAService target, String ... args) throws Exception {
    DummyZKFC zkfc = new DummyZKFC(conf, target);
    return zkfc.run(args);
  }
View Full Code Here

 
  @Test
  public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
    DummyHAService svc = cluster.getService(1);

    DummyZKFC zkfcInOtherCluster = new DummyZKFC(conf, cluster.getService(1)) {
      @Override
      protected String getScopeInsideParentNode() {
        return "other-scope";
      }
    };
   
    // Run without formatting the base dir,
    // should barf
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        runFC(svc));

    // Format the base dir, should succeed
    assertEquals(0, runFC(svc, "-formatZK"));
   
    // Run the other cluster without formatting, should barf because
    // it uses a different parent znode
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        zkfcInOtherCluster.run(new String[]{}));
   
    // Should succeed in formatting the second cluster
    assertEquals(0, zkfcInOtherCluster.run(new String[]{"-formatZK"}));

    // But should not have deleted the original base node from the first
    // cluster
    assertEquals(ZKFailoverController.ERR_CODE_FORMAT_DENIED,
        runFC(svc, "-formatZK", "-nonInteractive"));
View Full Code Here

   */
  @Test(timeout=15000)
  public void testCedeActive() throws Exception {
    try {
      cluster.start();
      DummyZKFC zkfc = cluster.getZkfc(0);
      // It should be in active to start.
      assertEquals(ActiveStandbyElector.State.ACTIVE,
          zkfc.getElectorForTests().getStateForTests());

      // Ask it to cede active for 3 seconds. It should respond promptly
      // (i.e. the RPC itself should not take 3 seconds!)
      ZKFCProtocol proxy = zkfc.getLocalTarget().getZKFCProxy(conf, 5000);
      long st = Time.now();
      proxy.cedeActive(3000);
      long et = Time.now();
      assertTrue("RPC to cedeActive took " + (et - st) + " ms",
          et - st < 1000);
     
      // Should be in "INIT" state since it's not in the election
      // at this point.
      assertEquals(ActiveStandbyElector.State.INIT,
          zkfc.getElectorForTests().getStateForTests());

      // After the prescribed 3 seconds, should go into STANDBY state,
      // since the other node in the cluster would have taken ACTIVE.
      cluster.waitForElectorState(0, ActiveStandbyElector.State.STANDBY);
      long et2 = Time.now();
View Full Code Here

      cluster.stop();
    }
  }

  private int runFC(DummyHAService target, String ... args) throws Exception {
    DummyZKFC zkfc = new DummyZKFC(conf, target);
    return zkfc.run(args);
  }
View Full Code Here

 
  @Test
  public void testFormatOneClusterLeavesOtherClustersAlone() throws Exception {
    DummyHAService svc = cluster.getService(1);

    DummyZKFC zkfcInOtherCluster = new DummyZKFC(conf, cluster.getService(1)) {
      @Override
      protected String getScopeInsideParentNode() {
        return "other-scope";
      }
    };
   
    // Run without formatting the base dir,
    // should barf
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        runFC(svc));

    // Format the base dir, should succeed
    assertEquals(0, runFC(svc, "-formatZK"));
   
    // Run the other cluster without formatting, should barf because
    // it uses a different parent znode
    assertEquals(ZKFailoverController.ERR_CODE_NO_PARENT_ZNODE,
        zkfcInOtherCluster.run(new String[]{}));
   
    // Should succeed in formatting the second cluster
    assertEquals(0, zkfcInOtherCluster.run(new String[]{"-formatZK"}));

    // But should not have deleted the original base node from the first
    // cluster
    assertEquals(ZKFailoverController.ERR_CODE_FORMAT_DENIED,
        runFC(svc, "-formatZK", "-nonInteractive"));
View Full Code Here

   */
  @Test(timeout=15000)
  public void testCedeActive() throws Exception {
    try {
      cluster.start();
      DummyZKFC zkfc = cluster.getZkfc(0);
      // It should be in active to start.
      assertEquals(ActiveStandbyElector.State.ACTIVE,
          zkfc.getElectorForTests().getStateForTests());

      // Ask it to cede active for 3 seconds. It should respond promptly
      // (i.e. the RPC itself should not take 3 seconds!)
      ZKFCProtocol proxy = zkfc.getLocalTarget().getZKFCProxy(conf, 5000);
      long st = Time.now();
      proxy.cedeActive(3000);
      long et = Time.now();
      assertTrue("RPC to cedeActive took " + (et - st) + " ms",
          et - st < 1000);
     
      // Should be in "INIT" state since it's not in the election
      // at this point.
      assertEquals(ActiveStandbyElector.State.INIT,
          zkfc.getElectorForTests().getStateForTests());

      // After the prescribed 3 seconds, should go into STANDBY state,
      // since the other node in the cluster would have taken ACTIVE.
      cluster.waitForElectorState(0, ActiveStandbyElector.State.STANDBY);
      long et2 = Time.now();
View Full Code Here

      cluster.stop();
    }
  }

  private int runFC(DummyHAService target, String ... args) throws Exception {
    DummyZKFC zkfc = new DummyZKFC(conf, target);
    return zkfc.run(args);
  }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.ha.MiniZKFCCluster.DummyZKFC

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.