/** * Determines whether the Server is the process of starting or is already running. * * @return a boolean indicating if the Server is starting or is already running. */ protected boolean isStartingOrRunning() { return this.starting.get() || isRunning(); }
/** * Determines whether a GemFire Cache Server can be started with this instance of ServerLauncher. * * @return a boolean indicating whether a GemFire Cache Server can be started with this instance * of ServerLauncher, which is true if the ServerLauncher has not already started a Server * or a Server is not already running. * @see #start() */ private boolean isStartable() { return !isRunning() && this.starting.compareAndSet(false, true); }
/** * Determines whether the Server can be stopped in-process, such as when a Server is embedded in * an application and the ServerLauncher API is being used. * * @return a boolean indicating whether the Server can be stopped in-process (the application's * process with an embedded Server). */ private boolean isStoppable() { return isRunning() && getCache() != null; }
/** * 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()); }
private ServerState statusInProcess() { if (isStartingOrRunning()) { debug( "Getting status from the ServerLauncher instance that actually launched the GemFire Cache Server.%n"); return new ServerState(this, isRunning() ? Status.ONLINE : Status.STARTING); } else { return new ServerState(this, Status.NOT_RESPONDING); } }
@Test public void isRunningReturnsTrueWhenRunningIsSetTrue() { ServerLauncher launcher = new Builder().build(); launcher.running.set(true); assertThat(launcher.isRunning()).isTrue(); }
@Test public void isRunningReturnsFalseWhenRunningIsSetFalse() { ServerLauncher launcher = new Builder().build(); launcher.running.set(false); assertThat(launcher.isRunning()).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(); }
@Test public void buildCreatesServerLauncherWithBuilderValues() throws UnknownHostException { ServerLauncher launcher = new Builder().setCommand(Command.STOP).setAssignBuckets(true) .setForce(true).setMemberName("serverOne").setRebalance(true) .setServerBindAddress(InetAddress.getLocalHost().getHostAddress()).setServerPort(11235) .setCriticalHeapPercentage(90.0f).setEvictionHeapPercentage(75.0f).setMaxConnections(100) .setMaxMessageCount(512).setMaxThreads(8).setMessageTimeToLive(120000) .setSocketBufferSize(32768).setRedirectOutput(Boolean.TRUE).build(); assertThat(launcher.getCommand()).isEqualTo(Command.STOP); assertThat(launcher.getMemberName()).isEqualTo("serverOne"); assertThat(launcher.getServerBindAddress()).isEqualTo(InetAddress.getLocalHost()); assertThat(launcher.getServerPort().intValue()).isEqualTo(11235); assertThat(launcher.getCriticalHeapPercentage().floatValue()).isEqualTo(90.0f); assertThat(launcher.getEvictionHeapPercentage().floatValue()).isEqualTo(75.0f); assertThat(launcher.getMaxConnections().intValue()).isEqualTo(100); assertThat(launcher.getMaxMessageCount().intValue()).isEqualTo(512); assertThat(launcher.getMaxThreads().intValue()).isEqualTo(8); assertThat(launcher.getMessageTimeToLive().intValue()).isEqualTo(120000); assertThat(launcher.getSocketBufferSize().intValue()).isEqualTo(32768); assertThat(launcher.isAssignBuckets()).isTrue(); assertThat(launcher.isDebugging()).isFalse(); assertThat(launcher.isDisableDefaultServer()).isFalse(); assertThat(launcher.isForcing()).isTrue(); assertThat(launcher.isHelping()).isFalse(); assertThat(launcher.isRebalancing()).isTrue(); assertThat(launcher.isRedirectingOutput()).isTrue(); assertThat(launcher.isRunning()).isFalse(); }
/** * Invokes the 'status' command and operation to check the status of a GemFire server (a cache * server). */ public ServerState status() { final ServerLauncher launcher = getInstance(); // if this instance is running then return local status if (isStartingOrRunning()) { debug( "Getting status from the ServerLauncher instance that actually launched the GemFire Cache Server.%n"); return new ServerState(this, isRunning() ? Status.ONLINE : Status.STARTING); } else if (isPidInProcess() && launcher != null) { return launcher.statusInProcess(); } else if (getPid() != null) { debug("Getting Server status using process ID (%1$s)%n", getPid()); return statusWithPid(); } // attempt to get status using workingDirectory else if (getWorkingDirectory() != null) { debug("Getting Server status using working directory (%1$s)%n", getWorkingDirectory()); return statusWithWorkingDirectory(); } debug("This ServerLauncher was not the instance used to launch the GemFire Cache Server, and " + "neither PID nor working directory were specified; the Server's state is unknown.%n"); return new ServerState(this, Status.NOT_RESPONDING); }