Search in sources :

Example 6 with TcpServer

use of org.spf4j.io.tcp.TcpServer in project spf4j by zolyfarkas.

the class TcpServerTest method testTimeout.

@Test(expected = java.net.SocketException.class, timeout = 60000)
public void testTimeout() throws IOException, InterruptedException {
    String testSite = "10.10.10.10";
    ForkJoinPool pool = new ForkJoinPool(1024);
    try (TcpServer server = new TcpServer(pool, new ProxyClientHandler(HostAndPort.fromParts(testSite, 80), null, null, 10000, 5000), 1978, 10)) {
        server.startAsync().awaitRunning();
        // results in a socket exception after 5 seconds
        readfromSite("http://localhost:1978");
        Assert.fail("Should timeout");
    }
}
Also used : ProxyClientHandler(org.spf4j.io.tcp.proxy.ProxyClientHandler) TcpServer(org.spf4j.io.tcp.TcpServer) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Aggregations

ForkJoinPool (java.util.concurrent.ForkJoinPool)6 Test (org.junit.Test)6 TcpServer (org.spf4j.io.tcp.TcpServer)6 ProxyClientHandler (org.spf4j.io.tcp.proxy.ProxyClientHandler)6 IOException (java.io.IOException)2 AbstractRunnable (org.spf4j.base.AbstractRunnable)2 ByteBuffer (java.nio.ByteBuffer)1 Selector (java.nio.channels.Selector)1 SocketChannel (java.nio.channels.SocketChannel)1 ExecutorService (java.util.concurrent.ExecutorService)1 ClientHandler (org.spf4j.io.tcp.ClientHandler)1 DeadlineAction (org.spf4j.io.tcp.DeadlineAction)1