@Test public void testCPInBareCommand() { bare = new BareCommand(); bare.setExecutionContext(new ExecutionContext(bare, null, null)); bare.setClasspath("." + File.pathSeparator + "target/externals"); bare.setQuorum(1); bare.run(); assertWaitUntil(() -> bare.vertx != null); // Do reproduce the verticle fail-over, set the TCCL final ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(bare.createClassloader()); bare.vertx.deployVerticle(VERTICLE, new DeploymentOptions().setHa(true)); } finally { Thread.currentThread().setContextClassLoader(originalClassloader); } assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); }
/** * Registers a shutdown hook closing the given vert.x instance when the JVM is terminating. * Optionally, an action can be executed after the termination of the {@link Vertx} instance. * * @param vertx the vert.x instance, must not be {@code null} * @param log the log, must not be {@code null} * @param action the action, may be {@code null} */ protected static void addShutdownHook(Vertx vertx, Logger log, Runnable action) { Runtime.getRuntime().addShutdownHook(new Thread(getTerminationRunnable(vertx, log, action))); }
JsonObject optionsJson = getJsonFromFileOrString(vertxOptions, "options"); if (optionsJson == null) { MetricsOptions metricsOptions = getMetricsOptions(); options = new VertxOptions().setMetricsOptions(metricsOptions); } else { MetricsOptions metricsOptions = getMetricsOptions(optionsJson.getJsonObject("metricsOptions")); options = new VertxOptions(optionsJson).setMetricsOptions(metricsOptions); configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX); beforeStartingVertx(options); Vertx instance; if (isClustered()) { log.info("Starting clustering..."); if (!Objects.equals(options.getClusterHost(), VertxOptions.DEFAULT_CLUSTER_HOST)) { clusterHost = getDefaultAddress(); if (clusterHost == null) { log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host"); if (getHA()) { options.setHAEnabled(true); if (haGroup != null) { create(options, ar -> { result.set(ar); latch.countDown(); instance = create(options);
/** * Starts the vert.x instance. */ @Override public void run() { this.run(null); }
/** * Validates the command line parameters. * * @param context - the execution context * @throws CLIException - validation failed */ @Override public void setUp(ExecutionContext context) throws CLIException { super.setUp(context); CommandLine commandLine = executionContext.commandLine(); if (!isClustered() && ( commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-host")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-port")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-public-host")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-public-port")) )) { throw new CLIException("The -cluster-xxx options require -cluster to be enabled"); } // If quorum and / or ha-group, ha need to have been explicitly set io.vertx.core.cli.Option haGroupOption = executionContext.cli().getOption("hagroup"); io.vertx.core.cli.Option quorumOption = executionContext.cli().getOption("quorum"); if (!ha && (commandLine.isOptionAssigned(haGroupOption) || commandLine.isOptionAssigned(quorumOption))) { throw new CLIException("The option -hagroup and -quorum requires -ha to be enabled"); } }
/** * @return the metric options. */ protected MetricsOptions getMetricsOptions(JsonObject jsonObject) { MetricsOptions metricsOptions; VertxMetricsFactory factory = ServiceHelper.loadFactoryOrNull(VertxMetricsFactory.class); if (factory != null) { metricsOptions = jsonObject == null ? factory.newOptions() : factory.newOptions(jsonObject); } else { metricsOptions = jsonObject == null ? new MetricsOptions() : new MetricsOptions(jsonObject); } configureFromSystemProperties(metricsOptions, METRICS_OPTIONS_PROP_PREFIX); return metricsOptions; }
super.run(this::afterStoppingVertx); if (vertx == null) {
/** * Validates the command line parameters. * * @param context - the execution context * @throws CLIException - validation failed */ @Override public void setUp(ExecutionContext context) throws CLIException { super.setUp(context); }
/** * @return the metric options. */ protected MetricsOptions getMetricsOptions(JsonObject jsonObject) { MetricsOptions metricsOptions; VertxMetricsFactory factory = ServiceHelper.loadFactoryOrNull(VertxMetricsFactory.class); if (factory != null) { metricsOptions = jsonObject == null ? factory.newOptions() : factory.newOptions(jsonObject); } else { metricsOptions = jsonObject == null ? new MetricsOptions() : new MetricsOptions(jsonObject); } configureFromSystemProperties(metricsOptions, METRICS_OPTIONS_PROP_PREFIX); return metricsOptions; }
JsonObject optionsJson = getJsonFromFileOrString(vertxOptions, "options"); if (optionsJson == null) { MetricsOptions metricsOptions = getMetricsOptions(); options = new VertxOptions().setMetricsOptions(metricsOptions); } else { MetricsOptions metricsOptions = getMetricsOptions(optionsJson.getJsonObject("metricsOptions")); options = new VertxOptions(optionsJson).setMetricsOptions(metricsOptions); configureFromSystemProperties(options, VERTX_OPTIONS_PROP_PREFIX); beforeStartingVertx(options); Vertx instance; if (isClustered()) { log.info("Starting clustering..."); if (!Objects.equals(options.getClusterHost(), VertxOptions.DEFAULT_CLUSTER_HOST)) { clusterHost = getDefaultAddress(); if (clusterHost == null) { log.error("Unable to find a default network interface for clustering. Please specify one using -cluster-host"); if (getHA()) { options.setHAEnabled(true); if (haGroup != null) { create(options, ar -> { result.set(ar); latch.countDown(); instance = create(options);
@Test public void testCPInBareCommand() { bare = new BareCommand(); bare.setExecutionContext(new ExecutionContext(bare, null, null)); bare.setClasspath("." + File.pathSeparator + "target/externals"); bare.setQuorum(1); bare.run(); assertWaitUntil(() -> bare.vertx != null); // Do reproduce the verticle fail-over, set the TCCL final ClassLoader originalClassloader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(bare.createClassloader()); bare.vertx.deployVerticle(VERTICLE, new DeploymentOptions().setHa(true)); } finally { Thread.currentThread().setContextClassLoader(originalClassloader); } assertWaitUntil(() -> { try { return getHttpCode() == 200; } catch (IOException e) { return false; } }); }
/** * Starts the vert.x instance. */ @Override public void run() { this.run(null); }
BareCommand.getTerminationRunnable(vertx, LoggerFactory.getLogger("foo"), () -> asv.set(true)).run();
/** * Validates the command line parameters. * * @param context - the execution context * @throws CLIException - validation failed */ @Override public void setUp(ExecutionContext context) throws CLIException { super.setUp(context); }
super.run(this::afterStoppingVertx); if (vertx == null) {
/** * Registers a shutdown hook closing the given vert.x instance when the JVM is terminating. * Optionally, an action can be executed after the termination of the {@link Vertx} instance. * * @param vertx the vert.x instance, must not be {@code null} * @param log the log, must not be {@code null} * @param action the action, may be {@code null} */ protected static void addShutdownHook(Vertx vertx, Logger log, Runnable action) { Runtime.getRuntime().addShutdownHook(new Thread(getTerminationRunnable(vertx, log, action))); }
/** * Validates the command line parameters. * * @param context - the execution context * @throws CLIException - validation failed */ @Override public void setUp(ExecutionContext context) throws CLIException { super.setUp(context); CommandLine commandLine = executionContext.commandLine(); if (!isClustered() && ( commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-host")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-port")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-public-host")) || commandLine.isOptionAssigned(executionContext.cli().getOption("cluster-public-port")) )) { throw new CLIException("The -cluster-xxx options require -cluster to be enabled"); } // If quorum and / or ha-group, ha need to have been explicitly set io.vertx.core.cli.Option haGroupOption = executionContext.cli().getOption("hagroup"); io.vertx.core.cli.Option quorumOption = executionContext.cli().getOption("quorum"); if (!ha && (commandLine.isOptionAssigned(haGroupOption) || commandLine.isOptionAssigned(quorumOption))) { throw new CLIException("The option -hagroup and -quorum requires -ha to be enabled"); } }
super.run(this::afterStoppingVertx); if (vertx == null) {
BareCommand.getTerminationRunnable(vertx, LoggerFactory.getLogger("foo"), () -> asv.set(true)).run();
super.run(this::afterStoppingVertx); if (vertx == null) {