Package com.alibaba.wasp

Examples of com.alibaba.wasp.Server


   * @throws org.apache.zookeeper.KeeperException
   */
  @Test
  public void testYankingEntityGroupFromUnderIt() throws IOException,
      NodeExistsException, KeeperException {
    final Server server = new MockServer(WTU);
    final FServerServices rss = new MockFServerServices();

    FTable htd = TEST_FTD;
    final EntityGroupInfo egi = TEST_EGI;
    EntityGroup entityGroup = EntityGroup.createEntityGroup(egi,
        WTU.getConfiguration(), htd, rss);
    assertNotNull(entityGroup);
    try {
      OpenEntityGroupHandler handler = new OpenEntityGroupHandler(server, rss,
          egi, htd) {
        @Override
        EntityGroup openEntityGroup() {
          // Open entityGroup first, then remove znode as though it'd been
          // hijacked.
          EntityGroup entityGroup = super.openEntityGroup();

          // Don't actually open entityGroup BUT remove the znode as though it'd
          // been hijacked on us.
          ZooKeeperWatcher zkw = this.server.getZooKeeper();
          String node = ZKAssign.getNodeName(zkw, egi.getEncodedName());
          try {
            ZKUtil.deleteNodeFailSilent(zkw, node);
          } catch (KeeperException e) {
            throw new RuntimeException("Ugh failed delete of " + node, e);
          }
          return entityGroup;
        }
      };
      // Call process without first creating OFFLINE entityGroup in zk, see if
      // exception or just quiet return (expected).
      handler.process();
      ZKAssign.createNodeOffline(server.getZooKeeper(), egi,
          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 {
      EntityGroup.closeEntityGroup(entityGroup);
View Full Code Here


    }
  }

  @Test
  public void testFailedOpenEntityGroup() throws Exception {
    Server server = new MockServer(WTU);
    FServerServices rsServices = new MockFServerServices();

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

    // Create the handler
    OpenEntityGroupHandler handler = new OpenEntityGroupHandler(server,
        rsServices, TEST_EGI, TEST_FTD) {
      @Override
      EntityGroup openEntityGroup() {
        // Fake failure of opening a entityGroup due to an IOE, which is caught
        return null;
      }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign
        .getData(server.getZooKeeper(), TEST_EGI.getEncodedName()));
    assertEquals(EventType.FSERVER_ZK_ENTITYGROUP_FAILED_OPEN,
        rt.getEventType());
  }
View Full Code Here

        rt.getEventType());
  }

  @Test
  public void testFailedUpdateMeta() throws Exception {
    Server server = new MockServer(WTU);
    FServerServices rsServices = new MockFServerServices();

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

    // Create the handler
    OpenEntityGroupHandler handler = new OpenEntityGroupHandler(server,
        rsServices, TEST_EGI, TEST_FTD) {
      @Override
      boolean updateMeta(final EntityGroup e) {
        // Fake failure of updating META
        return false;
      }
    };
    handler.process();

    // Handler should have transitioned it to FAILED_OPEN
    EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign
        .getData(server.getZooKeeper(), TEST_EGI.getEncodedName()));
    assertEquals(EventType.FSERVER_ZK_ENTITYGROUP_FAILED_OPEN,
        rt.getEventType());
  }
View Full Code Here

   * @throws org.apache.zookeeper.KeeperException
   */
  @Test
  public void testFailedCommitAborts() throws IOException, NodeExistsException,
      KeeperException {
    final Server server = new MockServer(WTU, false);
    final FServerServices rss = new MockFServerServices();
    FTable wtd = TEST_FTD;
    final EntityGroupInfo egi = new EntityGroupInfo(wtd.getTableName(),
        FConstants.EMPTY_END_ROW, FConstants.EMPTY_END_ROW);
    EntityGroup entityGroup = EntityGroup.createEntityGroup(egi,
        WTU.getConfiguration(), wtd, rss);
    try {
      assertNotNull(entityGroup);
      // Spy on the entityGroup so can throw exception when close is called.
      EntityGroup spy = Mockito.spy(entityGroup);
      final boolean abort = false;
      Mockito.when(spy.close(abort)).thenThrow(
          new RuntimeException("Mocked failed close!"));
      rss.addToOnlineEntityGroups(spy);
      assertFalse(server.isStopped());
      CloseEntityGroupHandler handler = new CloseEntityGroupHandler(server,
          rss, egi, false, false, -1, EventType.M_FSERVER_CLOSE_ENTITYGROUP);
      boolean throwable = false;
      try {
        handler.process();
      } catch (Throwable t) {
        throwable = true;
      } finally {
        assertTrue(throwable);
        // Abort calls stop so stopped flag should be set.
        assertTrue(server.isStopped());
      }
    } finally {
      EntityGroup.closeEntityGroup(entityGroup);
    }
  }
View Full Code Here

   * @throws com.alibaba.wasp.DeserializationException
   */
  @Test
  public void testZKClosingNodeVersionMismatch() throws IOException,
      NodeExistsException, KeeperException, DeserializationException {
    final Server server = new MockServer(WTU);
    final MockFServerServices rss = new MockFServerServices();

    FTable ftd = TEST_FTD;
    final EntityGroupInfo egi = TEST_EGI;

    // open a entityGroup first so that it can be closed later
    openEntityGroup(server, rss, ftd, egi);

    int versionOfClosingNode = ZKAssign.createNodeClosing(
        server.getZooKeeper(), egi, server.getServerName());

    CloseEntityGroupHandler handler = new CloseEntityGroupHandler(server, rss,
        egi, false, true, versionOfClosingNode + 1,
        EventType.M_FSERVER_CLOSE_ENTITYGROUP);
    handler.process();

    EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign
        .getData(server.getZooKeeper(), egi.getEncodedName()));
    assertTrue(rt.getEventType().equals(EventType.M_ZK_ENTITYGROUP_CLOSING));
  }
