Examples of TwillRunner


Examples of org.apache.twill.api.TwillRunner

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

Examples of org.apache.twill.api.TwillRunner

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

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

    TwillController controller = runner.prepare(new EchoServer(),
                                                ResourceSpecification.Builder.with()
                                                         .setVirtualCores(1)
                                                         .setMemory(1, ResourceSpecification.SizeUnit.GIGA)
                                                         .setInstances(2)
                                                         .build())
                                        .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
                                        .withApplicationArguments("echo")
                                        .withArguments("EchoServer", "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(30, TimeUnit.SECONDS));

    Iterable<Discoverable> echoServices = controller.discoverService("echo");
    Assert.assertTrue(YarnTestUtils.waitForSize(echoServices, 2, 60));

    for (Discoverable discoverable : echoServices) {
      String msg = "Hello: " + discoverable.getSocketAddress();

      Socket socket = new Socket(discoverable.getSocketAddress().getAddress(),
                                 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(msg);
        Assert.assertEquals(msg, reader.readLine());
      } finally {
        socket.close();
      }
    }

    // Increase number of instances
    controller.changeInstances("EchoServer", 3);
    Assert.assertTrue(YarnTestUtils.waitForSize(echoServices, 3, 60));

    echoServices = controller.discoverService("echo2");

    // Decrease number of instances
    controller.changeInstances("EchoServer", 1);
    Assert.assertTrue(YarnTestUtils.waitForSize(echoServices, 1, 60));

    // Increase number of instances again
    controller.changeInstances("EchoServer", 2);
    Assert.assertTrue(YarnTestUtils.waitForSize(echoServices, 2, 60));

    // Make sure still only one app is running
    Iterable<TwillRunner.LiveInfo> apps = runner.lookupLive();
    Assert.assertTrue(YarnTestUtils.waitForSize(apps, 1, 60));

    // Creates a new runner service to check it can regain control over running app.
    TwillRunnerService runnerService = YarnTestUtils.createTwillRunnerService(tmpFolder.newFolder());
    runnerService.startAndWait();
View Full Code Here

Examples of org.apache.twill.api.TwillRunner

          latch.countDown();
        }
      }
    };

    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

Examples of org.apache.twill.api.TwillRunner

    }
  }

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

Examples of org.apache.twill.api.TwillRunner

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

Examples of org.apache.twill.api.TwillRunner

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

Examples of org.apache.twill.api.TwillRunner

public final class DistributeShellTestRun extends BaseYarnTest {

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

Examples of org.apache.twill.api.TwillRunner

*/
public final class ProvisionTimeoutTestRun extends BaseYarnTest {

  @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.
View Full Code Here

Examples of org.apache.twill.api.TwillRunner

  @Test
  public void testLocalFile() throws Exception {
    String header = Files.readFirstLine(new File(getClass().getClassLoader().getResource("header.txt").toURI()),
                                        Charsets.UTF_8);

    TwillRunner runner = YarnTestUtils.getTwillRunner();
    String prevJVMOptions = "";
    if (runner instanceof YarnTwillRunnerService) {
      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();
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.