private ServerState stopInProcess() { if (isStoppable()) { if (this.cache.isReconnecting()) { this.cache.getDistributedSystem().stopReconnecting(); } // Another case of needing to use a non-daemon thread to keep the JVM alive until a clean // shutdown can be performed. If not, the JVM may exit too early causing the member to be // seen as having crashed and not cleanly departed. Thread t = new LoggingThread("ServerLauncherStopper", false, this::doStopInProcess); t.start(); try { t.join(); } catch (InterruptedException e) { // no matter, we're shutting down... } INSTANCE.compareAndSet(this, null); // note: other thread may return Status.NOT_RESPONDING now this.running.set(false); return new ServerState(this, Status.STOPPED); } else { return new ServerState(this, Status.NOT_RESPONDING); } }
@Test public void reconnectingDistributedSystemIsDisconnectedOnStop() { Cache cache = mock(Cache.class, "Cache"); DistributedSystem system = mock(DistributedSystem.class, "DistributedSystem"); Cache reconnectedCache = mock(Cache.class, "ReconnectedCache"); when(cache.isReconnecting()).thenReturn(true); when(cache.getReconnectedCache()).thenReturn(reconnectedCache); when(reconnectedCache.isReconnecting()).thenReturn(true); when(reconnectedCache.getReconnectedCache()).thenReturn(null); when(reconnectedCache.getDistributedSystem()).thenReturn(system); ServerLauncher launcher = new Builder().setCache(cache).build(); launcher.running.set(true); launcher.stop(); verify(cache, times(1)).isReconnecting(); verify(cache, times(1)).getReconnectedCache(); verify(cache, times(1)).isReconnecting(); verify(cache, times(1)).getReconnectedCache(); verify(reconnectedCache, times(1)).getDistributedSystem(); verify(system, times(1)).stopReconnecting(); verify(reconnectedCache, times(1)).close(); }
InternalDistributedSystem.systemAttemptingReconnect.stopReconnecting();