Examples of InMemoryZKServer


Examples of org.apache.twill.internal.zookeeper.InMemoryZKServer

  }

  // Test controller listener receive first state change without state transition from service
  @Test
  public void testControllerListener() throws InterruptedException {
    InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
    zkServer.startAndWait();

    LOG.info("ZKServer: " + zkServer.getConnectionStr());
    try {
      RunId runId = RunIds.generate();
      ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
      zkClientService.startAndWait();

      Service service = createService(zkClientService, runId);
      service.startAndWait();

      final CountDownLatch runLatch = new CountDownLatch(1);
      TwillController controller = getController(zkClientService, runId);
      controller.addListener(new ServiceListenerAdapter() {
        @Override
        public void running() {
          runLatch.countDown();
        }
      }, Threads.SAME_THREAD_EXECUTOR);

      Assert.assertTrue(runLatch.await(2, TimeUnit.SECONDS));

      service.stopAndWait();

      zkClientService.stopAndWait();
    } finally {
      zkServer.stopAndWait();
    }
  }
View Full Code Here

Examples of org.apache.twill.internal.zookeeper.InMemoryZKServer

  public static TemporaryFolder tmpFolder = new TemporaryFolder();

  @Test
  public void testClientServer() throws Exception {
    // Simply start a transaction server and connect to it with the client.
    InMemoryZKServer zkServer = InMemoryZKServer.builder().setDataDir(tmpFolder.newFolder()).build();
    zkServer.startAndWait();

    try {
      Configuration conf = HBaseConfiguration.create();
      conf.set(TxConstants.Service.CFG_DATA_TX_ZOOKEEPER_QUORUM, zkServer.getConnectionStr());
      conf.set(TxConstants.Manager.CFG_TX_SNAPSHOT_DIR, tmpFolder.newFolder().getAbsolutePath());

      final TransactionServiceMain main = new TransactionServiceMain(conf);
      Thread t = new Thread() {
        @Override
        public void run() {
          try {
            main.start();
          } catch (Exception e) {
            throw Throwables.propagate(e);
          }
        }
      };

      try {
        t.start();
        TransactionServiceClient.doMain(true, conf);
      } finally {
        main.stop();
        t.join();
      }
    } finally {
      zkServer.stopAndWait();
    }
  }
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.