/** * Utility method to execute a specific command. * * @param cmd the command * @param args the arguments */ public static void executeCommand(String cmd, String... args) { new Launcher().execute(cmd, args); }
/** * Main entry point. * * @param args the user command line arguments. */ public static void main(String[] args) { new Launcher().dispatch(args); }
@Test public void testRunVerticleWithMainVerticleInManifestWithCustomCommand() throws Exception { // Copy the right manifest File manifest = new File("target/test-classes/META-INF/MANIFEST-Launcher-hello.MF"); if (!manifest.isFile()) { throw new IllegalStateException("Cannot find the MANIFEST-Launcher-hello.MF file"); } File target = new File("target/test-classes/META-INF/MANIFEST.MF"); Files.copy(manifest.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); Launcher launcher = new Launcher(); HelloCommand.called = false; String[] args = {"--name=vert.x"}; launcher.dispatch(args); assertWaitUntil(() -> HelloCommand.called); }
@Test public void testRunVerticleWithoutMainVerticleInManifestButWithCustomCommand() throws Exception { // Copy the right manifest File manifest = new File("target/test-classes/META-INF/MANIFEST-Launcher-Default-Command.MF"); if (!manifest.isFile()) { throw new IllegalStateException("Cannot find the MANIFEST-Default-Command.MF file"); } File target = new File("target/test-classes/META-INF/MANIFEST.MF"); Files.copy(manifest.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); Launcher launcher = new Launcher(); HelloCommand.called = false; String[] args = {"--name=vert.x"}; launcher.dispatch(args); assertWaitUntil(() -> HelloCommand.called); }
@Test public void testRunWithOverriddenDefaultCommandRequiringArgs() throws Exception { // Copy the right manifest File manifest = new File("target/test-classes/META-INF/MANIFEST-Launcher-run.MF"); if (!manifest.isFile()) { throw new IllegalStateException("Cannot find the MANIFEST-Launcher-run.MF file"); } File target = new File("target/test-classes/META-INF/MANIFEST.MF"); Files.copy(manifest.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); String[] args = {TestVerticle.class.getName()}; Launcher launcher = new Launcher(); launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); cleanup(launcher); }
@Test public void testRunWithOverriddenDefaultCommand() throws Exception { // Copy the right manifest File manifest = new File("target/test-classes/META-INF/MANIFEST-Launcher-hello.MF"); if (!manifest.isFile()) { throw new IllegalStateException("Cannot find the MANIFEST-Launcher-hello.MF file"); } File target = new File("target/test-classes/META-INF/MANIFEST.MF"); Files.copy(manifest.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); HelloCommand.called = false; String[] args = {"run", TestVerticle.class.getName(), "--name=vert.x"}; Launcher launcher = new Launcher(); launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 1); cleanup(launcher); }
@Test public void testRunVerticleWithMainVerticleInManifestWithArgs() throws Exception { // Copy the right manifest File manifest = new File("target/test-classes/META-INF/MANIFEST-Launcher.MF"); if (!manifest.isFile()) { throw new IllegalStateException("Cannot find the MANIFEST-Launcher.MF file"); } File target = new File("target/test-classes/META-INF/MANIFEST.MF"); Files.copy(manifest.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING); Launcher launcher = new Launcher(); String[] args = {"-cluster", "-worker", "-instances=10"}; launcher.dispatch(args); assertWaitUntil(() -> TestVerticle.instanceCount.get() == 10); assertEquals(Arrays.asList(args), TestVerticle.processArgs); cleanup(launcher); }
@Test public void testFatJarWithoutMainVerticle() throws IOException { setManifest("MANIFEST-Launcher-No-Main-Verticle.MF"); record(); cli.dispatch(new Launcher(), new String[0]); stop(); assertThat(output.toString()).contains("Usage:"); }
@Test public void testStartingApplicationInRedeployMode() { cli.dispatch(new Launcher(), new String[]{"run", HttpTestVerticle.class.getName(), "--redeploy=**" + File.separator + "*.txt", "--launcher-class=" + Launcher.class.getName() }); assertWaitUntil(() -> { try { return RunCommandTest.getHttpCode() == 200; } catch (IOException e) { return false; } }); }
@Test public void testDeploymentOfJavaVerticleWithCluster() throws IOException { cli.dispatch(new Launcher(), new String[] {"run", HttpTestVerticle.class.getName(), "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testDeploymentOfJavaVerticle() { cli.dispatch(new Launcher(), new String[] {"run", HttpTestVerticle.class.getName()}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); }
@Test public void testFatJarWithMissingMainVerticle() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Missing-Main-Verticle.MF"); record(); cli.dispatch(new Launcher(), new String[]{}); assertWaitUntil(() -> error.toString().contains("ClassNotFoundException")); stop(); }
@Test public void testWithConfProvidedInline() throws IOException { long someNumber = new Random().nextLong(); setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"--conf={\"random\":" + someNumber + "}"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").getLong("random")).isEqualTo(someNumber); }
@Test public void testThatHADeploysVerticle() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-ha", "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testFatJarWithHTTPVerticle() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[]{}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isFalse(); }
@Test public void testThatHADeploysVerticleWhenCombinedWithCluster() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-ha", "-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testFatJarWithHTTPVerticleWithCluster() throws IOException, InterruptedException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[]{"-cluster"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getBoolean("clustered")).isTrue(); }
@Test public void testWithConfProvidedAsFile() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"--conf", "target/test-classes/conf.json"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").getString("name")).isEqualToIgnoringCase("vertx"); }
@Test public void testMetricsEnabledFromCommandLine() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); cli.dispatch(new Launcher(), new String[] {"-Dvertx.metrics.options.enabled=true"}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); // Check that the metrics are enabled // We cannot use the response from the verticle as it uses the DymmyVertxMetrics (no metrics provider) assertThat(((RunCommand)cli.getExistingCommandInstance("run")).options.getMetricsOptions().isEnabled()).isTrue(); }
@Test public void testWithBrokenConfProvidedInline() throws IOException { setManifest("MANIFEST-Launcher-Http-Verticle.MF"); // There is a missing `}` in the json fragment. This is normal, as the test check that the configuration is not // read in this case. cli.dispatch(new Launcher(), new String[] {"--conf={\"name\":\"vertx\""}); assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); assertThat(getContent().getJsonObject("conf").toString()).isEqualToIgnoringCase("{}"); }