ProcessModuleHandle extends NuAbstractProcessHandler implements ModuleHandle { @Override public Future<Void> start() { if (port == 0) { return start2(); } NetClientOptions options = new NetClientOptions().setConnectTimeout(200); NetClient c = vertx.createNetClient(options); return c.connect(port, "localhost").compose(socket -> { socket.close(); return Future.failedFuture(messages.getMessage("11502", Integer.toString(port))); }, fail -> start2()); } ProcessModuleHandle(Vertx vertx, LaunchDescriptor desc, String id,
                             Ports ports, int port); @Override Future<Void> start(); @Override void onStdout(ByteBuffer buffer, boolean closed); @Override void onStderr(ByteBuffer buffer, boolean closed); @Override void onExit(int code); @SuppressWarnings("indentation") @Override Future<Void> stop();  }
@Test public void testProgramNoListener(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); desc.setExec("java -version %p"); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertTrue(cause.getMessage().startsWith("Deployment failed. Could not connect to port 9231")) )); }
@Test public void testProgramDoesNotExist(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); desc.setExec("gyf 10 %p"); ModuleHandle mh = createModuleHandle(desc, 0); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("Could not execute gyf 10 0", cause.getMessage()) )); }
@Test public void testProgramReturnsError(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); desc.setExec("java -Dport=%p -jar unknown.jar"); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure()); }
@Test public void testNoExecNoCmdLineStart(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("Can not deploy: No exec, no CmdlineStart in LaunchDescriptor", cause.getMessage()) )); }
@Test public void testMissingPercentPexec(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); desc.setExec("java -Dport=9000 -jar unknown.jar"); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("Can not deploy: No %p in the exec line", cause.getMessage()) )); }
@Test public void testMissingPercentPcmdlineStart(TestContext context) { LaunchDescriptor desc = new LaunchDescriptor(); desc.setCmdlineStart("java -Dport=9000 -jar unknown.jar"); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("Can not deploy: No %p in the cmdlineStart", cause.getMessage()) )); }
@Test public void testCmdlineStartNoListener(TestContext context) { String os = System.getProperty("os.name").toLowerCase(); Assume.assumeFalse(os.contains("win")); LaunchDescriptor desc = new LaunchDescriptor(); desc.setCmdlineStart("echo %p; sleep 2"); desc.setCmdlineStop("gyf"); ModuleHandle mh = createModuleHandle(desc, 9231); mh.start().onComplete(context.asyncAssertFailure()); }
@Test public void testCmdlineStartNotFound(TestContext context) { String os = System.getProperty("os.name").toLowerCase(); Assume.assumeFalse(os.contains("win")); LaunchDescriptor desc = new LaunchDescriptor(); desc.setCmdlineStart("gyf %p"); desc.setCmdlineStop("gyf"); ModuleHandle mh = createModuleHandle(desc, 0); mh.start().onComplete(context.asyncAssertFailure(cause -> context.assertEquals("Could not execute gyf 0", cause.getMessage()) )); }