@Test public void testScope() { context.getBean("client"); context.getBean("client"); Assert.assertEquals(3, HazelcastClient.getAllHazelcastClients().size()); HazelcastInstance instance = (HazelcastInstance) context.getBean("instance"); Assert.assertEquals(1, Hazelcast.getAllHazelcastInstances().size()); Assert.assertEquals(instance, Hazelcast.getAllHazelcastInstances().iterator().next()); }
@Test public void testLazy() { Assert.assertTrue(Hazelcast.getAllHazelcastInstances().isEmpty()); Assert.assertTrue(HazelcastClient.getAllHazelcastClients().isEmpty()); context.getBean("map2"); Assert.assertEquals(1, Hazelcast.getAllHazelcastInstances().size()); Assert.assertEquals(1, HazelcastClient.getAllHazelcastClients().size()); HazelcastInstance hazelcast = Hazelcast.getAllHazelcastInstances().iterator().next(); Assert.assertEquals(2, hazelcast.getInstances().size()); }
@Override public void start() throws Exception { System.out.println("Elapsed time: " + sw); // if(true) return; EventBus eb = vertx.eventBus(); // eb.addInterceptor(sc->{ // System.out.println("----- "+sc.message()); // sc.next(); // }); // Send a message every second AtomicInteger count = new AtomicInteger(0); // vertx.setPeriodic(1000, v -> { sendPing(eb, count); }); // sendPing(eb, count); for (int i = 1; i < 5; ++i) { vertx.setTimer( 1000 * i, v -> { sendPing(eb, count); }); } // vertx.setTimer(1000*6, v -> { throw new RuntimeException("test"); }); if (!true) { // This works!! vertx.setTimer( 1000 * 7, v -> { System.out.println("Calling vertx.close()"); log.info("Calling vertx.close()"); vertx.close( c -> { System.out.println("Callback to vertx.close() " + c); System.err.println("Callback to vertx.close() " + c); log.info("Callback to vertx.close() " + c); }); try { System.out.println("Sleeping"); Thread.sleep(2000); System.out.println("Waking"); } catch (Exception e) { e.printStackTrace(); } }); } else { Thread thread = new Thread( () -> { System.out.println("calling vertx.close()"); if (false) vertx.close( c -> { // this executes only if I hit Ctrl-C (perhaps because Vertx already has a // shutdownHook!) log.info("callback to vertx.close() " + c); System.out.println("vertx closed"); // Runner.mgr.leave(r->{}); Hazelcast.getAllHazelcastInstances() .forEach( h -> { System.err.println("calling h.close() " + h); h.getLifecycleService().shutdown(); }); System.err.println("calling Hazelcast.shutdownAll() "); Hazelcast.shutdownAll(); }); try { int sec = 0; log.info( "Sleeping {} seconds to allow Vertx's shutdown hook to finish completely...", sec); Thread.sleep(sec * 1000); System.out.println("Waking"); } catch (Exception e) { e.printStackTrace(); } }, "vertx-shutdown-hook"); // thread.setDaemon(false); Runtime.getRuntime().addShutdownHook(thread); } vertx.setTimer( 1000 * 7, v -> { System.exit(0); }); }