also clean up code of DefaultProcessCommands and fix it's Javadoc which was out of sync with implementationtags/5.5-M11
@@ -87,8 +87,8 @@ public class CeServer implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
checkState(ceMainThread != null, "isReady() can not be called before start()"); | |||
public boolean isUp() { | |||
checkState(ceMainThread != null, "isUp() can not be called before start()"); | |||
return ceMainThread.isStarted(); | |||
} |
@@ -91,9 +91,9 @@ public class CeServerTest { | |||
CeServer ceServer = newCeServer(); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("isReady() can not be called before start()"); | |||
expectedException.expectMessage("isUp() can not be called before start()"); | |||
ceServer.isReady(); | |||
ceServer.isUp(); | |||
} | |||
@Test | |||
@@ -103,15 +103,15 @@ public class CeServerTest { | |||
ceServer.start(); | |||
assertThat(ceServer.isReady()).isFalse(); | |||
assertThat(ceServer.isUp()).isFalse(); | |||
// release ComputeEngine startup method | |||
computeEngine.releaseStartup(); | |||
while (!ceServer.isReady()) { | |||
while (!ceServer.isUp()) { | |||
// wait for isReady to change to true, otherwise test will fail with timeout | |||
} | |||
assertThat(ceServer.isReady()).isTrue(); | |||
assertThat(ceServer.isUp()).isTrue(); | |||
} | |||
@Test | |||
@@ -123,15 +123,15 @@ public class CeServerTest { | |||
ceServer.start(); | |||
assertThat(ceServer.isReady()).isFalse(); | |||
assertThat(ceServer.isUp()).isFalse(); | |||
// release ComputeEngine startup method which will throw startupException | |||
computeEngine.releaseStartup(); | |||
while (!ceServer.isReady()) { | |||
while (!ceServer.isUp()) { | |||
// wait for isReady to change to true, otherwise test will fail with timeout | |||
} | |||
assertThat(ceServer.isReady()).isTrue(); | |||
assertThat(ceServer.isUp()).isTrue(); | |||
} | |||
@Test |
@@ -155,7 +155,7 @@ public class Monitor { | |||
watcherThreads.add(watcherThread); | |||
// wait for process to be ready (accept requests or so on) | |||
processRef.waitForReady(); | |||
processRef.waitForUp(); | |||
LOG.info("{} is up", processRef); | |||
} |
@@ -58,17 +58,17 @@ class ProcessRef { | |||
return commands; | |||
} | |||
void waitForReady() { | |||
boolean ready = false; | |||
while (!ready) { | |||
void waitForUp() { | |||
boolean up = false; | |||
while (!up) { | |||
if (isStopped()) { | |||
throw new MessageException(String.format("%s failed to start", this)); | |||
} | |||
ready = commands.isReady(); | |||
up = commands.isUp(); | |||
try { | |||
Thread.sleep(200L); | |||
} catch (InterruptedException e) { | |||
throw new IllegalStateException(String.format("Interrupted while waiting for %s to be ready", this), e); | |||
throw new IllegalStateException(String.format("Interrupted while waiting for %s to be up", this), e); | |||
} | |||
} | |||
} |
@@ -151,7 +151,7 @@ public class MonitorTest { | |||
// blocks until started | |||
underTest.start(singletonList(client.newCommand())); | |||
assertThat(client).isReady() | |||
assertThat(client).isUp() | |||
.wasStartedBefore(System.currentTimeMillis()); | |||
// blocks until stopped | |||
@@ -172,10 +172,10 @@ public class MonitorTest { | |||
// start p2 when p1 is fully started (ready) | |||
assertThat(p1) | |||
.isReady() | |||
.isUp() | |||
.wasStartedBefore(p2); | |||
assertThat(p2) | |||
.isReady(); | |||
.isUp(); | |||
underTest.stop(); | |||
@@ -195,8 +195,8 @@ public class MonitorTest { | |||
HttpProcessClient p1 = new HttpProcessClient(tempDir, "p1"); | |||
HttpProcessClient p2 = new HttpProcessClient(tempDir, "p2"); | |||
underTest.start(Arrays.asList(p1.newCommand(), p2.newCommand())); | |||
assertThat(p1).isReady(); | |||
assertThat(p2).isReady(); | |||
assertThat(p1).isUp(); | |||
assertThat(p2).isUp(); | |||
// emulate CTRL-C | |||
underTest.getShutdownHook().run(); | |||
@@ -215,8 +215,8 @@ public class MonitorTest { | |||
HttpProcessClient p2 = new HttpProcessClient(tempDir, "p2"); | |||
underTest.start(Arrays.asList(p1.newCommand(), p2.newCommand())); | |||
assertThat(p1).isReady(); | |||
assertThat(p2).isReady(); | |||
assertThat(p1).isUp(); | |||
assertThat(p2).isUp(); | |||
p2.restart(); | |||
@@ -247,8 +247,8 @@ public class MonitorTest { | |||
HttpProcessClient p1 = new HttpProcessClient(tempDir, "p1"); | |||
HttpProcessClient p2 = new HttpProcessClient(tempDir, "p2"); | |||
underTest.start(Arrays.asList(p1.newCommand(), p2.newCommand())); | |||
assertThat(p1.isReady()).isTrue(); | |||
assertThat(p2.isReady()).isTrue(); | |||
assertThat(p1.isUp()).isTrue(); | |||
assertThat(p2.isUp()).isTrue(); | |||
// kill p1 -> waiting for detection by monitor than termination of p2 | |||
p1.kill(); | |||
@@ -369,7 +369,7 @@ public class MonitorTest { | |||
/** | |||
* @see org.sonar.process.test.HttpProcess | |||
*/ | |||
boolean isReady() { | |||
boolean isUp() { | |||
try { | |||
HttpRequest httpRequest = HttpRequest.get("http://localhost:" + httpPort + "/" + "ping") | |||
.readTimeout(2000).connectTimeout(2000); | |||
@@ -538,12 +538,12 @@ public class MonitorTest { | |||
return this; | |||
} | |||
public HttpProcessClientAssert isReady() { | |||
public HttpProcessClientAssert isUp() { | |||
isNotNull(); | |||
// check condition | |||
if (!actual.isReady()) { | |||
failWithMessage("HttpClient %s should be ready", actual.commandKey); | |||
if (!actual.isUp()) { | |||
failWithMessage("HttpClient %s should be up", actual.commandKey); | |||
} | |||
return this; | |||
@@ -552,7 +552,7 @@ public class MonitorTest { | |||
public HttpProcessClientAssert isNotReady() { | |||
isNotNull(); | |||
if (actual.isReady()) { | |||
if (actual.isUp()) { | |||
failWithMessage("HttpClient %s should not be ready", actual.commandKey); | |||
} | |||
@@ -32,46 +32,50 @@ import static org.sonar.process.ProcessCommands.MAX_PROCESSES; | |||
* Process inter-communication to : | |||
* <ul> | |||
* <li>share status of child process</li> | |||
* <li>stop child process</li> | |||
* <li>stop/restart child process</li> | |||
* </ul> | |||
* | |||
* <p/> | |||
* It relies on files shared by both processes. Following alternatives were considered but not selected : | |||
* <p> | |||
* It relies on a single file accessed by all processes through a {@link MappedByteBuffer}.<br/> | |||
* Following alternatives were considered but not selected : | |||
* <ul> | |||
* <li>JMX beans over RMI: network issues (mostly because of Java reverse-DNS) + requires to configure and open a new port</li> | |||
* <li>simple socket protocol: same drawbacks are RMI connection</li> | |||
* <li>java.lang.Process#destroy(): shutdown hooks are not executed on some OS (mostly MSWindows)</li> | |||
* <li>execute OS-specific commands (for instance kill on *nix): OS-specific, so hell to support. Moreover how to get identify a process ?</li> | |||
* </ul> | |||
* </p> | |||
* | |||
* <p> | |||
* The file contains {@link ProcessCommands#MAX_PROCESSES} groups of {@link #BYTE_LENGTH_FOR_ONE_PROCESS} bits. | |||
* Each group of byte is used as follow: | |||
* <ul> | |||
* <li>First byte contains {@link #EMPTY} until process is UP and writes {@link #UP}</li> | |||
* <li>Second byte contains {@link #EMPTY} until any process requests current one to stop by writing value {@link #STOP}</li> | |||
* <li>Third byte contains {@link #EMPTY} until any process requests current one to restart by writing value {@link #RESTART}. Process acknowledges restart by writing back {@link #EMPTY}</li> | |||
* <li>The next 8 bytes contains a long (value of {@link System#currentTimeMillis()}) which represents the date of the last ping</li> | |||
* </ul> | |||
* </p> | |||
*/ | |||
public class AllProcessesCommands { | |||
private static final int UP_BYTE_OFFSET = 0; | |||
private static final int STOP_BYTE_OFFSET = 1; | |||
private static final int RESTART_BYTE_OFFSET = 2; | |||
private static final int PING_BYTE_OFFSET = 3; | |||
/** | |||
* The ByteBuffer will contains : | |||
* <ul> | |||
* <li>First byte will contains 0x00 until stop command is issued = 0xFF</li> | |||
* <li>Then each 10 bytes will be reserved for each process</li> | |||
* </ul> | |||
* | |||
* Description of ten bytes of each process : | |||
* <ul> | |||
* <li>First byte will contains the state 0x00 until READY 0x01</li> | |||
* <li>The second byte will contains the request for stopping 0x00 or STOP (0xFF)</li> | |||
* <li>The second byte will contains the request for restarting 0x00 or RESTART (0xAA)</li> | |||
* <li>The next 8 bytes contains a long (System.currentTimeInMillis for ping)</li> | |||
* </ul> | |||
*/ | |||
final MappedByteBuffer mappedByteBuffer; | |||
private final RandomAccessFile sharedMemory; | |||
private static final int BYTE_LENGTH_FOR_ONE_PROCESS = 1 + 1 + 1 + 8; | |||
// With this shared memory we can handle up to MAX_PROCESSES processes | |||
private static final int MAX_SHARED_MEMORY = BYTE_LENGTH_FOR_ONE_PROCESS * MAX_PROCESSES; | |||
public static final byte STOP = (byte) 0xFF; | |||
public static final byte RESTART = (byte) 0xAA; | |||
public static final byte READY = (byte) 0x01; | |||
public static final byte EMPTY = (byte) 0x00; | |||
private static final byte STOP = (byte) 0xFF; | |||
private static final byte RESTART = (byte) 0xAA; | |||
private static final byte UP = (byte) 0x01; | |||
private static final byte EMPTY = (byte) 0x00; | |||
//VisibleForTesting | |||
final MappedByteBuffer mappedByteBuffer; | |||
private final RandomAccessFile sharedMemory; | |||
public AllProcessesCommands(File directory) { | |||
if (!directory.isDirectory() || !directory.exists()) { | |||
@@ -103,56 +107,52 @@ public class AllProcessesCommands { | |||
return processCommands; | |||
} | |||
boolean isReady(int processNumber) { | |||
return mappedByteBuffer.get(offset(processNumber)) == READY; | |||
boolean isUp(int processNumber) { | |||
return readByte(processNumber, UP_BYTE_OFFSET) == UP; | |||
} | |||
/** | |||
* To be executed by child process to declare that it's ready | |||
* To be executed by child process to declare that it is done starting | |||
*/ | |||
void setReady(int processNumber) { | |||
mappedByteBuffer.put(offset(processNumber), READY); | |||
void setUp(int processNumber) { | |||
writeByte(processNumber, UP_BYTE_OFFSET, UP); | |||
} | |||
void ping(int processNumber) { | |||
mappedByteBuffer.putLong(2 + offset(processNumber), System.currentTimeMillis()); | |||
writeLong(processNumber, PING_BYTE_OFFSET, System.currentTimeMillis()); | |||
} | |||
long getLastPing(int processNumber) { | |||
return mappedByteBuffer.getLong(2 + offset(processNumber)); | |||
return readLong(processNumber, PING_BYTE_OFFSET); | |||
} | |||
/** | |||
* To be executed by monitor process to ask for child process termination | |||
*/ | |||
void askForStop(int processNumber) { | |||
mappedByteBuffer.put(offset(processNumber) + 1, STOP); | |||
writeByte(processNumber, STOP_BYTE_OFFSET, STOP); | |||
} | |||
boolean askedForStop(int processNumber) { | |||
return mappedByteBuffer.get(offset(processNumber) + 1) == STOP; | |||
return readByte(processNumber, STOP_BYTE_OFFSET) == STOP; | |||
} | |||
void askForRestart(int processNumber) { | |||
mappedByteBuffer.put(offset(processNumber) + 3, RESTART); | |||
writeByte(processNumber, RESTART_BYTE_OFFSET, RESTART); | |||
} | |||
boolean askedForRestart(int processNumber) { | |||
return mappedByteBuffer.get(offset(processNumber) + 3) == RESTART; | |||
return readByte(processNumber, RESTART_BYTE_OFFSET) == RESTART; | |||
} | |||
void acknowledgeAskForRestart(int processNumber) { | |||
mappedByteBuffer.put(offset(processNumber) + 3, EMPTY); | |||
writeByte(processNumber, RESTART_BYTE_OFFSET, EMPTY); | |||
} | |||
public void close() { | |||
IOUtils.closeQuietly(sharedMemory); | |||
} | |||
int offset(int processNumber) { | |||
return BYTE_LENGTH_FOR_ONE_PROCESS * processNumber; | |||
} | |||
public void checkProcessNumber(int processNumber) { | |||
boolean result = processNumber >= 0 && processNumber < MAX_PROCESSES; | |||
if (!result) { | |||
@@ -162,10 +162,31 @@ public class AllProcessesCommands { | |||
private void cleanData(int processNumber) { | |||
for (int i = 0; i < BYTE_LENGTH_FOR_ONE_PROCESS; i++) { | |||
mappedByteBuffer.put(offset(processNumber) + i, EMPTY); | |||
writeByte(processNumber, i, EMPTY); | |||
} | |||
} | |||
private void writeByte(int processNumber, int offset, byte value) { | |||
mappedByteBuffer.put(offset(processNumber) + offset, value); | |||
} | |||
private byte readByte(int processNumber, int offset) { | |||
return mappedByteBuffer.get(offset(processNumber) + offset); | |||
} | |||
private void writeLong(int processNumber, int offset, long value) { | |||
mappedByteBuffer.putLong(offset(processNumber) + offset, value); | |||
} | |||
private long readLong(int processNumber, int offset) { | |||
return mappedByteBuffer.getLong(offset(processNumber) + offset); | |||
} | |||
// VisibleForTesting | |||
int offset(int processNumber) { | |||
return BYTE_LENGTH_FOR_ONE_PROCESS * processNumber; | |||
} | |||
private class ProcessCommandsImpl implements ProcessCommands { | |||
private final int processNumber; | |||
@@ -175,13 +196,13 @@ public class AllProcessesCommands { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
return AllProcessesCommands.this.isReady(processNumber); | |||
public boolean isUp() { | |||
return AllProcessesCommands.this.isUp(processNumber); | |||
} | |||
@Override | |||
public void setReady() { | |||
AllProcessesCommands.this.setReady(processNumber); | |||
public void setUp() { | |||
AllProcessesCommands.this.setUp(processNumber); | |||
} | |||
@Override |
@@ -40,13 +40,13 @@ public class DefaultProcessCommands implements ProcessCommands { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
return delegate.isReady(); | |||
public boolean isUp() { | |||
return delegate.isUp(); | |||
} | |||
@Override | |||
public void setReady() { | |||
delegate.setReady(); | |||
public void setUp() { | |||
delegate.setUp(); | |||
} | |||
@Override |
@@ -27,11 +27,10 @@ public interface Monitored { | |||
void start(); | |||
/** | |||
* True if the process is started and operational (-> can accept requests), false if | |||
* it's still starting. An exception is thrown is process failed to start (not starting | |||
* nor started). | |||
* True if the process is done starting, false otherwise. | |||
* An exception may be thrown if process fails to start. | |||
*/ | |||
boolean isReady(); | |||
boolean isUp(); | |||
/** | |||
* Blocks until the process is terminated |
@@ -19,33 +19,27 @@ | |||
*/ | |||
package org.sonar.process; | |||
import java.io.File; | |||
/** | |||
* Process inter-communication to : | |||
* <ul> | |||
* <li>share status of child process</li> | |||
* <li>stop child process</li> | |||
* <li>restart all child processes</li> | |||
* <li>share status of specific process</li> | |||
* <li>stop/restart a specific processes</li> | |||
* </ul> | |||
* | |||
* <p/> | |||
* It relies on files shared by both processes. Following alternatives were considered but not selected : | |||
* <ul> | |||
* <li>JMX beans over RMI: network issues (mostly because of Java reverse-DNS) + requires to configure and open a new port</li> | |||
* <li>simple socket protocol: same drawbacks are RMI connection</li> | |||
* <li>java.lang.Process#destroy(): shutdown hooks are not executed on some OS (mostly MSWindows)</li> | |||
* <li>execute OS-specific commands (for instance kill on *nix): OS-specific, so hell to support. Moreover how to get identify a process ?</li> | |||
* </ul> | |||
* @see DefaultProcessCommands#DefaultProcessCommands(File, int) | |||
*/ | |||
public interface ProcessCommands extends AutoCloseable { | |||
int MAX_PROCESSES = 50; | |||
boolean isReady(); | |||
boolean isUp(); | |||
/** | |||
* To be executed by child process to declare that it's ready | |||
* To be executed by child process to declare that it is done starting | |||
*/ | |||
void setReady(); | |||
void setUp(); | |||
void ping(); | |||
@@ -79,14 +79,14 @@ public class ProcessEntryPoint implements Stoppable { | |||
stopWatcher.start(); | |||
monitored.start(); | |||
boolean ready = false; | |||
while (!ready) { | |||
ready = monitored.isReady(); | |||
boolean up = false; | |||
while (!up) { | |||
up = monitored.isUp(); | |||
Thread.sleep(20L); | |||
} | |||
// notify monitor that process is ready | |||
commands.setReady(); | |||
commands.setUp(); | |||
if (lifecycle.tryToMoveTo(Lifecycle.State.STARTED)) { | |||
monitored.awaitStop(); |
@@ -33,6 +33,10 @@ import static org.sonar.process.ProcessCommands.MAX_PROCESSES; | |||
public class AllProcessesCommandsTest { | |||
private static final int PROCESS_NUMBER = 1; | |||
private static final byte STOP = (byte) 0xFF; | |||
private static final byte RESTART = (byte) 0xAA; | |||
private static final byte UP = (byte) 0x01; | |||
private static final byte EMPTY = (byte) 0x00; | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@@ -57,17 +61,17 @@ public class AllProcessesCommandsTest { | |||
File dir = temp.newFolder(); | |||
AllProcessesCommands commands = new AllProcessesCommands(dir); | |||
assertThat(commands.isReady(PROCESS_NUMBER)).isFalse(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER))).isEqualTo(AllProcessesCommands.EMPTY); | |||
assertThat(commands.isUp(PROCESS_NUMBER)).isFalse(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER))).isEqualTo(EMPTY); | |||
assertThat(commands.mappedByteBuffer.getLong(2 + commands.offset(PROCESS_NUMBER))).isEqualTo(0L); | |||
commands.setReady(PROCESS_NUMBER); | |||
assertThat(commands.isReady(PROCESS_NUMBER)).isTrue(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER))).isEqualTo(AllProcessesCommands.READY); | |||
commands.setUp(PROCESS_NUMBER); | |||
assertThat(commands.isUp(PROCESS_NUMBER)).isTrue(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER))).isEqualTo(UP); | |||
long currentTime = System.currentTimeMillis(); | |||
commands.ping(PROCESS_NUMBER); | |||
assertThat(commands.mappedByteBuffer.getLong(2 + commands.offset(PROCESS_NUMBER))).isGreaterThanOrEqualTo(currentTime); | |||
assertThat(commands.mappedByteBuffer.getLong(3 + commands.offset(PROCESS_NUMBER))).isGreaterThanOrEqualTo(currentTime); | |||
} | |||
@Test | |||
@@ -75,12 +79,12 @@ public class AllProcessesCommandsTest { | |||
File dir = temp.newFolder(); | |||
AllProcessesCommands commands = new AllProcessesCommands(dir); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + PROCESS_NUMBER)).isNotEqualTo(AllProcessesCommands.STOP); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 1)).isNotEqualTo(STOP); | |||
assertThat(commands.askedForStop(PROCESS_NUMBER)).isFalse(); | |||
commands.askForStop(PROCESS_NUMBER); | |||
assertThat(commands.askedForStop(PROCESS_NUMBER)).isTrue(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + PROCESS_NUMBER)).isEqualTo(AllProcessesCommands.STOP); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 1)).isEqualTo(STOP); | |||
} | |||
@Test | |||
@@ -88,12 +92,12 @@ public class AllProcessesCommandsTest { | |||
File dir = temp.newFolder(); | |||
AllProcessesCommands commands = new AllProcessesCommands(dir); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isNotEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) +2)).isNotEqualTo(RESTART); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isFalse(); | |||
commands.askForRestart(PROCESS_NUMBER); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isTrue(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 2)).isEqualTo(RESTART); | |||
} | |||
@Test | |||
@@ -101,11 +105,11 @@ public class AllProcessesCommandsTest { | |||
File dir = temp.newFolder(); | |||
AllProcessesCommands commands = new AllProcessesCommands(dir); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isNotEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 2)).isNotEqualTo(RESTART); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isFalse(); | |||
commands.acknowledgeAskForRestart(PROCESS_NUMBER); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isNotEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 2)).isNotEqualTo(RESTART); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isFalse(); | |||
} | |||
@@ -117,10 +121,10 @@ public class AllProcessesCommandsTest { | |||
commands.askForRestart(PROCESS_NUMBER); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isTrue(); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 2)).isEqualTo(RESTART); | |||
commands.acknowledgeAskForRestart(PROCESS_NUMBER); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 3)).isNotEqualTo(AllProcessesCommands.RESTART); | |||
assertThat(commands.mappedByteBuffer.get(commands.offset(PROCESS_NUMBER) + 2)).isNotEqualTo(RESTART); | |||
assertThat(commands.askedForRestart(PROCESS_NUMBER)).isFalse(); | |||
} | |||
@@ -57,10 +57,10 @@ public class DefaultProcessCommandsTest { | |||
File dir = temp.newFolder(); | |||
DefaultProcessCommands commands = new DefaultProcessCommands(dir, PROCESS_NUMBER); | |||
assertThat(commands.isReady()).isFalse(); | |||
assertThat(commands.isUp()).isFalse(); | |||
commands.setReady(); | |||
assertThat(commands.isReady()).isTrue(); | |||
commands.setUp(); | |||
assertThat(commands.isUp()).isTrue(); | |||
} | |||
@Test |
@@ -165,7 +165,7 @@ public class ProcessEntryPointTest { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
return true; | |||
} | |||
@@ -188,7 +188,7 @@ public class ProcessEntryPointTest { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
return false; | |||
} | |||
@@ -88,7 +88,7 @@ public class HttpProcess implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
if (ready) { | |||
return true; | |||
} |
@@ -51,7 +51,7 @@ public class InfiniteTerminationProcess implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
return state == State.STARTED; | |||
} | |||
@@ -51,7 +51,7 @@ public class StandardProcess implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
return state == State.STARTED; | |||
} | |||
@@ -46,7 +46,7 @@ public class SearchServer implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
public boolean isUp() { | |||
return node != null && node.client().admin().cluster().prepareHealth() | |||
.setWaitForYellowStatus() | |||
.setTimeout(TimeValue.timeValueSeconds(30L)) |
@@ -81,7 +81,7 @@ public class SearchServerTest { | |||
searchServer = new SearchServer(props); | |||
searchServer.start(); | |||
assertThat(searchServer.isReady()).isTrue(); | |||
assertThat(searchServer.isUp()).isTrue(); | |||
Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", CLUSTER_NAME).build(); | |||
client = new TransportClient(settings) |
@@ -66,7 +66,7 @@ class EmbeddedTomcat { | |||
} | |||
} | |||
boolean isReady() { | |||
boolean isUp() { | |||
if (webappContext == null) { | |||
return false; | |||
} |
@@ -44,8 +44,8 @@ public class WebServer implements Monitored { | |||
} | |||
@Override | |||
public boolean isReady() { | |||
return tomcat.isReady(); | |||
public boolean isUp() { | |||
return tomcat.isUp(); | |||
} | |||
@Override |
@@ -60,9 +60,9 @@ public class EmbeddedTomcatTest { | |||
props.set("sonar.web.port", String.valueOf(httpPort)); | |||
props.set("sonar.ajp.port", String.valueOf(ajpPort)); | |||
EmbeddedTomcat tomcat = new EmbeddedTomcat(props); | |||
assertThat(tomcat.isReady()).isFalse(); | |||
assertThat(tomcat.isUp()).isFalse(); | |||
tomcat.start(); | |||
assertThat(tomcat.isReady()).isTrue(); | |||
assertThat(tomcat.isUp()).isTrue(); | |||
// check that http connector accepts requests | |||
URL url = new URL("http://" + Inet4Address.getLocalHost().getHostAddress() + ":" + httpPort); | |||
@@ -70,7 +70,7 @@ public class EmbeddedTomcatTest { | |||
// stop server | |||
tomcat.terminate(); | |||
// tomcat.isReady() must not be called. It is used to wait for server startup, not shutdown. | |||
// tomcat.isUp() must not be called. It is used to wait for server startup, not shutdown. | |||
try { | |||
url.openConnection().connect(); | |||
fail(); |