Fix the non delivery of Bye message

Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
2016-12-05 23:51:50 -05:00
parent c27872de94
commit 5d25971b56
12 changed files with 189 additions and 34 deletions

View File

@@ -259,8 +259,8 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
* @throws IOException if the communication failed */
private void communicate(final Socket socket, final PrintWriter writer,
BufferedReader in) throws IOException {
Thread th = new Thread(new OutputForwardRunnable(writer, socket),
"ClientComm"); //$NON-NLS-1$
OutputForwardRunnable cc = new OutputForwardRunnable(writer, socket);
Thread th = new Thread(cc, "ClientComm"); //$NON-NLS-1$
th.start();
if (autoClose) {
communicateOnce(socket, in);
@@ -322,7 +322,14 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
}
String ln = reading.getMessage();
if (ln.equals(close)) {
Thread wait = consoleManager.getWaitForDelivery("Bye."); //$NON-NLS-1$
consoleManager.println("Bye."); //$NON-NLS-1$
try {
wait.join();
} catch (InterruptedException e) {
LOGGER.warning("The Bye wait was interrupted."); //$NON-NLS-1$
LOGGER.log(Level.FINE, "An interruption occured", e); //$NON-NLS-1$
}
return false;
}
// Pass command to application

View File

@@ -85,9 +85,10 @@ public class SocketConsoleApplicationTest {
new InputStreamReader(kkSocket.getInputStream()));) {
String fromServer;
int i = 0;
int i = -1;
String[] cmds = {"help", "toto", "test", "bye"};
while ((fromServer = in.readLine()) != null) {
i++;
LOGGER.fine("Server: \n" + fromServer);
if (fromServer.equals("Bye.")) {
break;
@@ -105,7 +106,6 @@ public class SocketConsoleApplicationTest {
LOGGER.fine("Client: " + fromUser);
out.println(fromUser);
}
i++;
}
assertEquals(4, i);
} catch (final IOException e) {