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>
<groupId>net.bigeon</groupId>
<artifactId>smu</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
</dependencies>
<parent>

View File

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

View File

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

View File

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

View File

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