if (this.stoppedForReconnect) { logger.info("waiting for distributed system to disconnect..."); while (ds.isConnected()) { Thread.sleep(5000);
/** * Determines whether to continue waiting and keep the GemFire non-Server data member running. * * @param cache the Cache associated with this GemFire (non-Server) data member. * @return a boolean value indicating whether the GemFire data member should continue running, as * determined by the running flag and a connection to the distributed system (GemFire * cluster). */ boolean isWaiting(final Cache cache) { // return (isRunning() && !getCache().isClosed()); return isRunning() && (cache.getDistributedSystem().isConnected() || cache.isReconnecting()); }
@Override public void restarting(DistributedSystem ds, GemFireCache cache, InternalConfigurationPersistenceService sharedConfig) { if (ds != null) { this.loadSnapshot = new LocatorLoadSnapshot(); this.ds = (InternalDistributedSystem) ds; this.advisor = ControllerAdvisor.createControllerAdvisor(this); // escapes constructor but // allows field to be final if (ds.isConnected()) { this.advisor.handshake(); // GEODE-1393: need to get server information during restart } } }
@Test(timeout = 60_000) public void returnsWhenLauncherIsRunningAndSystemIsNotConnected() { serverLauncher.running.set(true); when(cache.getCacheServers()).thenReturn(emptyList()); when(cache.isReconnecting()).thenReturn(false); when(system.isConnected()) .thenReturn(true, true, true) // Connected for a while... .thenReturn(false); // ... then not serverLauncher.waitOnServer(); // Four times: false, false, false, true verify(system, times(4)).isConnected(); }
@After public void tearDown() { serverVM.invoke(() -> { DistributedSystem system = cache.getDistributedSystem(); cache.close(); cache = null; assertThat(system.isConnected()).isFalse(); }); clientVM.invoke(() -> { cache.close(); cache = null; }); }
@Test(timeout = 60_000) public void returnsWhenLauncherIsRunningAndCacheIsNotReconnecting() { serverLauncher.running.set(true); when(cache.getCacheServers()).thenReturn(emptyList()); when(system.isConnected()).thenReturn(false); when(cache.isReconnecting()) .thenReturn(true, true, true) // Reconnecting for a while... .thenReturn(false); // ... then not serverLauncher.waitOnServer(); // Four times: true, true, true, false verify(cache, times(4)).isReconnecting(); }
@Test(timeout = 60_000) public void returnsImmediatelyIfCacheHasServers() { serverLauncher.running.set(true); List<CacheServer> servers = singletonList(mock(CacheServer.class)); when(cache.getCacheServers()).thenReturn(servers); when(system.isConnected()).thenReturn(true); when(cache.isReconnecting()).thenReturn(false); serverLauncher.waitOnServer(); } }
public void waitTilLocatorFullyStarted() { vm.invoke(() -> { try { await().until(() -> { InternalLocator intLocator = ClusterStartupRule.getLocator(); InternalCache cache = ClusterStartupRule.getCache(); return intLocator != null && cache != null && intLocator.getDistributedSystem() .isConnected(); }); } catch (Exception e) { // provide more information when condition is not satisfied after awaitility timeout InternalLocator intLocator = ClusterStartupRule.getLocator(); InternalCache cache = ClusterStartupRule.getCache(); DistributedSystem ds = intLocator.getDistributedSystem(); logger.info("locator is: " + (intLocator != null ? "not null" : "null")); logger.info("cache is: " + (cache != null ? "not null" : "null")); if (ds != null) { logger .info("distributed system is: " + (ds.isConnected() ? "connected" : "not connected")); } else { logger.info("distributed system is: null"); } throw e; } }); }
@Test public void isWaitingReturnsTrueWhenSystemIsConnected() { Cache cache = mock(Cache.class, "Cache"); DistributedSystem system = mock(DistributedSystem.class, "DistributedSystem"); when(cache.getDistributedSystem()).thenReturn(system); when(system.isConnected()).thenReturn(true); ServerLauncher launcher = new Builder().build(); launcher.running.set(true); assertThat(launcher.isWaiting(cache)).isTrue(); }
public void waitTilLocatorFullyReconnected() { vm.invoke(() -> { try { await().until(() -> { InternalLocator intLocator = ClusterStartupRule.getLocator(); InternalCache cache = ClusterStartupRule.getCache(); return intLocator != null && cache != null && intLocator.getDistributedSystem() .isConnected() && intLocator.isReconnected(); }); } catch (Exception e) { // provide more information when condition is not satisfied after awaitility timeout InternalLocator intLocator = ClusterStartupRule.getLocator(); InternalCache cache = ClusterStartupRule.getCache(); DistributedSystem ds = intLocator.getDistributedSystem(); logger.info("locator is: " + (intLocator != null ? "not null" : "null")); logger.info("cache is: " + (cache != null ? "not null" : "null")); if (ds != null) { logger .info("distributed system is: " + (ds.isConnected() ? "connected" : "not connected")); } else { logger.info("distributed system is: null"); } logger.info("locator is reconnected: " + (intLocator.isReconnected())); throw e; } }); }
@Test public void isWaitingReturnsFalseWhenSystemIsNotConnected() { Cache cache = mock(Cache.class, "Cache"); DistributedSystem system = mock(DistributedSystem.class, "DistributedSystem"); when(cache.getDistributedSystem()).thenReturn(system); when(system.isConnected()).thenReturn(false); when(cache.isReconnecting()).thenReturn(false); ServerLauncher launcher = new Builder().setMemberName("serverOne").build(); launcher.running.set(true); assertThat(launcher.isWaiting(cache)).isFalse(); }
@Test(timeout = 60_000) public void returnsWhenLauncherIsNotRunning() { when(cache.getCacheServers()).thenReturn(emptyList()); when(system.isConnected()).thenReturn(true); when(cache.isReconnecting()).thenReturn(false); // Running at first... serverLauncher.running.set(true); // Using isReconnecting() as a test hook to change running state // while we're in the while loop. when(cache.isReconnecting()) .thenReturn(false, false, false) .thenAnswer(invocation -> { serverLauncher.running.set(false); // ... then not running return false; }); serverLauncher.waitOnServer(); assertThat(serverLauncher.isRunning()).isFalse(); }
@Override public void execute(final FunctionContext context) { DistributedSystem ds = InternalDistributedSystem.getConnectedInstance(); if (ds == null || !ds.isConnected()) { return; } String host = ds.getDistributedMember().getHost(); NetstatFunctionArgument args = (NetstatFunctionArgument) context.getArguments(); boolean withlsof = args.isWithlsof(); String lineSeparator = args.getLineSeparator(); String netstatOutput = executeCommand(lineSeparator, withlsof); StringBuilder netstatInfo = new StringBuilder(); // {0} will be replaced on Manager addMemberHostHeader(netstatInfo, "{0}", host, lineSeparator); NetstatFunctionResult result = new NetstatFunctionResult(host, netstatInfo.toString(), CliUtil.compressBytes(netstatOutput.getBytes())); context.getResultSender().lastResult(result); }
private void verifyShutDown(MemberVM... members) { SerializableCallableIF<Boolean> isCacheOpenInThisVM = () -> { boolean cacheExists; try { Cache cacheInstance = CacheFactory.getAnyInstance(); cacheExists = cacheInstance.getDistributedSystem().isConnected(); } catch (CacheClosedException e) { cacheExists = false; } return cacheExists; }; for (MemberVM member : members) { Callable<Boolean> isMemberShutDown = () -> !member.getVM().invoke(isCacheOpenInThisVM); await().until(isMemberShutDown); } } }
public static void crashDistributedSystem(final DistributedSystem msys) { msys.getLogWriter().info("crashing distributed system: " + msys); GMSMembershipManager mgr = ((GMSMembershipManager) getMembershipManager(msys)); mgr.saveCacheXmlForReconnect(false); MembershipManagerHelper.inhibitForcedDisconnectLogging(true); MembershipManagerHelper.beSickMember(msys); MembershipManagerHelper.playDead(msys); mgr.forceDisconnect("for testing"); // wait at most 10 seconds for system to be disconnected await().until(() -> !msys.isConnected()); MembershipManagerHelper.inhibitForcedDisconnectLogging(false); }
logger.info("Executing in TestFunction on Server : " + ds.getDistributedMember() + "with Context : " + context); while (ds.isConnected()) { logger.fine("Just executing function in infinite loop for Bug43513"); try {
private Function<Health.Builder, Health.Builder> withDistributedSystemDetails() { return healthBuilder -> getGemFireCache() .map(GemFireCache::getDistributedSystem) .map(distributedSystem -> healthBuilder .withDetail("geode.distributed-system.member-count", Optional.of(distributedSystem) .map(DistributedSystem::getAllOtherMembers) .map(Collection::size) .map(size -> size + 1) .orElse(1)) .withDetail("geode.distributed-system.connection", toConnectedNoConnectedString(distributedSystem.isConnected())) .withDetail("geode.distributed-system.reconnecting", toYesNoString(distributedSystem.isReconnecting())) .withDetail("geode.distributed-system.properties-location", Optional.ofNullable(DistributedSystem.getPropertiesFileURL()) .map(URL::toExternalForm) .filter(StringUtils::hasText) .orElse("")) .withDetail("geode.distributed-system.security-properties-location", Optional.ofNullable(DistributedSystem.getSecurityPropertiesFileURL()) .map(URL::toExternalForm) .filter(StringUtils::hasText) .orElse("")) ) .orElse(healthBuilder); }