/** * Create a new shell, the returned shell should be closed explicitely. * @return the created shell */ public io.vertx.rxjava.ext.shell.Shell createShell() { io.vertx.rxjava.ext.shell.Shell ret = io.vertx.rxjava.ext.shell.Shell.newInstance(delegate.createShell()); return ret; }
/** * Create a new shell, the returned shell should be closed explicitely. * @return the created shell */ public io.vertx.rxjava.ext.shell.Shell createShell() { io.vertx.rxjava.ext.shell.Shell ret = io.vertx.rxjava.ext.shell.Shell.newInstance(delegate.createShell()); return ret; }
/** * Create a new shell, the returned shell should be closed explicitely. * @param term the shell associated terminal * @return the created shell */ public io.vertx.rxjava.ext.shell.Shell createShell(io.vertx.rxjava.ext.shell.term.Term term) { io.vertx.rxjava.ext.shell.Shell ret = io.vertx.rxjava.ext.shell.Shell.newInstance(delegate.createShell(term.getDelegate())); return ret; }
/** * Create a new shell, the returned shell should be closed explicitely. * @param term the shell associated terminal * @return the created shell */ public io.vertx.rxjava.ext.shell.Shell createShell(io.vertx.rxjava.ext.shell.term.Term term) { io.vertx.rxjava.ext.shell.Shell ret = io.vertx.rxjava.ext.shell.Shell.newInstance(delegate.createShell(term.getDelegate())); return ret; }
private void assertBusTail(TestContext context, String cmd, Runnable send, Predicate<String> check) { Async runningLatch = context.async(); Shell shell = server.createShell(); Pty pty = Pty.create(); StringBuffer result = new StringBuffer(); pty.stdoutHandler(result::append); Job job = shell.createJob(cmd).setTty(pty.slave()); job.statusUpdateHandler(status -> { if (status == ExecStatus.RUNNING) { runningLatch.complete(); } }); job.run(); runningLatch.awaitSuccess(10000); send.run(); long now = System.currentTimeMillis(); String output; while (!check.test(output = result.toString())) { context.assertTrue(System.currentTimeMillis() - now < 10000, "Invalid command output <" + output + ">"); } }
private String testDeployCmd(TestContext context, String cmd) { Async async = context.async(); Shell shell = server.createShell(); Pty pty = Pty.create(); StringBuffer result = new StringBuffer(); pty.stdoutHandler(result::append); Job job = shell.createJob(cmd) .setTty(pty.slave()); job.statusUpdateHandler(status -> { if (status == ExecStatus.TERMINATED) { async.complete(); } }); job.run(); async.awaitSuccess(5000); shell.close(); return result.toString().trim(); } }
private <T> String assertBusSend(TestContext context, String cmd, Handler<Message<T>> handler) { Async terminatedLatch = context.async(); vertx.eventBus().consumer("the_address", handler); Shell shell = server.createShell(); Pty pty = Pty.create(); StringBuffer result = new StringBuffer(); pty.stdoutHandler(result::append); Job job = shell.createJob(cmd).setTty(pty.slave()); job.statusUpdateHandler(status -> { if (status == ExecStatus.TERMINATED) { terminatedLatch.complete(); } }); job.run(); terminatedLatch.awaitSuccess(5000); return result.toString(); }
@Test public void testSendEvent(TestContext context) { CountDownLatch latch = new CountDownLatch(1); commands.add(CommandBuilder.command("foo").processHandler(process -> { process.suspendHandler(v -> { process.end(0); }); latch.countDown(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Async async = context.async(); Pty pty = Pty.create(); job.setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { async.complete(); })).run(); try { latch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { context.fail(e); } job.suspend(); }
@Test public void testThrowExceptionInProcess(TestContext context) { commands.add(CommandBuilder.command("foo").processHandler(process -> { throw new RuntimeException(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Async async = context.async(); Pty pty = Pty.create(); job.setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(code -> { context.assertEquals(1, job.process().exitCode()); async.complete(); })).run(); }
@Test public void testStdout(TestContext context) { commands.add(CommandBuilder.command("foo").processHandler(process -> { process.write("bye_world"); process.end(0); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Async async = context.async(); LinkedList<String> out = new LinkedList<>(); Pty pty = Pty.create(); pty.stdoutHandler(out::add); job.setTty(pty.slave()); job.statusUpdateHandler(CommandProcessTest.terminateHandler(code -> { context.assertEquals(0, job.process().exitCode()); context.assertEquals(Arrays.asList("bye_world"), out); async.complete(); })).run(); }
@Test public void testStdin(TestContext context) { CountDownLatch latch = new CountDownLatch(1); commands.add(CommandBuilder.command("foo").processHandler(process -> { process.stdinHandler(data -> { context.assertEquals("hello_world", data); process.end(0); }); latch.countDown(); })); Shell shell = server.createShell(); Job job = shell.createJob(CliToken.tokenize("foo")); Async async = context.async(); Pty pty = Pty.create(); job.setTty(pty.slave()); job.statusUpdateHandler(CommandProcessTest.terminateHandler(code -> { context.assertEquals(0, job.process().exitCode()); async.complete(); })).run(); try { latch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { context.fail(e); } pty.write("hello_world"); }
@Test public void testClose(TestContext context) { Async endLatch = context.async(2); Async runningLatch = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { process.endHandler(v -> endLatch.countDown()); runningLatch.countDown(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); job.setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { endLatch.countDown(); })).run(); runningLatch.awaitSuccess(10000); shell.close(); endLatch.awaitSuccess(10000); context.assertEquals(0, shell.jobController().jobs().size()); }
@Test public void testRun(TestContext context) { commands.add(CommandBuilder.command("foo").processHandler(process -> { process.end(3); })); Shell shell = server.createShell(); Job job = shell.createJob(CliToken.tokenize("foo")); Async async = context.async(); job.setTty(Pty.create().slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(code -> { context.assertEquals(3, job.process().exitCode()); async.complete(); })).run(); }
@Test public void testSessionGet(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertEquals("the_value", session.get("the_key")); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Session session = new SessionImpl(); session.put("the_key", "the_value"); Pty pty = Pty.create(); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); async.complete(); })).run(); }
@Test public void testSessionPut(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertNull(session.get("the_key")); session.put("the_key", "the_value"); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); Session session = new SessionImpl(); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); context.assertEquals("the_value", session.get("the_key")); async.complete(); })).run(); }
@Test public void testSessionRemove(TestContext context) throws Exception { Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { Session session = process.session(); context.assertNotNull(session); context.assertEquals("the_value", session.remove("the_key")); process.end(); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); Session session = new SessionImpl(); session.put("the_key", "the_value"); job.setSession(session).setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { context.assertEquals(0, job.process().exitCode()); context.assertNull(session.get("the_key")); async.complete(); })).run(); }
@Test public void testResize(TestContext context) { commands.add(CommandBuilder.command("foo").processHandler(process -> { context.assertEquals(20, process.width()); context.assertEquals(10, process.height()); process.resizehandler(v -> { context.assertEquals(25, process.width()); context.assertEquals(15, process.height()); process.end(0); }); process.write("ping"); })); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create(); Async async = context.async(); pty.setSize(20, 10); pty.stdoutHandler(text -> { pty.setSize(25, 15); }); job.setTty(pty.slave()).statusUpdateHandler(CommandProcessTest.terminateHandler(status -> { async.complete(); })).run(); }
shellCtx.runOnContext(v3 -> { testContext.assertTrue(shellCtx == Vertx.currentContext()); Shell shell = server.createShell(); Job job = shell.createJob("foo"); Pty pty = Pty.create();