Package org.apache.hadoop.hbase.util

Examples of org.apache.hadoop.hbase.util.MockServer


   * @throws NodeExistsException
   * @throws KeeperException
   */
  @Test public void testYankingRegionFromUnderIt()
  throws IOException, NodeExistsException, KeeperException {
    final Server server = new MockServer(HTU);
    final RegionServerServices rss = new MockRegionServerServices();

    HTableDescriptor htd = TEST_HTD;
    final HRegionInfo hri = TEST_HRI;
    HRegion region =
         HRegion.createHRegion(hri, HTU.getDataTestDir(), HTU
            .getConfiguration(), htd);
    assertNotNull(region);
    try {
      OpenRegionHandler handler = new OpenRegionHandler(server, rss, hri, htd) {
        HRegion openRegion() {
          // Open region first, then remove znode as though it'd been hijacked.
          HRegion region = super.openRegion();

          // Don't actually open region BUT remove the znode as though it'd
          // been hijacked on us.
          ZooKeeperWatcher zkw = this.server.getZooKeeper();
          String node = ZKAssign.getNodeName(zkw, hri.getEncodedName());
          try {
            ZKUtil.deleteNodeFailSilent(zkw, node);
          } catch (KeeperException e) {
            throw new RuntimeException("Ugh failed delete of " + node, e);
          }
          return region;
        }
      };
      // Call process without first creating OFFLINE region in zk, see if
      // exception or just quiet return (expected).
      handler.process();
      ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
      // Call process again but this time yank the zk znode out from under it
      // post OPENING; again will expect it to come back w/o NPE or exception.
      handler.process();
    } finally {
      HRegion.closeHRegion(region);
View Full Code Here


    }
  }
 
  @Test
  public void testFailedOpenRegion() throws Exception {
    Server server = new MockServer(HTU);
    RegionServerServices rsServices = new MockRegionServerServices();

    // Create it OFFLINE, which is what it expects
    ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

    // Create the handler
    OpenRegionHandler handler =
      new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD) {
        @Override
        HRegion openRegion() {
          // Fake failure of opening a region due to an IOE, which is caught
          return null;
        }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    RegionTransitionData data =
      ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName());
    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
View Full Code Here

    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
 
  @Test
  public void testFailedUpdateMeta() throws Exception {
    Server server = new MockServer(HTU);
    RegionServerServices rsServices = new MockRegionServerServices();

    // Create it OFFLINE, which is what it expects
    ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server.getServerName());

    // Create the handler
    OpenRegionHandler handler =
      new OpenRegionHandler(server, rsServices, TEST_HRI, TEST_HTD) {
        @Override
        boolean updateMeta(final HRegion r) {
          // Fake failure of updating META
          return false;
        }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    RegionTransitionData data =
      ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName());
    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