View Full Code Here

   * @throws com.alibaba.wasp.DeserializationException
   */
  @Test
  public void testCloseEntityGroup() throws IOException, NodeExistsException,
      KeeperException, DeserializationException {
    final Server server = new MockServer(WTU);
    final MockFServerServices rss = new MockFServerServices();
    FTable htd = TEST_FTD;
    EntityGroupInfo egi = TEST_EGI;
    openEntityGroup(server, rss, htd, egi);
    int versionOfClosingNode = ZKAssign.createNodeClosing(
        server.getZooKeeper(), egi, server.getServerName());
    CloseEntityGroupHandler handler = new CloseEntityGroupHandler(server, rss,
        egi, false, true, versionOfClosingNode,
        EventType.M_FSERVER_CLOSE_ENTITYGROUP);
    handler.process();
    EntityGroupTransaction rt = EntityGroupTransaction.parseFrom(ZKAssign
        .getData(server.getZooKeeper(), egi.getEncodedName()));
    assertTrue(rt.getEventType()
        .equals(EventType.FSERVER_ZK_ENTITYGROUP_CLOSED));
  }
View Full Code Here

  public void testWholesomeSplit() throws IOException {
    // Start transaction.
    SplitTransaction st = prepareGOOD_SPLIT_ROW();

    // Run the execute. Look at what it returns.
    Server mockServer = Mockito.mock(Server.class);
    when(mockServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration());
    PairOfSameType<EntityGroup> daughters = st.execute(mockServer, null);
    // Do some assertions about execution.
    assertTrue(this.parent.isClosed());

    // Check daughters have correct key span.
View Full Code Here

    when(
        spiedUponSt.createDaughterEntityGroup(spiedUponSt.getSecondDaughter(),
            null)).thenThrow(new MockedFailedDaughterCreation());
    // Run the execute. Look at what it returns.
    boolean expectedException = false;
    Server mockServer = Mockito.mock(Server.class);
    when(mockServer.getConfiguration()).thenReturn(TEST_UTIL.getConfiguration());
    try {
      spiedUponSt.execute(mockServer, null);
    } catch (MockedFailedDaughterCreation e) {
      expectedException = true;
    }
View Full Code Here

      TEST_UTIL.getHBaseTestingUtility().startMiniZKCluster();
      TEST_UTIL.getConfiguration().set(FConstants.ZOOKEEPER_QUORUM,
          TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_QUORUM));
      TEST_UTIL.getConfiguration().set(FConstants.ZOOKEEPER_CLIENT_PORT,
          TEST_UTIL.getConfiguration().get(HConstants.ZOOKEEPER_CLIENT_PORT));
      final Server server = new MockServer(TEST_UTIL);
      FTable htd = FMetaTestUtil
          .makeTable("testShouldNotCompeleteOpenedEntityGroupSuccessfullyIfVersionMismatches");
      EntityGroupInfo egi = new EntityGroupInfo(Bytes.toBytes(htd
          .getTableName()), Bytes.toBytes(testIndex),
          Bytes.toBytes(testIndex + 1));
      entityGroup = EntityGroup.createEntityGroup(egi,
          TEST_UTIL.getConfiguration(), htd, null);
      assertNotNull(entityGroup);
      AssignmentManager am = Mockito.mock(AssignmentManager.class);
      EntityGroupStates rsm = Mockito.mock(EntityGroupStates.class);
      Mockito.doReturn(rsm).when(am).getEntityGroupStates();
      when(rsm.isEntityGroupInTransition(egi)).thenReturn(false);
      when(rsm.getEntityGroupState(egi)).thenReturn(
          new EntityGroupState(entityGroup.getEntityGroupInfo(),
              EntityGroupState.State.OPEN, System.currentTimeMillis(), server
                  .getServerName()));
      // create a node with OPENED state
      zkw = WaspTestingUtility.createAndForceNodeToOpenedState(TEST_UTIL,
          entityGroup, server.getServerName());
      when(am.getZKTable()).thenReturn(new ZKTable(zkw));
      Stat stat = new Stat();
      String nodeName = ZKAssign.getNodeName(zkw, entityGroup
          .getEntityGroupInfo().getEncodedName());
      ZKUtil.getDataAndWatch(zkw, nodeName, stat);

      // use the version for the OpenedEntityGroupHandler
      OpenedEntityGroupHandler handler = new OpenedEntityGroupHandler(server,
          am, entityGroup.getEntityGroupInfo(), server.getServerName(),
          stat.getVersion());
      // Once again overwrite the same znode so that the version changes.
      ZKAssign.transitionNode(zkw, entityGroup.getEntityGroupInfo(),
          server.getServerName(), EventType.FSERVER_ZK_ENTITYGROUP_OPENED,
          EventType.FSERVER_ZK_ENTITYGROUP_OPENED, stat.getVersion());

      // Should not invoke assignmentmanager.entityGroupOnline. If it is
      // invoked as per current mocking it will throw null pointer exception.
      boolean expectedException = false;
View Full Code Here

  public void testExecutorService() throws Exception {
    int maxThreads = 5;
    int maxTries = 10;
    int sleepInterval = 10;

    Server mockedServer = mock(Server.class);
    when(mockedServer.getConfiguration()).thenReturn(conf);

    // Start an executor service pool with max 5 threads
    ExecutorService executorService = new ExecutorService("unit_test");
    executorService.startExecutorService(
      ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads);
View Full Code Here

TOP

Related Classes of com.alibaba.wasp.Server

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.