Removed thread sleeping lock

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
Emmanuel Bigeon 2018-10-15 09:10:31 -04:00
parent 93589c750e
commit 6a7d0b11a0
5 changed files with 33 additions and 12 deletions

View File

@ -51,7 +51,7 @@
<dependency> <dependency>
<groupId>net.bigeon</groupId> <groupId>net.bigeon</groupId>
<artifactId>smu</artifactId> <artifactId>smu</artifactId>
<version>1.0.4</version> <version>1.0.5</version>
</dependency> </dependency>
</dependencies> </dependencies>
<parent> <parent>

View File

@ -118,7 +118,10 @@ public class ConsoleTestApplication {
public void execute(final ConsoleOutput out, final ConsoleInput in, public void execute(final ConsoleOutput out, final ConsoleInput in,
final String... args) throws CommandRunException { final String... args) throws CommandRunException {
try { try {
Thread.sleep(2000); Object obj = new Object();
synchronized (obj) {
obj.wait(2000);
}
output.println("Test command ran fine"); output.println("Test command ran fine");
} catch (IOException | InterruptedException e) { } catch (IOException | InterruptedException e) {
throw new CommandRunException("manager closed", e); throw new CommandRunException("manager closed", e);

View File

@ -90,7 +90,10 @@ public class PluggableConsoleInputTest {
} }
try { try {
Thread.sleep(100); Object obj = new Object();
synchronized (obj) {
obj.wait(100);
}
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -112,7 +115,10 @@ public class PluggableConsoleInputTest {
@Override @Override
public void run() { public void run() {
try { try {
Thread.sleep(200); Object obj = new Object();
synchronized (obj) {
obj.wait(200);
}
} catch (final InterruptedException e) { } catch (final InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -162,8 +168,11 @@ public class PluggableConsoleInputTest {
}); });
th.start(); th.start();
while (!input.isPrompting()) { Object obj = new Object();
Thread.sleep(10); synchronized (obj) {
while (!input.isPrompting()) {
obj.wait(10);
}
} }
input.connect(pis, out); input.connect(pis, out);
@ -176,7 +185,7 @@ public class PluggableConsoleInputTest {
public void run() { public void run() {
try { try {
input.prompt("Test", 5000); input.prompt("Test", 5000);
// fail("Prompt should io"); // fail("Prompt should io");
} catch (final IOException e) { } catch (final IOException e) {
// ok // ok
ref.set(e); ref.set(e);
@ -184,8 +193,10 @@ public class PluggableConsoleInputTest {
} }
}); });
th2.start(); th2.start();
while (!input.isPrompting()) { synchronized (obj) {
Thread.sleep(10); while (!input.isPrompting()) {
obj.wait(10);
}
} }
input.close(); input.close();

View File

@ -76,7 +76,6 @@ public class SocketConsoleApplicationTest {
public void testIntegration() throws IOException, InterruptedException { public void testIntegration() throws IOException, InterruptedException {
Thread server; Thread server;
server = TestServer.getServer(); server = TestServer.getServer();
Thread.sleep(1000);
final String hostName = "127.0.0.1"; final String hostName = "127.0.0.1";
final int portNumber = 3300; final int portNumber = 3300;
@ -128,11 +127,9 @@ public class SocketConsoleApplicationTest {
} }
assertEquals("Application exit command should close connection", 4, i); assertEquals("Application exit command should close connection", 4, i);
} }
Thread.sleep(100);
TestServer.closeServer(); TestServer.closeServer();
server.join(); server.join();
server = TestServer.getServer(); server = TestServer.getServer();
Thread.sleep(1000);
try (Socket kkSocket = new Socket(hostName, portNumber); try (Socket kkSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true); PrintWriter out = new PrintWriter(kkSocket.getOutputStream(), true);

View File

@ -90,6 +90,16 @@ public class TestServer {
} }
}); });
th.start(); th.start();
try {
Object waiting = new Object();
synchronized (waiting) {
while (!input.isPrompting()) {
waiting.wait(50);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} }
return SHELL; return SHELL;
} }