View Full Code Here

  @Test
  public void testShouldNotCompeleteOpenedRegionSuccessfullyIfVersionMismatches()
      throws Exception {
    try {
      TEST_UTIL.startMiniZKCluster();
      final Server server = new MockServer();
      HTableDescriptor htd = new HTableDescriptor(
          "testShouldNotCompeleteOpenedRegionSuccessfullyIfVersionMismatches");
      final HRegionInfo hri = new HRegionInfo(htd, HConstants.EMPTY_END_ROW,
          HConstants.EMPTY_END_ROW);
      HRegion region = HRegion.createHRegion(hri, HBaseTestingUtility
          .getTestDir(), server.getConfiguration());
      assertNotNull(region);
      AssignmentManager am = Mockito.mock(AssignmentManager.class);
      when(am.isRegionInTransition(hri)).thenReturn(
          new RegionState(region.getRegionInfo(), RegionState.State.OPEN,
              System.currentTimeMillis()));
      // create a node with OPENED state
      zkw = HBaseTestingUtility.createAndForceNodeToOpenedState(TEST_UTIL,
          region, server.getServerName());
      when(am.getZKTable()).thenReturn(new ZKTable(zkw));
      Stat stat = new Stat();
      String nodeName = ZKAssign.getNodeName(zkw, hri.getEncodedName());
      ZKUtil.getDataAndWatch(zkw, nodeName, stat);
      // use the version for the OpenedRegionHandler
      OpenedRegionHandler handler = new OpenedRegionHandler(server, am, region
          .getRegionInfo(), new HServerInfo(new HServerAddress(
          new InetSocketAddress(1111)), 0, ""), stat.getVersion());

      // Once again overwrite the same znode so that the version changes.
      ZKAssign.transitionNode(zkw, region.getRegionInfo(), server
          .getServerName(), EventType.RS_ZK_REGION_OPENED,
          EventType.RS_ZK_REGION_OPENED, stat.getVersion());

      // Should not invoke assignmentmanager.regionOnline. If it is invoked as
      // per current mocking it will throw null pointer exception.
View Full Code Here

   * @throws NodeExistsException
   * @throws KeeperException
   */
  @Test public void testOpenRegionHandlerYankingRegionFromUnderIt()
  throws IOException, NodeExistsException, KeeperException {
    final Server server = new MockServer();
    final RegionServerServices rss = new MockRegionServerServices();

    HTableDescriptor htd =
      new HTableDescriptor("testOpenRegionHandlerYankingRegionFromUnderIt");
    final HRegionInfo hri =
      new HRegionInfo(htd, HConstants.EMPTY_END_ROW, HConstants.EMPTY_END_ROW);
    OpenRegionHandler handler = new OpenRegionHandler(server, rss, hri) {
      HRegion openRegion() {
        // Open region first, then remove znode as though it'd been hijacked.
        HRegion region = super.openRegion();
        // Don't actually open region BUT remove the znode as though it'd
        // been hijacked on us.
        ZooKeeperWatcher zkw = this.server.getZooKeeper();
        String node = ZKAssign.getNodeName(zkw, hri.getEncodedName());
        try {
          ZKUtil.deleteNodeFailSilent(zkw, node);
        } catch (KeeperException e) {
          throw new RuntimeException("Ugh failed delete of " + node, e);
        }
        return region;
      }
    };
    // Call process without first creating OFFLINE region in zk, see if
    // exception or just quiet return (expected).
    handler.process();
    ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
    // Call process again but this time yank the zk znode out from under it
    // post OPENING; again will expect it to come back w/o NPE or exception.
    handler.process();
  }
View Full Code Here

   * @throws NodeExistsException
   * @throws KeeperException
   */
  @Test public void testOpenRegionHandlerYankingRegionFromUnderIt()
  throws IOException, NodeExistsException, KeeperException {
    final Server server = new MockServer();
    final RegionServerServices rss = new MockRegionServerServices();

    HTableDescriptor htd =
      new HTableDescriptor("testOpenRegionHandlerYankingRegionFromUnderIt");
    final HRegionInfo hri =
      new HRegionInfo(htd, HConstants.EMPTY_END_ROW, HConstants.EMPTY_END_ROW);
    OpenRegionHandler handler = new OpenRegionHandler(server, rss, hri) {
      HRegion openRegion() {
        // Open region first, then remove znode as though it'd been hijacked.
        HRegion region = super.openRegion();
        // Don't actually open region BUT remove the znode as though it'd
        // been hijacked on us.
        ZooKeeperWatcher zkw = this.server.getZooKeeper();
        String node = ZKAssign.getNodeName(zkw, hri.getEncodedName());
        try {
          ZKUtil.deleteNodeFailSilent(zkw, node);
        } catch (KeeperException e) {
          throw new RuntimeException("Ugh failed delete of " + node, e);
        }
        return region;
      }
    };
    // Call process without first creating OFFLINE region in zk, see if
    // exception or just quiet return (expected).
    handler.process();
    ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
    // Call process again but this time yank the zk znode out from under it
    // post OPENING; again will expect it to come back w/o NPE or exception.
    handler.process();
  }
View Full Code Here

    // post OPENING; again will expect it to come back w/o NPE or exception.
    handler.process();
  }
  @Test
  public void testFailedOpenRegion() throws Exception {
    Server server = new MockServer();
    RegionServerServices rsServices = new MockRegionServerServices();

    // Create it OFFLINE, which is what it expects
    ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server
        .getServerName());

    // Create the handler
    OpenRegionHandler handler =
      new OpenRegionHandler(server, rsServices, TEST_HRI) {
        @Override
        HRegion openRegion() {
          // Fake failure of opening a region due to an IOE, which is caught
          return null;
        }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    RegionTransitionData data =
      ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName());
    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
View Full Code Here

    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
 
  @Test
  public void testFailedUpdateMeta() throws Exception {
    Server server = new MockServer();
    RegionServerServices rsServices = new MockRegionServerServices();

    // Create it OFFLINE, which is what it expects
    ZKAssign.createNodeOffline(server.getZooKeeper(), TEST_HRI, server
        .getServerName());

    // Create the handler
    OpenRegionHandler handler =
      new OpenRegionHandler(server, rsServices, TEST_HRI) {
        @Override
        boolean updateMeta(final HRegion r) {
          // Fake failure of updating META
          return false;
        }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    RegionTransitionData data =
      ZKAssign.getData(server.getZooKeeper(), TEST_HRI.getEncodedName());
    assertEquals(EventType.RS_ZK_REGION_FAILED_OPEN, data.getEventType());
  }
View Full Code Here

   * @throws NodeExistsException
   * @throws KeeperException
   */
  @Test public void testYankingRegionFromUnderIt()
  throws IOException, NodeExistsException, KeeperException {
    final Server server = new MockServer(HTU);
    final RegionServerServices rss = HTU.createMockRegionServerService();

    HTableDescriptor htd = TEST_HTD;
    final HRegionInfo hri = TEST_HRI;
    HRegion region =
         HRegion.createHRegion(hri, HTU.getDataTestDir(), HTU
            .getConfiguration(), htd);
    assertNotNull(region);
    try {
      OpenRegionHandler handler = new OpenRegionHandler(server, rss, hri, htd) {
        HRegion openRegion() {
          // Open region first, then remove znode as though it'd been hijacked.
          HRegion region = super.openRegion();

          // Don't actually open region BUT remove the znode as though it'd
          // been hijacked on us.
          ZooKeeperWatcher zkw = this.server.getZooKeeper();
          String node = ZKAssign.getNodeName(zkw, hri.getEncodedName());
          try {
            ZKUtil.deleteNodeFailSilent(zkw, node);
          } catch (KeeperException e) {
            throw new RuntimeException("Ugh failed delete of " + node, e);
          }
          return region;
        }
      };
      rss.getRegionsInTransitionInRS().put(
        hri.getEncodedNameAsBytes(), Boolean.TRUE);
      // Call process without first creating OFFLINE region in zk, see if
      // exception or just quiet return (expected).
      handler.process();
      rss.getRegionsInTransitionInRS().put(
        hri.getEncodedNameAsBytes(), Boolean.TRUE);
      ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
      // Call process again but this time yank the zk znode out from under it
      // post OPENING; again will expect it to come back w/o NPE or exception.
      handler.process();
    } finally {
      HRegion.closeHRegion(region);
View Full Code Here

   * @throws KeeperException
   */
  @Test
  public void testRegionServerAbortionDueToFailureTransitioningToOpened()
      throws IOException, NodeExistsException, KeeperException {
    final Server server = new MockServer(HTU);
    final RegionServerServices rss = HTU.createMockRegionServerService();

    HTableDescriptor htd = TEST_HTD;
    final HRegionInfo hri = TEST_HRI;
    HRegion region =
         HRegion.createHRegion(hri, HTU.getDataTestDir(), HTU
            .getConfiguration(), htd);
    assertNotNull(region);
    try {
      OpenRegionHandler handler = new OpenRegionHandler(server, rss, hri, htd) {
        boolean transitionToOpened(final HRegion r) throws IOException {
          // remove znode simulating intermittent zookeeper connection issue
          ZooKeeperWatcher zkw = this.server.getZooKeeper();
          String node = ZKAssign.getNodeName(zkw, hri.getEncodedName());
          try {
            ZKUtil.deleteNodeFailSilent(zkw, node);
          } catch (KeeperException e) {
            throw new RuntimeException("Ugh failed delete of " + node, e);
          }
          // then try to transition to OPENED
          return super.transitionToOpened(r);
        }
      };
      rss.getRegionsInTransitionInRS().put(
        hri.getEncodedNameAsBytes(), Boolean.TRUE);
      // Call process without first creating OFFLINE region in zk, see if
      // exception or just quiet return (expected).
      handler.process();
      rss.getRegionsInTransitionInRS().put(
        hri.getEncodedNameAsBytes(), Boolean.TRUE);
      ZKAssign.createNodeOffline(server.getZooKeeper(), hri, server.getServerName());
      // Call process again but this time yank the zk znode out from under it
      // post OPENING; again will expect it to come back w/o NPE or exception.
      handler.process();
    } catch (IOException ioe) {
    } finally {
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.util.MockServer

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.