pauloricardomg commented on code in PR #3716: URL: https://github.com/apache/cassandra/pull/3716#discussion_r2229705232
########## test/distributed/org/apache/cassandra/distributed/test/ring/BootstrapTest.java: ########## @@ -288,4 +296,80 @@ public static void markViewsAsBuilt(@SuperCall Callable<Void> zuper) } } + /** + * This regression test for CASSANDRA-19902 ensures {@link StorageServiceMBean} JMX + * interface is published before the node finishes bootstrapping + */ + @Test + public void testStorageServiceMBeanIsPublishedOnJMXDuringBootstrap() throws Throwable + { + ExecutorService es = Executors.newFixedThreadPool(1); + try (Cluster cluster = builder().withNodes(2) + .withConfig(config -> config.with(GOSSIP) + .with(NETWORK) + .with(JMX) + .set("auto_bootstrap", true)) + .withInstanceInitializer(BBBootstrapInterceptor::install) + .createWithoutStarting(); + Closeable ignored = es::shutdown) + { + Runnable test = () -> + { + // Wait for bootstrap to start via countdown latch + IInvokableInstance joiningInstance = cluster.get(2); + joiningInstance.runOnInstance(() -> BBBootstrapInterceptor.bootstrapStart.awaitUninterruptibly()); + // At this point, it should be possible to check bootstrap status via JMX. + IInstanceConfig config = joiningInstance.config(); + try (JMXConnector jmxc = JMXUtil.getJmxConnector(config)) + { + MBeanServerConnection mbsc = jmxc.getMBeanServerConnection(); + StorageServiceMBean sp = javax.management.JMX.newMBeanProxy(mbsc, new ObjectName("org.apache.cassandra.db:type=StorageService"), StorageServiceMBean.class); + assertEquals(sp.getOperationMode(), StorageService.Mode.JOINING.toString()); + } + catch (Throwable t) + { + throw new AssertionError("Should not fail to connect via JMX before bootstrap is completed.", t); + } + finally + { + // Complete bootstrap via countdown latch so test will finish properly + joiningInstance.runOnInstance(() -> BBBootstrapInterceptor.bootstrapReady.decrement()); + } + }; + + Future<?> testResult = es.submit(test); + try + { + cluster.startup(); + } + catch (Exception ex) { + // ignore exceptions from startup process. More interested in the test result. + } + testResult.get(); + } + es.awaitTermination(5, TimeUnit.SECONDS); + } + + public static class BBBootstrapInterceptor + { + final static CountDownLatch bootstrapReady = CountDownLatch.newCountDownLatch(1); + final static CountDownLatch bootstrapStart = CountDownLatch.newCountDownLatch(1); + static void install(ClassLoader cl, int nodeNumber) + { + if (nodeNumber != 2) + return; + new ByteBuddy().rebase(StorageService.class) + .method(named("markViewsAsBuilt")) + .intercept(MethodDelegation.to(BBBootstrapInterceptor.class)) + .make() + .load(cl, ClassLoadingStrategy.Default.INJECTION); + } + + public static void markViewsAsBuilt(@SuperCall Callable<Void> zuper) Review Comment: yeah this is random, it's the way it currently is on https://github.com/apache/cassandra/blob/trunk/test/distributed/org/apache/cassandra/distributed/test/ring/BootstrapTest.java#L273 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org