Examples of MockServer


Examples of com.alibaba.wasp.util.MockServer

   * @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

Examples of com.alibaba.wasp.util.MockServer

    }
  }

  @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

Examples of com.alibaba.wasp.util.MockServer

        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

Examples of com.alibaba.wasp.util.MockServer

   * @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

Examples of com.alibaba.wasp.util.MockServer

   * @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

Examples of com.alibaba.wasp.util.MockServer

   * @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

Examples of com.alibaba.wasp.util.MockServer

      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

Examples of com.gatehill.apibms.core.model.MockServer

     * {@inheritDoc}
     */
    @Override
    public ExecutionInstance execute(File blueprintFile, MockFactory.BlueprintFormat format, String host, int port) throws ServiceException {
        final MockDefinition definition = mockFactory.createMock(blueprintFile, format);
        final MockServer server = serverService.start(definition, host, port);

        return new ExecutionInstance(server.getHost(), server.getPort(),
                definition.getEndpoints().toArray(new ResourceDefinition[definition.getEndpoints().size()]));
    }
View Full Code Here

Examples of net.sourceforge.cruisecontrol.gui.configuration.tree.util.MockServer

    String xml =
      "<cruisecontrol>" +
      "<project name='proj1'><schedule interval='100' /></project>" +
      "<project name='proj2'><schedule interval='200' /></project>" +
      "</cruisecontrol>";
    MockServer server;
    try {
      server = new MockServer(
          xml, rootInfo);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
   
    server.addProjectInfo("proj1", proj1Info);
    server.addProjectInfo("proj2", proj2Info);
   
    // Construct the ConfigTree to be tested.
    ConfigTree tree = new ConfigTree(server);
    TreeModel model = tree.getModel();
    RootNode root = (RootNode) model.getRoot();
View Full Code Here

Examples of nexj.core.rpc.MockServer

         + "\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><objects x" + "si:type=\"User\"><"
         + XML.BASE_PREFIX + "oid>10e8359492f25f4be49109b9979e684ff3</" + XML.BASE_PREFIX
         + "oid><" + XML.BASE_PREFIX + "event>welcome</" + XML.BASE_PREFIX
         + "event><fullName>fullname</fullName></objects><attributes>(password)</" + "attributes></Change-Request>");
      XMLChangeRequest changeRequest = (XMLChangeRequest)unmarshaller.deserialize(reader);
      MockServer server = new MockServer();

      changeRequest.invoke(server);

      Request request = server.getRequest();
      Request.Invocation action = request.getInvocation(0);

      assertEquals(1, request.getInvocationCount());
      assertNull(action.getEventName());
      assertEquals("User", request.getObject(0).getClassName());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.