AtomicInteger ai = new AtomicInteger(0); server.shellHandler(shell -> { shell.setPrompt(s -> { try { return "C: " + ai.incrementAndGet();
/** * See {@link io.vertx.rxjava.ext.shell.Shell#createJob} * @param line * @return */ public io.vertx.rxjava.ext.shell.system.Job createJob(String line) { io.vertx.rxjava.ext.shell.system.Job ret = io.vertx.rxjava.ext.shell.system.Job.newInstance(delegate.createJob(line)); return ret; }
@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()); }
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(); } }
/** * Close the shell. */ public void close() { delegate.close(); }
/** * @return the shell's job controller */ public io.vertx.rxjava.ext.shell.system.JobController jobController() { if (cached_0 != null) { return cached_0; } io.vertx.rxjava.ext.shell.system.JobController ret = io.vertx.rxjava.ext.shell.system.JobController.newInstance(delegate.jobController()); cached_0 = ret; return ret; }
/** * @return the current shell session */ public io.vertx.rxjava.ext.shell.session.Session session() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.shell.session.Session ret = io.vertx.rxjava.ext.shell.session.Session.newInstance(delegate.session()); cached_1 = ret; return ret; }
/** * See {@link io.vertx.rxjava.ext.shell.Shell#createJob} * @param line * @return */ public io.vertx.rxjava.ext.shell.system.Job createJob(String line) { io.vertx.rxjava.ext.shell.system.Job ret = io.vertx.rxjava.ext.shell.system.Job.newInstance(delegate.createJob(line)); return ret; }
/** * Close the shell. */ public void close() { delegate.close(); }
/** * @return the shell's job controller */ public io.vertx.rxjava.ext.shell.system.JobController jobController() { if (cached_0 != null) { return cached_0; } io.vertx.rxjava.ext.shell.system.JobController ret = io.vertx.rxjava.ext.shell.system.JobController.newInstance(delegate.jobController()); cached_0 = ret; return ret; }
/** * @return the current shell session */ public io.vertx.rxjava.ext.shell.session.Session session() { if (cached_1 != null) { return cached_1; } io.vertx.rxjava.ext.shell.session.Session ret = io.vertx.rxjava.ext.shell.session.Session.newInstance(delegate.session()); cached_1 = ret; return ret; }
/** * Create a job, the created job should then be executed with the {@link io.vertx.rxjava.ext.shell.system.Job#run} method. * @param line the command line creating this job * @return the created job */ public io.vertx.rxjava.ext.shell.system.Job createJob(List<io.vertx.rxjava.ext.shell.cli.CliToken> line) { io.vertx.rxjava.ext.shell.system.Job ret = io.vertx.rxjava.ext.shell.system.Job.newInstance(delegate.createJob(line.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList()))); return ret; }
/** * Set a new prompt in this session. * @param prompt the new prompt will be calculated when it's needed. */ public void setPrompt(Function<io.vertx.rxjava.ext.shell.session.Session, String> prompt) { delegate.setPrompt(new java.util.function.Function<io.vertx.ext.shell.session.Session,java.lang.String>() { public java.lang.String apply(io.vertx.ext.shell.session.Session arg) { String ret = prompt.apply(io.vertx.rxjava.ext.shell.session.Session.newInstance(arg)); return ret; } }); }
/** * Create a job, the created job should then be executed with the {@link io.vertx.rxjava.ext.shell.system.Job#run} method. * @param line the command line creating this job * @return the created job */ public io.vertx.rxjava.ext.shell.system.Job createJob(List<io.vertx.rxjava.ext.shell.cli.CliToken> line) { io.vertx.rxjava.ext.shell.system.Job ret = io.vertx.rxjava.ext.shell.system.Job.newInstance(delegate.createJob(line.stream().map(elt -> elt.getDelegate()).collect(java.util.stream.Collectors.toList()))); return ret; }
/** * Set a new prompt in this session. * @param prompt the new prompt will be calculated when it's needed. */ public void setPrompt(Function<io.vertx.rxjava.ext.shell.session.Session, String> prompt) { delegate.setPrompt(new java.util.function.Function<io.vertx.ext.shell.session.Session,java.lang.String>() { public java.lang.String apply(io.vertx.ext.shell.session.Session arg) { String ret = prompt.apply(io.vertx.rxjava.ext.shell.session.Session.newInstance(arg)); 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 + ">"); } }
@Test public void testPrompt(TestContext context) { commands = new TestCommands(vertx); ShellServer server = ShellServer.create(vertx, new ShellServerOptions() .setWelcomeMessage("") .setSessionTimeout(100) .setReaperInterval(100)); server.shellHandler(shell -> shell.setPrompt(s -> "FOOPROMPT")); TestTermServer termServer = new TestTermServer(vertx); server.registerTermServer(termServer); server. registerCommandResolver(CommandResolver.baseCommands(vertx)). registerCommandResolver(commands). listen(context.asyncAssertSuccess()); TestTtyConnection conn = termServer.openConnection(); Async async = context.async(); commands.add(CommandBuilder.command("foo").processHandler(process -> { context.assertEquals(null, conn.checkWritten("FOOPROMPTfoo\n")); process.stdinHandler(cp -> { context.fail(); }); process.endHandler(v -> { async.complete(); } ); process.end(); })); conn.read("foo\r"); async.awaitSuccess(5000); }
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(); }