Compare commits
16 Commits
gclc-socke
...
gclc-socke
| Author | SHA1 | Date | |
|---|---|---|---|
| 07645d7c0c | |||
| 99c0c9008b | |||
| 26265ad7e6 | |||
| 092883f4c3 | |||
| 25904c907d | |||
| ae55ebea29 | |||
| e989aff2f4 | |||
| 2f0c03a73b | |||
| ff9ace1033 | |||
| ffa54af3be | |||
| 269704f5a2 | |||
| aecc18cc83 | |||
| 063cad61cd | |||
| 201b6ad366 | |||
| bf8d76750f | |||
| 17ac47f15e |
@@ -70,7 +70,7 @@ of Emmanuel Bigeon. -->
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>gclc-socket</artifactId>
|
<artifactId>gclc-socket</artifactId>
|
||||||
<version>1.1.6</version>
|
<version>1.1.7</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<url>http://www.bigeon.fr/emmanuel</url>
|
<url>http://www.bigeon.fr/emmanuel</url>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -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.6</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
@@ -98,6 +98,6 @@ of Emmanuel Bigeon. -->
|
|||||||
<description>Socket implementation of GCLC</description>
|
<description>Socket implementation of GCLC</description>
|
||||||
<scm>
|
<scm>
|
||||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>gclc-socket-1.1.6</tag>
|
<tag>gclc-socket-1.1.7</tag>
|
||||||
</scm>
|
</scm>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -96,8 +96,7 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
while (!socket.isClosed()) {
|
while (!socket.isClosed()) {
|
||||||
while (!socket.isClosed() &&
|
while (!socket.isClosed() && !consoleManager.available()) {
|
||||||
!consoleManager.available()) {
|
|
||||||
waitASec();
|
waitASec();
|
||||||
}
|
}
|
||||||
if (socket.isClosed()) {
|
if (socket.isClosed()) {
|
||||||
@@ -192,7 +191,8 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
// Create the streams
|
// Create the streams
|
||||||
runSokectServer();
|
runSokectServer();
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
LOGGER.log(Level.SEVERE,
|
LOGGER.severe("Communication error between client and server"); //$NON-NLS-1$
|
||||||
|
LOGGER.log(Level.FINE,
|
||||||
"Communication error between client and server", e); //$NON-NLS-1$
|
"Communication error between client and server", e); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,12 +229,20 @@ public class SocketConsoleApplicationShell implements Runnable, AutoCloseable {
|
|||||||
LOGGER.log(Level.FINE,
|
LOGGER.log(Level.FINE,
|
||||||
"Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$
|
"Socket closed with exception (probably due to server interruption)", //$NON-NLS-1$
|
||||||
e);
|
e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
LOGGER.info("Closing client"); //$NON-NLS-1$
|
LOGGER.info("Closing client"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
runnable.setRunning(false);
|
runnable.setRunning(false);
|
||||||
consoleManager.type(applicationShutdown);
|
try {
|
||||||
consoleManager.close();
|
consoleManager.type(applicationShutdown);
|
||||||
|
consoleManager.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.warning("Unable to close application correctly"); //$NON-NLS-1$
|
||||||
|
LOGGER.log(Level.FINE, "Application closing caused an exception", //$NON-NLS-1$
|
||||||
|
e);
|
||||||
|
}
|
||||||
LOGGER.info("Closing Server"); //$NON-NLS-1$
|
LOGGER.info("Closing Server"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,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();
|
||||||
@@ -295,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>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>gclc</artifactId>
|
<artifactId>gclc</artifactId>
|
||||||
<version>1.3.4-SNAPSHOT</version>
|
<version>1.3.7-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<url>http://www.bigeon.fr/emmanuel</url>
|
<url>http://www.bigeon.fr/emmanuel</url>
|
||||||
<properties>
|
<properties>
|
||||||
@@ -53,7 +53,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>fr.bigeon</groupId>
|
<groupId>fr.bigeon</groupId>
|
||||||
<artifactId>ebigeon-config</artifactId>
|
<artifactId>ebigeon-config</artifactId>
|
||||||
<version>1.7.0</version>
|
<version>1.7.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
@@ -83,6 +83,6 @@
|
|||||||
<scm>
|
<scm>
|
||||||
|
|
||||||
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
<developerConnection>scm:git:gogs@git.code.bigeon.net:emmanuel/gclc.git</developerConnection>
|
||||||
<tag>HEAD</tag>
|
<tag>gclc-1.3.5</tag>
|
||||||
</scm>
|
</scm>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -167,7 +167,8 @@ public abstract class ParametrizedCommand extends Command {
|
|||||||
/** @param param the parameter
|
/** @param param the parameter
|
||||||
* @param stringParameter the string parameter type
|
* @param stringParameter the string parameter type
|
||||||
* @param needed if the parameter is needed
|
* @param needed if the parameter is needed
|
||||||
* @throws InvalidParameterException if the new definition is invalid */
|
* @throws InvalidParameterException if the new definition is invalid
|
||||||
|
* @deprecated since 1.3.3 */
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private void checkParam(String param, boolean stringParameter,
|
private void checkParam(String param, boolean stringParameter,
|
||||||
boolean needed) throws InvalidParameterException {
|
boolean needed) throws InvalidParameterException {
|
||||||
|
|||||||
@@ -53,6 +53,61 @@ import java.util.logging.Logger;
|
|||||||
* @author Emmanuel Bigeon */
|
* @author Emmanuel Bigeon */
|
||||||
public class ReadingRunnable implements Runnable {
|
public class ReadingRunnable implements Runnable {
|
||||||
|
|
||||||
|
/** The runnable to wait for notification on an object
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
private final class ToWaitRunnable implements Runnable {
|
||||||
|
/** The Object */
|
||||||
|
private final Object obj;
|
||||||
|
/** The locking object */
|
||||||
|
private final Object start;
|
||||||
|
/** The message */
|
||||||
|
private final String message;
|
||||||
|
/** The started status */
|
||||||
|
private boolean started = false;
|
||||||
|
|
||||||
|
/** @param obj the object to lock on
|
||||||
|
* @param start the object to notify when ready to wait
|
||||||
|
* @param message the message to wait for */
|
||||||
|
public ToWaitRunnable(Object obj, Object start,
|
||||||
|
String message) {
|
||||||
|
this.obj = obj;
|
||||||
|
this.start = start;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("synthetic-access")
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
synchronized (obj) {
|
||||||
|
synchronized (start) {
|
||||||
|
started = true;
|
||||||
|
start.notify();
|
||||||
|
}
|
||||||
|
while (isRunning()) {
|
||||||
|
try {
|
||||||
|
obj.wait();
|
||||||
|
if (delivering.equals(message)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.log(Level.SEVERE,
|
||||||
|
THREAD_INTERRUPTION_EXCEPTION, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return the started */
|
||||||
|
public boolean isStarted() {
|
||||||
|
synchronized (start) {
|
||||||
|
return started;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The thread intteruption logging message */
|
||||||
|
private static final String THREAD_INTERRUPTION_EXCEPTION = "Thread interruption exception."; //$NON-NLS-1$
|
||||||
/** The closed pipe message */
|
/** The closed pipe message */
|
||||||
private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$
|
private static final String CLOSED_PIPE = "Closed pipe"; //$NON-NLS-1$
|
||||||
/** Wait timeout */
|
/** Wait timeout */
|
||||||
@@ -79,6 +134,7 @@ public class ReadingRunnable implements Runnable {
|
|||||||
* The lock
|
* The lock
|
||||||
*/
|
*/
|
||||||
private final Object messageBlockerLock = new Object();
|
private final Object messageBlockerLock = new Object();
|
||||||
|
/** The message being delivered */
|
||||||
private String delivering;
|
private String delivering;
|
||||||
|
|
||||||
/** @param reader the input to read from */
|
/** @param reader the input to read from */
|
||||||
@@ -146,7 +202,7 @@ public class ReadingRunnable implements Runnable {
|
|||||||
try {
|
try {
|
||||||
lock.wait(TIMEOUT);
|
lock.wait(TIMEOUT);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$
|
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
|
||||||
e);
|
e);
|
||||||
}
|
}
|
||||||
if (messages.isEmpty() && !running) {
|
if (messages.isEmpty() && !running) {
|
||||||
@@ -218,36 +274,18 @@ public class ReadingRunnable implements Runnable {
|
|||||||
}
|
}
|
||||||
final Object obj = messageBlocker.get(message);
|
final Object obj = messageBlocker.get(message);
|
||||||
final Object start = new Object();
|
final Object start = new Object();
|
||||||
Thread th = new Thread(new Runnable() {
|
ToWaitRunnable waitRunn = new ToWaitRunnable(obj, start, message);
|
||||||
|
Thread th = new Thread(waitRunn);
|
||||||
@SuppressWarnings("synthetic-access")
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
synchronized (obj) {
|
|
||||||
synchronized (start) {
|
|
||||||
start.notify();
|
|
||||||
}
|
|
||||||
while (isRunning()) {
|
|
||||||
try {
|
|
||||||
obj.wait();
|
|
||||||
if (delivering.equals(message)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LOGGER.log(Level.SEVERE,
|
|
||||||
"Thread interruption exception.", e); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
synchronized (start) {
|
synchronized (start) {
|
||||||
th.start();
|
th.start();
|
||||||
try {
|
while (!waitRunn.isStarted()) {
|
||||||
start.wait();
|
try {
|
||||||
} catch (InterruptedException e) {
|
start.wait(TIMEOUT);
|
||||||
LOGGER.log(Level.SEVERE, "Thread interruption exception.", //$NON-NLS-1$
|
} catch (InterruptedException e) {
|
||||||
e);
|
LOGGER.log(Level.SEVERE, THREAD_INTERRUPTION_EXCEPTION,
|
||||||
|
e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return th;
|
return th;
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import static org.junit.Assert.assertFalse;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@@ -55,7 +56,6 @@ import fr.bigeon.gclc.exception.CommandRunExceptionType;
|
|||||||
import fr.bigeon.gclc.exception.InvalidCommandName;
|
import fr.bigeon.gclc.exception.InvalidCommandName;
|
||||||
import fr.bigeon.gclc.i18n.Messages;
|
import fr.bigeon.gclc.i18n.Messages;
|
||||||
import fr.bigeon.gclc.manager.ConsoleManager;
|
import fr.bigeon.gclc.manager.ConsoleManager;
|
||||||
import fr.bigeon.gclc.manager.SystemConsoleManager;
|
|
||||||
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
import fr.bigeon.gclc.manager.PipedConsoleManager;
|
||||||
|
|
||||||
/** Test class for ConsoleApplication
|
/** Test class for ConsoleApplication
|
||||||
@@ -70,9 +70,14 @@ public class ConsoleApplicationTest {
|
|||||||
/** Test the base of a console application */
|
/** Test the base of a console application */
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
ConsoleTestApplication app = new ConsoleTestApplication(
|
|
||||||
new SystemConsoleManager());
|
try (PipedConsoleManager manager = new PipedConsoleManager()) {
|
||||||
app.exit();
|
ConsoleTestApplication app = new ConsoleTestApplication(manager);
|
||||||
|
app.exit();
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail("System Console Manager failed");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -156,7 +161,10 @@ public class ConsoleApplicationTest {
|
|||||||
manager.type("exit");
|
manager.type("exit");
|
||||||
th.join();
|
th.join();
|
||||||
|
|
||||||
} catch (IOException | InvalidCommandName | InterruptedException e) {
|
} catch (IOException | InvalidCommandName |
|
||||||
|
|
||||||
|
InterruptedException e) {
|
||||||
|
|
||||||
assertNull(e);
|
assertNull(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright Bigeon Emmanuel (2014)
|
||||||
|
*
|
||||||
|
* emmanuel@bigeon.fr
|
||||||
|
*
|
||||||
|
* This software is a computer program whose purpose is to
|
||||||
|
* provide a generic framework for console applications.
|
||||||
|
*
|
||||||
|
* This software is governed by the CeCILL license under French law and
|
||||||
|
* abiding by the rules of distribution of free software. You can use,
|
||||||
|
* modify and/or redistribute the software under the terms of the CeCILL
|
||||||
|
* license as circulated by CEA, CNRS and INRIA at the following URL
|
||||||
|
* "http://www.cecill.info".
|
||||||
|
*
|
||||||
|
* As a counterpart to the access to the source code and rights to copy,
|
||||||
|
* modify and redistribute granted by the license, users are provided only
|
||||||
|
* with a limited warranty and the software's author, the holder of the
|
||||||
|
* economic rights, and the successive licensors have only limited
|
||||||
|
* liability.
|
||||||
|
*
|
||||||
|
* In this respect, the user's attention is drawn to the risks associated
|
||||||
|
* with loading, using, modifying and/or developing or reproducing the
|
||||||
|
* software by the user in light of its specific status of free software,
|
||||||
|
* that may mean that it is complicated to manipulate, and that also
|
||||||
|
* therefore means that it is reserved for developers and experienced
|
||||||
|
* professionals having in-depth computer knowledge. Users are therefore
|
||||||
|
* encouraged to load and test the software's suitability as regards their
|
||||||
|
* requirements in conditions enabling the security of their systems and/or
|
||||||
|
* data to be ensured and, more generally, to use and operate it in the
|
||||||
|
* same conditions as regards security.
|
||||||
|
*
|
||||||
|
* The fact that you are presently reading this means that you have had
|
||||||
|
* knowledge of the CeCILL license and that you accept its terms.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* gclc:fr.bigeon.gclc.manager.ReadingRunnableTest.java
|
||||||
|
* Created on: Dec 6, 2016
|
||||||
|
*/
|
||||||
|
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 java.nio.charset.Charset;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/** <p>
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Emmanuel Bigeon */
|
||||||
|
public class ReadingRunnableTest {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
@Before
|
||||||
|
public void setUp() {}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getMessage()}. */
|
||||||
|
@Test
|
||||||
|
public final void testGetMessage() {
|
||||||
|
BufferedReader reader = null;
|
||||||
|
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
|
runnable.setRunning(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
runnable.getMessage();
|
||||||
|
fail("reading from closed runnable");
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertNotNull(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#hasMessage()}. */
|
||||||
|
@Test
|
||||||
|
public final void testHasMessage() {
|
||||||
|
|
||||||
|
BufferedReader reader = null;
|
||||||
|
ReadingRunnable runnable = new ReadingRunnable(reader);
|
||||||
|
runnable.setRunning(false);
|
||||||
|
|
||||||
|
try {
|
||||||
|
runnable.getMessage();
|
||||||
|
fail("reading from closed runnable");
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertNotNull(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Test method for
|
||||||
|
* {@link fr.bigeon.gclc.manager.ReadingRunnable#getWaitForDelivery(java.lang.String)}.
|
||||||
|
*
|
||||||
|
* @throws InterruptedException */
|
||||||
|
@Test
|
||||||
|
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("msg");
|
||||||
|
|
||||||
|
out.write(Charset.forName("UTF-8")
|
||||||
|
.encode("msg" + System.lineSeparator()).array());
|
||||||
|
|
||||||
|
Thread th2 = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
runnable.getMessage();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, "get");
|
||||||
|
th2.start();
|
||||||
|
try {
|
||||||
|
th.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
assertNull(e);
|
||||||
|
}
|
||||||
|
runnable.setRunning(false);
|
||||||
|
out.close();
|
||||||
|
} catch (IOException e1) {
|
||||||
|
assertNull(e1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -65,13 +65,12 @@ public class SystemConsoleManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
public final void testPrompt() {
|
public final void testPrompt() {
|
||||||
|
|
||||||
try {
|
final String test = "test";
|
||||||
PipedOutputStream outStream = new PipedOutputStream();
|
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||||
InputStream in = new PipedInputStream(outStream);
|
InputStream in = new PipedInputStream(outStream);
|
||||||
final PrintStream out = new PrintStream(outStream);
|
final PrintStream out = new PrintStream(outStream);
|
||||||
final String test = "test";
|
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
||||||
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
in, Charset.forName("UTF-8"))) {
|
||||||
in, Charset.forName("UTF-8"));
|
|
||||||
|
|
||||||
Thread th = new Thread(new Runnable() {
|
Thread th = new Thread(new Runnable() {
|
||||||
|
|
||||||
@@ -95,10 +94,18 @@ public class SystemConsoleManagerTest {
|
|||||||
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#setPrompt(java.lang.String)}. */
|
* {@link fr.bigeon.gclc.manager.SystemConsoleManager#setPrompt(java.lang.String)}. */
|
||||||
@Test
|
@Test
|
||||||
public final void testSetPrompt() {
|
public final void testSetPrompt() {
|
||||||
SystemConsoleManager manager = new SystemConsoleManager();
|
try (PipedOutputStream outStream = new PipedOutputStream();
|
||||||
String prt = "++";
|
InputStream in = new PipedInputStream(outStream);
|
||||||
manager.setPrompt(prt);
|
final PrintStream out = new PrintStream(outStream);
|
||||||
assertEquals(prt, manager.getPrompt());
|
SystemConsoleManager manager = new SystemConsoleManager(System.out,
|
||||||
|
in, Charset.forName("UTF-8"))) {
|
||||||
|
|
||||||
|
String prt = "++";
|
||||||
|
manager.setPrompt(prt);
|
||||||
|
assertEquals(prt, manager.getPrompt());
|
||||||
|
} catch (IOException e) {
|
||||||
|
assertNull(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test method for
|
/** Test method for
|
||||||
|
|||||||
Reference in New Issue
Block a user