From eb5e8f7774ee19a58c6796840ec9e71d67bb5a1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 9 Mar 2016 11:06:15 +0100 Subject: [PATCH] SONAR-7435 rename state when process is done starting from ready to up also clean up code of DefaultProcessCommands and fix it's Javadoc which was out of sync with implementation --- .../main/java/org/sonar/ce/app/CeServer.java | 4 +- .../java/org/sonar/ce/app/CeServerTest.java | 16 +-- .../org/sonar/process/monitor/Monitor.java | 2 +- .../org/sonar/process/monitor/ProcessRef.java | 10 +- .../sonar/process/monitor/MonitorTest.java | 28 ++--- .../sonar/process/AllProcessesCommands.java | 111 +++++++++++------- .../sonar/process/DefaultProcessCommands.java | 8 +- .../java/org/sonar/process/Monitored.java | 7 +- .../org/sonar/process/ProcessCommands.java | 22 ++-- .../org/sonar/process/ProcessEntryPoint.java | 8 +- .../process/AllProcessesCommandsTest.java | 32 ++--- .../process/DefaultProcessCommandsTest.java | 6 +- .../sonar/process/ProcessEntryPointTest.java | 4 +- .../org/sonar/process/test/HttpProcess.java | 2 +- .../test/InfiniteTerminationProcess.java | 2 +- .../sonar/process/test/StandardProcess.java | 2 +- .../java/org/sonar/search/SearchServer.java | 2 +- .../org/sonar/search/SearchServerTest.java | 2 +- .../org/sonar/server/app/EmbeddedTomcat.java | 2 +- .../java/org/sonar/server/app/WebServer.java | 4 +- .../sonar/server/app/EmbeddedTomcatTest.java | 6 +- 21 files changed, 149 insertions(+), 131 deletions(-) diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java index d519af478d3..89f50567509 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/app/CeServer.java @@ -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(); } diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java index 0d5c247d567..2978aba2dd6 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/app/CeServerTest.java @@ -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 diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java index a4e1bfd4b7f..9a9feeab241 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/Monitor.java @@ -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); } diff --git a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java index 5ae2edaaf10..d3523ed2ed4 100644 --- a/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java +++ b/server/sonar-process-monitor/src/main/java/org/sonar/process/monitor/ProcessRef.java @@ -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); } } } diff --git a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java index ea25a399cfe..9b8a305a7f4 100644 --- a/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java +++ b/server/sonar-process-monitor/src/test/java/org/sonar/process/monitor/MonitorTest.java @@ -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); } diff --git a/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java b/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java index e174984a88b..52f5bcfd9fd 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/AllProcessesCommands.java @@ -32,46 +32,50 @@ import static org.sonar.process.ProcessCommands.MAX_PROCESSES; * Process inter-communication to : * * - *

- * It relies on files shared by both processes. Following alternatives were considered but not selected : + *

+ * It relies on a single file accessed by all processes through a {@link MappedByteBuffer}.
+ * Following alternatives were considered but not selected : *

+ *

+ * + *

+ * The file contains {@link ProcessCommands#MAX_PROCESSES} groups of {@link #BYTE_LENGTH_FOR_ONE_PROCESS} bits. + * Each group of byte is used as follow: + *

+ *

*/ 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 : - * - * - * Description of ten bytes of each process : - * - */ - 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 diff --git a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java index 68ca4a98063..0ef4413aa75 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/DefaultProcessCommands.java @@ -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 diff --git a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java index f7015ac42d8..87a6b1f32c1 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Monitored.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Monitored.java @@ -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 diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java index e1299f94092..f52f5b5f5df 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessCommands.java @@ -19,33 +19,27 @@ */ package org.sonar.process; +import java.io.File; + /** * Process inter-communication to : * * - *

- * It relies on files shared by both processes. Following alternatives were considered but not selected : - *

+ * @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(); diff --git a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java index d932511ed73..8968210526d 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java +++ b/server/sonar-process/src/main/java/org/sonar/process/ProcessEntryPoint.java @@ -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(); diff --git a/server/sonar-process/src/test/java/org/sonar/process/AllProcessesCommandsTest.java b/server/sonar-process/src/test/java/org/sonar/process/AllProcessesCommandsTest.java index 625ab016e1d..ad92121b824 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/AllProcessesCommandsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/AllProcessesCommandsTest.java @@ -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(); } diff --git a/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java b/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java index b641ddbba5c..89d07923427 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/DefaultProcessCommandsTest.java @@ -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 diff --git a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java index e8a62fc58b0..8e107af3ee1 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/ProcessEntryPointTest.java @@ -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; } diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java index 60cb57644f4..77e135163ef 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java +++ b/server/sonar-process/src/test/java/org/sonar/process/test/HttpProcess.java @@ -88,7 +88,7 @@ public class HttpProcess implements Monitored { } @Override - public boolean isReady() { + public boolean isUp() { if (ready) { return true; } diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java index cb75808346f..3cf328eff4d 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java +++ b/server/sonar-process/src/test/java/org/sonar/process/test/InfiniteTerminationProcess.java @@ -51,7 +51,7 @@ public class InfiniteTerminationProcess implements Monitored { } @Override - public boolean isReady() { + public boolean isUp() { return state == State.STARTED; } diff --git a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java index b3b3a5099cb..9e9ab0485e9 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java +++ b/server/sonar-process/src/test/java/org/sonar/process/test/StandardProcess.java @@ -51,7 +51,7 @@ public class StandardProcess implements Monitored { } @Override - public boolean isReady() { + public boolean isUp() { return state == State.STARTED; } diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index 013cae726b9..0a7939abedf 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -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)) diff --git a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java index 065d0179c47..5ce6cf13a0b 100644 --- a/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java +++ b/server/sonar-search/src/test/java/org/sonar/search/SearchServerTest.java @@ -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) diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java b/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java index 432dbae8ff9..a656f9a56d5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java @@ -66,7 +66,7 @@ class EmbeddedTomcat { } } - boolean isReady() { + boolean isUp() { if (webappContext == null) { return false; } diff --git a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java index c444ba2b6f5..4dda540667c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java +++ b/server/sonar-server/src/main/java/org/sonar/server/app/WebServer.java @@ -44,8 +44,8 @@ public class WebServer implements Monitored { } @Override - public boolean isReady() { - return tomcat.isReady(); + public boolean isUp() { + return tomcat.isUp(); } @Override diff --git a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java index 138b4d29dd7..00ee0486f59 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/app/EmbeddedTomcatTest.java @@ -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(); -- 2.39.5