Merge pull request #762 from khatwaniNikhil/BAEL-418-Changes

Fixed Failing EchoTest
This commit is contained in:
Jim Kerak 2016-10-21 19:16:27 -04:00 committed by GitHub
commit a65bad7c1f
2 changed files with 24 additions and 9 deletions

View File

@ -1,14 +1,15 @@
package com.baeldung.java.nio.selector;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.Selector;
import java.nio.channels.SelectionKey;
import java.nio.ByteBuffer;
import java.io.IOException;
import java.util.Set;
import java.util.Iterator;
import java.net.InetSocketAddress;
import java.util.Set;
public class EchoServer {
@ -47,4 +48,15 @@ public class EchoServer {
}
}
}
}
public static Process start() throws IOException, InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = EchoServer.class.getCanonicalName();
ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp", classpath, className);
return builder.start();
}
}

View File

@ -2,17 +2,20 @@ package com.baeldung.java.nio.selector;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test;
public class EchoTest {
@Test
public void givenClient_whenServerEchosMessage_thenCorrect() {
public void givenClient_whenServerEchosMessage_thenCorrect() throws IOException, InterruptedException {
Process process = EchoServer.start();
EchoClient client = EchoClient.start();
String resp1 = client.sendMessage("hello");
String resp2 = client.sendMessage("world");
assertEquals("hello", resp1);
assertEquals("world", resp2);
process.destroy();
}
}