@Override public TwillPreparer withArguments(String runnableName, String... args) { getDelegate().withArguments(runnableName, args); return this; }
@Override public TwillPreparer withArguments(String runnableName, String... args) { getDelegate().withArguments(runnableName, args); return this; }
@Override public TwillPreparer withArguments(String runnableName, Iterable<String> args) { getDelegate().withArguments(runnableName, args); return this; }
@Override public TwillPreparer withArguments(String runnableName, Iterable<String> args) { getDelegate().withArguments(runnableName, args); return this; }
.withArguments("BundledJarRunnable", arguments.toArray()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start();
@Test public void testEnv() throws Exception { TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new EchoApp()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("echo1", "echo1") .withArguments("echo2", "echo2") .withEnv(ImmutableMap.of("GREETING", "Hello")) .withEnv("echo2", ImmutableMap.of("GREETING", "Hello2")) .start(); // Service echo1 should returns "Hello" as greeting, echo2 should returns "Hello2" Map<String, String> runnableGreetings = ImmutableMap.of("echo1", "Hello", "echo2", "Hello2"); for (Map.Entry<String, String> entry : runnableGreetings.entrySet()) { Discoverable discoverable = getDiscoverable(controller.discoverService(entry.getKey()), 60, TimeUnit.SECONDS); try ( Socket socket = new Socket(discoverable.getSocketAddress().getAddress(), discoverable.getSocketAddress().getPort()) ) { 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("GREETING"); Assert.assertEquals(entry.getValue(), reader.readLine()); } } controller.terminate().get(); }
.withEnv(envVars) .withMaxRetries(YARN_RUNNABLE_NAME, MAX_APP_RESTART_RETRIES) .withArguments(YARN_RUNNABLE_NAME, discoveryArgs.toArray());
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("envecho") .withArguments("EnvironmentEchoServer", "echo2") .start();
.addJVMOptions(" -verbose:gc -Xloggc:gc.log -XX:+PrintGCDetails") .withApplicationArguments("local") .withArguments("LocalFileSocketServer", "local2") .withResources(footerFile.toURI()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
/** * Test to verify placement policy without dynamically changing number of instances. */ @Test public void testPlacementPolicy() throws Exception { // Ignore test if it is running against older Hadoop versions which does not support blacklists. Assume.assumeTrue(YarnUtils.getHadoopVersion().equals(YarnUtils.HadoopVersions.HADOOP_22)); waitNodeManagerCount(0, 10, TimeUnit.SECONDS); TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new PlacementPolicyApplication()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("PlacementPolicyTest") .withArguments("hostRunnable", "host") .withArguments("hostRackRunnable", "hostRack") .withArguments("distributedRunnable", "distributed") .start(); try { // All runnables should get started. ServiceDiscovered serviceDiscovered = controller.discoverService("PlacementPolicyTest"); Assert.assertTrue(waitForSize(serviceDiscovered, 4, 80)); // DISTRIBUTED runnables should be provisioned on different nodes. Assert.assertTrue(getProvisionedNodeManagerCount() >= 2); } finally { controller.terminate().get(120, TimeUnit.SECONDS); } // Sleep a bit before exiting. TimeUnit.SECONDS.sleep(2); }
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("BuggyServer", "echo2") .start();
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("DistributedTest") .withArguments("Alice", "alice") .withArguments("Bob", "bob") .withArguments("Eve", "eve") .start();
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("EchoServer", "echo2") .start(); .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("EchoServer", "echo2") .start());
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("DistributedTest") .withArguments("Alice", "alice") .withArguments("Bob", "bob") .withArguments("Eve", "eve") .start();
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("echo1", "echo1") .withArguments("echo2", "echo2") .start();
@Test public void testFailureRestart() throws Exception { TwillRunner runner = getTwillRunner(); ResourceSpecification resource = ResourceSpecification.Builder.with() .setVirtualCores(1) .setMemory(512, ResourceSpecification.SizeUnit.MEGA) .setInstances(2) .build(); TwillController controller = runner.prepare(new FailureRunnable(), resource) .withApplicationArguments("failure") .withArguments(FailureRunnable.class.getSimpleName(), "failure2") .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); Iterable<Discoverable> discoverables = controller.discoverService("failure"); Assert.assertTrue(waitForSize(discoverables, 2, 120)); // Make sure we see the right instance IDs Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables)); // Kill server with instanceId = 0 controller.sendCommand(FailureRunnable.class.getSimpleName(), Command.Builder.of("kill0").build()); // Make sure the runnable is killed. Assert.assertTrue(waitForSize(discoverables, 1, 120)); // Wait for the restart Assert.assertTrue(waitForSize(discoverables, 2, 120)); // Make sure we see the right instance IDs Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables)); controller.terminate().get(120, TimeUnit.SECONDS); }
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .withApplicationArguments("echo") .withArguments("EchoServer", "echo2") .start();