Search in sources :

Example 1 with MyUDPClient

use of com.netflix.ribbon.transport.netty.MyUDPClient in project ribbon by Netflix.

the class UdpClientTest method testUdpClientTimeout.

@Test
public void testUdpClientTimeout() throws Exception {
    int port = choosePort();
    UdpServer<DatagramPacket, DatagramPacket> server = new HelloUdpServer(port, 5000).createServer();
    server.start();
    BaseLoadBalancer lb = new BaseLoadBalancer();
    Server myServer = new Server("localhost", port);
    lb.setServersList(Lists.newArrayList(myServer));
    MyUDPClient client = new MyUDPClient(lb, DefaultClientConfigImpl.getClientConfigWithDefaultValues());
    try {
        String response = client.submit("Is there anybody out there?").map(new Func1<DatagramPacket, String>() {

            @Override
            public String call(DatagramPacket datagramPacket) {
                return datagramPacket.content().toString(Charset.defaultCharset());
            }
        }).toBlocking().first();
        fail("Exception expected");
    } catch (Exception e) {
        assertTrue(e.getCause() instanceof TimeoutException);
        assertEquals(1, client.getLoadBalancerContext().getServerStats(myServer).getSuccessiveConnectionFailureCount());
    } finally {
        server.shutdown();
    }
}
Also used : MyUDPClient(com.netflix.ribbon.transport.netty.MyUDPClient) Server(com.netflix.loadbalancer.Server) UdpServer(io.reactivex.netty.protocol.udp.server.UdpServer) DatagramPacket(io.netty.channel.socket.DatagramPacket) BaseLoadBalancer(com.netflix.loadbalancer.BaseLoadBalancer) TimeoutException(java.util.concurrent.TimeoutException) SocketException(java.net.SocketException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

BaseLoadBalancer (com.netflix.loadbalancer.BaseLoadBalancer)1 Server (com.netflix.loadbalancer.Server)1 MyUDPClient (com.netflix.ribbon.transport.netty.MyUDPClient)1 DatagramPacket (io.netty.channel.socket.DatagramPacket)1 UdpServer (io.reactivex.netty.protocol.udp.server.UdpServer)1 SocketException (java.net.SocketException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1