use of io.reactivex.netty.protocol.udp.server.UdpServer 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();
}
}
use of io.reactivex.netty.protocol.udp.server.UdpServer in project ribbon by Netflix.
the class UdpClientTest method testUdpClientWithoutTimeout.
@Test
public void testUdpClientWithoutTimeout() throws Exception {
int port = choosePort();
UdpServer<DatagramPacket, DatagramPacket> server = new HelloUdpServer(port, 0).createServer();
server.start();
BaseLoadBalancer lb = new BaseLoadBalancer();
lb.setServersList(Lists.newArrayList(new Server("localhost", port)));
RxClient<DatagramPacket, DatagramPacket> client = RibbonTransport.newUdpClient(lb, DefaultClientConfigImpl.getClientConfigWithDefaultValues());
try {
String response = client.connect().flatMap(new Func1<ObservableConnection<DatagramPacket, DatagramPacket>, Observable<DatagramPacket>>() {
@Override
public Observable<DatagramPacket> call(ObservableConnection<DatagramPacket, DatagramPacket> connection) {
connection.writeStringAndFlush("Is there anybody out there?");
return connection.getInput();
}
}).take(1).map(new Func1<DatagramPacket, String>() {
@Override
public String call(DatagramPacket datagramPacket) {
return datagramPacket.content().toString(Charset.defaultCharset());
}
}).toBlocking().first();
assertEquals(HelloUdpServer.WELCOME_MSG, response);
} finally {
server.shutdown();
}
}
Aggregations