Merge pull request #762 from khatwaniNikhil/BAEL-418-Changes
Fixed Failing EchoTest
This commit is contained in:
commit
a65bad7c1f
|
@ -1,14 +1,15 @@
|
||||||
package com.baeldung.java.nio.selector;
|
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.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
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.util.Iterator;
|
||||||
import java.net.InetSocketAddress;
|
import java.util.Set;
|
||||||
|
|
||||||
public class EchoServer {
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -2,17 +2,20 @@ package com.baeldung.java.nio.selector;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class EchoTest {
|
public class EchoTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClient_whenServerEchosMessage_thenCorrect() {
|
public void givenClient_whenServerEchosMessage_thenCorrect() throws IOException, InterruptedException {
|
||||||
|
Process process = EchoServer.start();
|
||||||
EchoClient client = EchoClient.start();
|
EchoClient client = EchoClient.start();
|
||||||
String resp1 = client.sendMessage("hello");
|
String resp1 = client.sendMessage("hello");
|
||||||
String resp2 = client.sendMessage("world");
|
String resp2 = client.sendMessage("world");
|
||||||
assertEquals("hello", resp1);
|
assertEquals("hello", resp1);
|
||||||
assertEquals("world", resp2);
|
assertEquals("world", resp2);
|
||||||
|
process.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue