Package org.apache.twill.api

Examples of org.apache.twill.api.TwillController


      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);
View Full Code Here


      }
    });
  }

  private TwillController getController(ZKClient zkClient, RunId runId) {
    TwillController controller = new AbstractTwillController(runId, zkClient, ImmutableList.<LogHandler>of()) {

      @Override
      public void kill() {
        // No-op
      }

      @Override
      protected void instanceNodeUpdated(NodeData nodeData) {
        // No-op
      }

      @Override
      protected void instanceNodeFailed(Throwable cause) {
        // Shutdown if the instance node goes away
        if (cause instanceof KeeperException.NoNodeException) {
          forceShutDown();
        }
      }

      @Override
      protected void stateNodeUpdated(StateNode stateNode) {
        // No-op
      }

      @Override
      public ResourceReport getResourceReport() {
        return null;
      }
    };
    controller.startAndWait();
    return controller;
  }
View Full Code Here

  private static final Logger LOG = LoggerFactory.getLogger(SessionExpireTestRun.class);

  @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();
  }
View Full Code Here

        }
      }
    };

    TwillRunner runner = YarnTestUtils.getTwillRunner();
    TwillController controller = runner.prepare(new LogRunnable())
                                       .addLogHandler(logHandler)
                                       .start();

    Services.getCompletionFuture(controller).get();
    latch.await(1, TimeUnit.SECONDS);
View Full Code Here

  }

  @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();
      }
View Full Code Here

public final class ServiceDiscoveryTest extends BaseYarnTest {

  @Test
  public void testServiceDiscovery() throws InterruptedException, ExecutionException, TimeoutException {
    TwillRunner twillRunner = YarnTestUtils.getTwillRunner();
    TwillController controller = twillRunner
      .prepare(new ServiceApplication())
      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
      .withArguments("r1", "12345")
      .withArguments("r2", "45678")
      .start();

    ListenableFuture<Service.State> completion = Services.getCompletionFuture(controller);
    try {
      completion.get(60, TimeUnit.SECONDS);
    } finally {
      controller.stopAndWait();
    }
  }
View Full Code Here

public class InitializeFailTestRun extends BaseYarnTest {

  @Test
  public void testInitFail() throws InterruptedException, ExecutionException, TimeoutException {
    TwillRunner runner = YarnTestUtils.getTwillRunner();
    TwillController controller = runner.prepare(new InitFailRunnable())
                                       .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                       .start();

    Services.getCompletionFuture(controller).get(2, TimeUnit.MINUTES);
  }
View Full Code Here

  @Ignore
  @Test
  public void testDistributedShell() throws InterruptedException {
    TwillRunner twillRunner = YarnTestUtils.getTwillRunner();

    TwillController controller = twillRunner.prepare(new DistributedShell("pwd", "ls -al"))
                                            .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
                                            .start();

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

      @Override
      public void terminated(Service.State from) {
        stopLatch.countDown();
      }
View Full Code Here

  @Test
  public void testProvisionTimeout() throws InterruptedException, ExecutionException, TimeoutException {
    TwillRunner runner = YarnTestUtils.getTwillRunner();

    TwillController controller = runner.prepare(new TimeoutApplication())
                                       .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                       .start();

    // The provision should failed in 30 seconds after AM started, which AM could took a while to start.
    // Hence we give 90 seconds max time here.
    try {
      Services.getCompletionFuture(controller).get(90, TimeUnit.SECONDS);
    } finally {
      // If it timeout, kill the app as cleanup.
      controller.kill();
    }
  }
View Full Code Here

      YarnTwillRunnerService yarnRunner = (YarnTwillRunnerService) runner;
      prevJVMOptions = yarnRunner.getJVMOptions() != null ? yarnRunner.getJVMOptions() : "";
      yarnRunner.setJVMOptions(prevJVMOptions + " -verbose:gc -Xloggc:gc.log -XX:+PrintGCDetails");
    }

    TwillController controller = runner.prepare(new LocalFileApplication())
      .withApplicationArguments("local")
      .withArguments("LocalFileSocketServer", "local2")
      .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
      .start();

    if (runner instanceof YarnTwillRunnerService) {
      ((YarnTwillRunnerService) runner).setJVMOptions(prevJVMOptions);
    }

    Iterable<Discoverable> discoverables = controller.discoverService("local");
    Assert.assertTrue(YarnTestUtils.waitForSize(discoverables, 1, 60));

    InetSocketAddress socketAddress = discoverables.iterator().next().getSocketAddress();
    Socket socket = new Socket(socketAddress.getAddress(), socketAddress.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));

      String msg = "Local file test";
      writer.println(msg);
      Assert.assertEquals(header, reader.readLine());
      Assert.assertEquals(msg, reader.readLine());
    } finally {
      socket.close();
    }

    controller.stopAndWait();

    Assert.assertTrue(YarnTestUtils.waitForSize(discoverables, 0, 60));

    TimeUnit.SECONDS.sleep(2);
  }
View Full Code Here

TOP

Related Classes of org.apache.twill.api.TwillController

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.