Upgrade dependency on gclc, fixed test.
This commit is contained in:
parent
201b6ad366
commit
063cad61cd
@ -81,7 +81,7 @@ of Emmanuel Bigeon. -->
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.3.3</version>
|
<version>1.3.4-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
|
@ -240,7 +240,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
consoleManager.close();
|
consoleManager.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.warning("Unable to close application correctly"); //$NON-NLS-1$
|
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);
|
e);
|
||||||
}
|
}
|
||||||
LOGGER.info("Closing Server"); //$NON-NLS-1$
|
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$
|
Thread th = new Thread(cc, "ClientComm"); //$NON-NLS-1$
|
||||||
th.start();
|
th.start();
|
||||||
if (autoClose) {
|
if (autoClose) {
|
||||||
communicateOnce(socket, in);
|
communicateOnce(in);
|
||||||
} else {
|
} 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 */
|
* @throws IOException if the communication failed */
|
||||||
private void communicateOnce(Socket socket,
|
private void communicateOnce(BufferedReader in) throws IOException {
|
||||||
BufferedReader in) throws IOException {
|
|
||||||
ReadingRunnable reading = new ReadingRunnable(in);
|
ReadingRunnable reading = new ReadingRunnable(in);
|
||||||
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
||||||
th.start();
|
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 */
|
* @throws IOException if the communication failed */
|
||||||
private void communicateLoop(Socket socket,
|
private void communicateLoop(BufferedReader in) throws IOException {
|
||||||
BufferedReader in) throws IOException {
|
|
||||||
ReadingRunnable reading = new ReadingRunnable(in);
|
ReadingRunnable reading = new ReadingRunnable(in);
|
||||||
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
Thread th = new Thread(reading, "gclcToApp"); //$NON-NLS-1$
|
||||||
th.start();
|
th.start();
|
||||||
|
@ -51,7 +51,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.3.3</version>
|
<version>1.3.4-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
|
@ -39,21 +39,23 @@
|
|||||||
package fr.bigeon.gclc.manager;
|
package fr.bigeon.gclc.manager;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/** <p>
|
||||||
* <p>
|
|
||||||
* TODO
|
* TODO
|
||||||
*
|
*
|
||||||
* @author Emmanuel Bigeon
|
* @author Emmanuel Bigeon */
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ReadingRunnableTest {
|
public class ReadingRunnableTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,11 +63,10 @@ public class ReadingRunnableTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {}
|
public void setUp() {}
|
||||||
|
|
||||||
/**
|
/** Test method for
|
||||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}.
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}. */
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public final void testGetMessage(){
|
public final void testGetMessage() {
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
runnable.setRunning(false);
|
runnable.setRunning(false);
|
||||||
@ -79,11 +80,10 @@ public class ReadingRunnableTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Test method for
|
||||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}.
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}. */
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public final void testHasMessage(){
|
public final void testHasMessage() {
|
||||||
|
|
||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
ReadingRunnable runnable = new ReadingRunnable(reader);
|
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
@ -97,11 +97,53 @@ public class ReadingRunnableTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Test method for
|
||||||
* Test method for {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
||||||
*/
|
*
|
||||||
|
* @throws InterruptedException */
|
||||||
@Test
|
@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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user