当前位置: 首页>>代码示例>>Java>>正文


Java TwillController.addListener方法代码示例

本文整理汇总了Java中org.apache.twill.api.TwillController.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java TwillController.addListener方法的具体用法?Java TwillController.addListener怎么用?Java TwillController.addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.twill.api.TwillController的用法示例。


在下文中一共展示了TwillController.addListener方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDebugPortOneRunnable

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testDebugPortOneRunnable() throws Exception {
  YarnTwillRunnerService runner = (YarnTwillRunnerService) YarnTestUtils.getTwillRunner();
  runner.startAndWait();

  TwillController controller = runner.prepare(new DummyApplication())
                                     .enableDebugging("r1")
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                     .start();
  final CountDownLatch running = new CountDownLatch(1);
  controller.addListener(new ServiceListenerAdapter() {
    @Override
    public void running() {
      running.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));
  Assert.assertTrue(waitForDebugPort(controller, "r1", 30));
  controller.stop().get(120, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:24,代码来源:DebugTestRun.java

示例2: testDebugPortAllRunnables

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testDebugPortAllRunnables() throws Exception {
  YarnTwillRunnerService runner = (YarnTwillRunnerService) YarnTestUtils.getTwillRunner();
  runner.startAndWait();

  TwillController controller = runner.prepare(new DummyApplication())
                                     .enableDebugging()
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                     .start();
  final CountDownLatch running = new CountDownLatch(1);
  controller.addListener(new ServiceListenerAdapter() {
    @Override
    public void running() {
      running.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));
  Assert.assertTrue(waitForDebugPort(controller, "r1", 30));
  Assert.assertTrue(waitForDebugPort(controller, "r2", 30));
  controller.stop().get(120, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:25,代码来源:DebugTestRun.java

示例3: testTaskCompleted

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testTaskCompleted() throws InterruptedException {
  TwillRunner twillRunner = YarnTestUtils.getTwillRunner();
  TwillController controller = twillRunner.prepare(new SleepTask(),
                                              ResourceSpecification.Builder.with()
                                                .setVirtualCores(1)
                                                .setMemory(512, ResourceSpecification.SizeUnit.MEGA)
                                                .setInstances(3).build())
                                          .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                          .start();

  final CountDownLatch runLatch = new CountDownLatch(1);
  final CountDownLatch stopLatch = new CountDownLatch(1);
  controller.addListener(new ServiceListenerAdapter() {

    @Override
    public void running() {
      runLatch.countDown();
    }

    @Override
    public void terminated(Service.State from) {
      stopLatch.countDown();
    }
  }, Threads.SAME_THREAD_EXECUTOR);

  Assert.assertTrue(runLatch.await(1, TimeUnit.MINUTES));

  Assert.assertTrue(stopLatch.await(1, TimeUnit.MINUTES));

  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:33,代码来源:TaskCompletedTestRun.java

示例4: testAppSessionExpire

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testAppSessionExpire() throws InterruptedException, ExecutionException {
  TwillRunner runner = YarnTestUtils.getTwillRunner();
  TwillController controller = runner.prepare(new SleepRunnable(600))
                                     .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                     .start();

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

  // Wait for application running
  Assert.assertTrue(runLatch.await(60, TimeUnit.SECONDS));

  // Find the app master ZK session and expire it two times, 10 seconds apart.
  for (int i = 0; i < 2; i++) {
    Assert.assertTrue(expireAppMasterZKSession(controller, 10, TimeUnit.SECONDS));

    ListenableFuture<Service.State> completion = Services.getCompletionFuture(controller);
    try {
      completion.get(10, TimeUnit.SECONDS);
      Assert.fail("Unexpected application termination.");
    } catch (TimeoutException e) {
      // OK, expected.
    }
  }

  controller.stopAndWait();
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:34,代码来源:SessionExpireTestRun.java

示例5: testControllerBefore

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testControllerBefore() 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();

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

      @Override
      public void terminated(Service.State from) {
        stopLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

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

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

    service.stop();

    Assert.assertTrue(stopLatch.await(20000, TimeUnit.SECONDS));

  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:41,代码来源:ControllerTest.java

示例6: testControllerListener

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@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();
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:33,代码来源:ControllerTest.java

示例7: testRunnablesGetAllowedResourcesInEnv

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testRunnablesGetAllowedResourcesInEnv() throws InterruptedException, IOException,
  TimeoutException, ExecutionException {
  TwillRunner runner = YarnTestUtils.getTwillRunner();

  ResourceSpecification resourceSpec = ResourceSpecification.Builder.with()
    .setVirtualCores(1)
    .setMemory(2048, ResourceSpecification.SizeUnit.MEGA)
    .setInstances(1)
    .build();
  TwillController controller = runner.prepare(new EnvironmentEchoServer(), resourceSpec)
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .withApplicationArguments("envecho")
    .withArguments("EnvironmentEchoServer", "echo2")
    .start();

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

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));

  Iterable<Discoverable> envEchoServices = controller.discoverService("envecho");
  Assert.assertTrue(YarnTestUtils.waitForSize(envEchoServices, 1, 120));

  // TODO: check virtual cores once yarn adds the ability
  Map<String, String> expectedValues = Maps.newHashMap();
  expectedValues.put(EnvKeys.YARN_CONTAINER_MEMORY_MB, "2048");
  expectedValues.put(EnvKeys.TWILL_INSTANCE_COUNT, "1");

  // check environment of the runnable.
  Discoverable discoverable = envEchoServices.iterator().next();
  for (Map.Entry<String, String> expected : expectedValues.entrySet()) {
    Socket socket = new Socket(discoverable.getSocketAddress().getHostName(),
                               discoverable.getSocketAddress().getPort());
    try {
      PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
      LineReader reader = new LineReader(new InputStreamReader(socket.getInputStream(), Charsets.UTF_8));
      writer.println(expected.getKey());
      Assert.assertEquals(expected.getValue(), reader.readLine());
    } finally {
      socket.close();
    }
  }

  controller.stop().get(120, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:54,代码来源:ResourceReportTestRun.java

示例8: testResourceReportWithFailingContainers

import org.apache.twill.api.TwillController; //导入方法依赖的package包/类
@Test
public void testResourceReportWithFailingContainers() throws InterruptedException, IOException,
  TimeoutException, ExecutionException {
  TwillRunner runner = YarnTestUtils.getTwillRunner();

  ResourceSpecification resourceSpec = ResourceSpecification.Builder.with()
    .setVirtualCores(1)
    .setMemory(256, ResourceSpecification.SizeUnit.MEGA)
    .setInstances(2)
    .build();
  TwillController controller = runner.prepare(new BuggyServer(), resourceSpec)
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .withApplicationArguments("echo")
    .withArguments("BuggyServer", "echo2")
    .start();

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

  Assert.assertTrue(running.await(120, TimeUnit.SECONDS));

  Iterable<Discoverable> echoServices = controller.discoverService("echo");
  Assert.assertTrue(YarnTestUtils.waitForSize(echoServices, 2, 120));
  // check that we have 2 runnables.
  ResourceReport report = controller.getResourceReport();
  Assert.assertEquals(2, report.getRunnableResources("BuggyServer").size());

  // cause a divide by 0 in one server
  Discoverable discoverable = echoServices.iterator().next();
  Socket socket = new Socket(discoverable.getSocketAddress().getAddress(),
                             discoverable.getSocketAddress().getPort());
  try {
    PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), Charsets.UTF_8), true);
    writer.println("0");
  } finally {
    socket.close();
  }

  // takes some time for app master to find out the container completed...
  int count = 0;
  while (count < 100) {
    report = controller.getResourceReport();
    // check that we have 1 runnable, not 2.
    if (report.getRunnableResources("BuggyServer").size() == 1) {
      break;
    }
    LOG.info("Wait for BuggyServer to have 1 instance left. Trial {}.", count);
    count++;
    TimeUnit.SECONDS.sleep(1);
  }
  Assert.assertTrue("Still has 2 contains running after 100 seconds", count < 100);

  controller.stop().get(100, TimeUnit.SECONDS);
  // Sleep a bit before exiting.
  TimeUnit.SECONDS.sleep(2);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:62,代码来源:ResourceReportTestRun.java


注:本文中的org.apache.twill.api.TwillController.addListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。