]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7435 rename state when process is done starting from ready to up
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 9 Mar 2016 10:06:15 +0000 (11:06 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 21 Mar 2016 15:44:03 +0000 (16:44 +0100)
also clean up code of DefaultProcessCommands and fix it's Javadoc which was out of sync with implementation

21 files changed:
server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java
server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java
server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java
server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java
server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java
server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java
server/sonar-process/src/main/java/org/sonar/process/Monitored.java
server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java
server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java
server/sonar-process/src/test/java/org/sonar/process/AllProcessesCommandsTest.java
server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java
server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java
server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java
server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java
server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java
server/sonar-search/src/main/java/org/sonar/search/SearchServer.java
server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java
server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java
server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java

index d519af478d318c709d0211be60cc99a681bb5d8c..89f5056750936f3125c3b80f96a18f251bc26860 100644 (file)
@@ -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();
   }
index 0d5c247d5671f713824949abbab11ec568439e7c..2978aba2dd661621a70301c25e21d363d832962d 100644 (file)
@@ -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
index a4e1bfd4b7f19e9161bd2257ec594b08399ebc78..9a9feeab2410041ec2124d153866283e5119ac9d 100644 (file)
@@ -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);
   }
index 5ae2edaaf1073fcc3d1938fb0b8c1e59c1567b23..d3523ed2ed423b4adbfd0d24a4ff2a39a8ef42be 100644 (file)
@@ -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);
       }
     }
   }
index ea25a399cfe987e82d64762f2a05e6fb9066012d..9b8a305a7f4b7ccc47302b52551eab2a99cb6e5b 100644 (file)
@@ -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);
       }
 
index e174984a88b2cb3fa7a3804a15425dfb325e973f..52f5bcfd9fd08360faf00fa809d891e8dd88bcac 100644 (file)
@@ -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
index 68ca4a9806321965ca662c02195acab1b0cfd536..0ef4413aa7577c325b246fa988842ae64d2ae43a 100644 (file)
@@ -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
index f7015ac42d8707d520ab1dc7ecee46ce942a0194..87a6b1f32c1935ebcee451c5d34ac2c55060f680 100644 (file)
@@ -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
index e1299f940922fc5dda48e02d89f93cd6de045538..f52f5b5f5df8a2ef31b810a5cf5b0ce06672849c 100644 (file)
  */
 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();
 
index d932511ed73e848fd3d25a1af173ea79fd6f258b..8968210526dbc577052dcd0c5855472eba0b50d2 100644 (file)
@@ -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();
index 625ab016e1dcc87385eb206b20af699caf49daf4..ad92121b8248ced747999776fba51d893a361b9e 100644 (file)
@@ -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();
   }
 
index b641ddbba5cc0d2c27c43c12546548c53b6e4414..89d07923427280a8c3d550dfe48b8e266875caa7 100644 (file)
@@ -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
index e8a62fc58b0e660fe2dffa0ad80d87073546be89..8e107af3ee1a29ff6bdbd2abfbecaf179cd63d92 100644 (file)
@@ -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;
     }
 
index 60cb57644f45eb5c3ce3b837b13a12a41fa8fa42..77e135163ef393ce7489338a3202e7bf61a38355 100644 (file)
@@ -88,7 +88,7 @@ public class HttpProcess implements Monitored {
   }
 
   @Override
-  public boolean isReady() {
+  public boolean isUp() {
     if (ready) {
       return true;
     }
index cb75808346f0c63d01c0a1ed51a94a37544d308a..3cf328eff4dd25a522d2e71633242df5d0c48a7a 100644 (file)
@@ -51,7 +51,7 @@ public class InfiniteTerminationProcess implements Monitored {
   }
 
   @Override
-  public boolean isReady() {
+  public boolean isUp() {
     return state == State.STARTED;
   }
 
index b3b3a5099cba369355e47995ddecbbe441ec83c7..9e9ab0485e991aec679b31f7d2c41433f197942f 100644 (file)
@@ -51,7 +51,7 @@ public class StandardProcess implements Monitored {
   }
 
   @Override
-  public boolean isReady() {
+  public boolean isUp() {
     return state == State.STARTED;
   }
 
index 013cae726b94fd893c57ee5bc053f514ff445856..0a7939abedf16ac53fd56465e6865bcdf884a7e5 100644 (file)
@@ -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))
index 065d0179c47452cd2946612239b7bec9be830195..5ce6cf13a0bcd8ce4731a5c4c907764a419ce87b 100644 (file)
@@ -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)
index 432dbae8ff92a2545f191c5c54c0666e2c5e5ddd..a656f9a56d561cd9b8f4a058fdac812b230aec2e 100644 (file)
@@ -66,7 +66,7 @@ class EmbeddedTomcat {
     }
   }
 
-  boolean isReady() {
+  boolean isUp() {
     if (webappContext == null) {
       return false;
     }
index c444ba2b6f532719654f265259d99faf8af004b3..4dda540667c91f05b61af6116040d6fb6b461168 100644 (file)
@@ -44,8 +44,8 @@ public class WebServer implements Monitored {
   }
 
   @Override
-  public boolean isReady() {
-    return tomcat.isReady();
+  public boolean isUp() {
+    return tomcat.isUp();
   }
 
   @Override
index 138b4d29dd72bb2f1a8d186c532e1d0dd612e6b8..00ee0486f59b215e82b2db7f37f5a543a38ef817 100644 (file)
@@ -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();