diff --git a/gclc-socket/pom.xml b/gclc-socket/pom.xml index 221fa58..29834bb 100644 --- a/gclc-socket/pom.xml +++ b/gclc-socket/pom.xml @@ -81,7 +81,7 @@ of Emmanuel Bigeon. --> fr.bigeon gclc - 1.3.3 + 1.3.4-SNAPSHOT fr.bigeon diff --git a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java index 4ebdff3..e95ae53 100644 --- a/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java +++ b/gclc-socket/src/main/java/fr/bigeon/gclc/socket/SocketConsoleApplicationShell.java @@ -240,7 +240,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable { consoleManager.close(); } catch (IOException e) { LOGGER.warning("Unable to close application correctly"); //$NON-NLS-1$ - LOGGER.log(Level.FINE, "Application closing caused an exception", + LOGGER.log(Level.FINE, "Application closing caused an exception", //$NON-NLS-1$ e); } LOGGER.info("Closing Server"); //$NON-NLS-1$ @@ -271,17 +271,15 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable { Thread th = new Thread(cc, "ClientComm"); //$NON-NLS-1$ th.start(); if (autoClose) { - communicateOnce(socket, in); + communicateOnce(in); } else { - communicateLoop(socket, in); + communicateLoop(in); } } - /** @param socket the socket - * @param in the input from the client + /** @param in the input from the client * @throws IOException if the communication failed */ - private void communicateOnce(Socket socket, - BufferedReader in) throws IOException { + private void communicateOnce(BufferedReader in) throws IOException { ReadingRunnable reading = new ReadingRunnable(in); Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$ th.start(); @@ -303,11 +301,9 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable { } } - /** @param socket the socket - * @param in the input from the client + /** @param in the input from the client * @throws IOException if the communication failed */ - private void communicateLoop(Socket socket, - BufferedReader in) throws IOException { + private void communicateLoop(BufferedReader in) throws IOException { ReadingRunnable reading = new ReadingRunnable(in); Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$ th.start(); diff --git a/gclc-swt/pom.xml b/gclc-swt/pom.xml index 10fd9e2..13c7795 100644 --- a/gclc-swt/pom.xml +++ b/gclc-swt/pom.xml @@ -51,7 +51,7 @@ fr.bigeon gclc - 1.3.3 + 1.3.4-SNAPSHOT fr.bigeon diff --git a/gclc/src/test/java/fr/bigeon/gclc/manager/ReadingRunnableTest.java b/gclc/src/test/java/fr/bigeon/gclc/manager/ReadingRunnableTest.java index 0d319bc..15f991d 100644 --- a/gclc/src/test/java/fr/bigeon/gclc/manager/ReadingRunnableTest.java +++ b/gclc/src/test/java/fr/bigeon/gclc/manager/ReadingRunnableTest.java @@ -39,21 +39,23 @@ package fr.bigeon.gclc.manager; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; import org.junit.Before; import org.junit.Test; -/** - *

+/**

* TODO * - * @author Emmanuel Bigeon - * - */ + * @author Emmanuel Bigeon */ public class ReadingRunnableTest { /** @@ -61,11 +63,10 @@ public class ReadingRunnableTest { @Before public void setUp() {} - /** - * Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}. - */ + /** Test method for + * {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}. */ @Test - public final void testGetMessage(){ + public final void testGetMessage() { BufferedReader reader = null; ReadingRunnable runnable = new ReadingRunnable(reader); runnable.setRunning(false); @@ -79,11 +80,10 @@ public class ReadingRunnableTest { } - /** - * Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}. - */ + /** Test method for + * {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}. */ @Test - public final void testHasMessage(){ + public final void testHasMessage() { BufferedReader reader = null; ReadingRunnable runnable = new ReadingRunnable(reader); @@ -97,11 +97,53 @@ public class ReadingRunnableTest { } } - /** - * Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}. - */ + /** Test method for + * {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}. + * + * @throws InterruptedException */ @Test - public final void testGetWaitForDelivery(){ + public final void testGetWaitForDelivery() throws InterruptedException { + try (PipedOutputStream out = new PipedOutputStream(); + InputStream piped = new PipedInputStream(out); + BufferedReader reader = new BufferedReader( + new InputStreamReader(piped, "UTF-8"))) { + final ReadingRunnable runnable = new ReadingRunnable(reader); + Thread th0 = new Thread(runnable, "read"); + th0.start(); + Thread th = runnable.getWaitForDelivery(""); + + final Object start = new Object(); + + Thread th2 = new Thread(new Runnable() { + + @Override + public void run() { + synchronized (start) { + start.notify(); + } + try { + runnable.getMessage(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }, "get"); + synchronized (start) { + th2.start(); + start.wait(); + } + runnable.interrupt(); + try { + th.join(); + } catch (InterruptedException e) { + assertNull(e); + } + runnable.setRunning(false); + out.close(); + } catch (IOException e1) { + assertNull(e1); + } } }