use of io.reactivex.netty.protocol.http.client.HttpClientResponse in project ribbon by Netflix.
the class NettyClientTest method testConnectTimeout.
@Test
public void testConnectTimeout() throws Exception {
LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient(DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1"));
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("http://www.google.com:81/");
Observable<HttpClientResponse<ByteBuf>> observable = observableClient.submit(new Server("www.google.com", 81), request);
ObserverWithLatch<HttpClientResponse<ByteBuf>> observer = new ObserverWithLatch<HttpClientResponse<ByteBuf>>();
observable.subscribe(observer);
observer.await();
assertNotNull(observer.error);
assertTrue(observer.error instanceof io.netty.channel.ConnectTimeoutException);
}
use of io.reactivex.netty.protocol.http.client.HttpClientResponse in project ribbon by Netflix.
the class NettyClientTest method testContext.
@Test
public void testContext() throws Exception {
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/context");
LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient();
String requestId = "xyz";
ContextsContainerImpl contextsContainer = new ContextsContainerImpl(new MapBackedKeySupplier());
contextsContainer.addContext("Context1", "value1");
RxContexts.DEFAULT_CORRELATOR.onNewServerRequest(requestId, contextsContainer);
Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(new Server(host, port), request);
final AtomicReference<ContextsContainer> responseContext = new AtomicReference<ContextsContainer>();
String requestIdSent = response.flatMap(new Func1<HttpClientResponse<ByteBuf>, Observable<ByteBuf>>() {
@Override
public Observable<ByteBuf> call(HttpClientResponse<ByteBuf> t1) {
return t1.getContent();
}
}).map(new Func1<ByteBuf, String>() {
@Override
public String call(ByteBuf t1) {
String requestId = RxContexts.DEFAULT_CORRELATOR.getRequestIdForClientRequest();
responseContext.set(RxContexts.DEFAULT_CORRELATOR.getContextForClientRequest(requestId));
return t1.toString(Charset.defaultCharset());
}
}).toBlocking().single();
assertEquals(requestId, requestIdSent);
assertEquals("value1", responseContext.get().getContext("Context1"));
}
use of io.reactivex.netty.protocol.http.client.HttpClientResponse in project ribbon by Netflix.
the class NettyClientTest method testUnexpectedResponse.
@Test
public void testUnexpectedResponse() throws Exception {
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/throttle");
LoadBalancingHttpClient<ByteBuf, ByteBuf> client = RibbonTransport.newHttpClient();
Observable<HttpClientResponse<ByteBuf>> responseObservable = client.submit(new Server(host, port), request);
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
final CountDownLatch latch = new CountDownLatch(1);
responseObservable.subscribe(new Action1<HttpClientResponse<ByteBuf>>() {
@Override
public void call(HttpClientResponse<ByteBuf> t1) {
latch.countDown();
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable t1) {
error.set(t1);
latch.countDown();
}
});
latch.await();
assertTrue(error.get() instanceof ClientException);
ClientException ce = (ClientException) error.get();
assertTrue(ce.getErrorType() == ClientException.ErrorType.SERVER_THROTTLED);
}
use of io.reactivex.netty.protocol.http.client.HttpClientResponse in project ribbon by Netflix.
the class NettyClientTest method testSubmitToAbsoluteURI.
@Test
public void testSubmitToAbsoluteURI() throws Exception {
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/person");
LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient();
// final List<Person> result = Lists.newArrayList();
Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(request);
Person person = getPersonObservable(response).toBlocking().single();
assertEquals(EmbeddedResources.defaultPerson, person);
// need to sleep to wait until connection is released
final HttpClientListener listener = observableClient.getListener();
assertEquals(1, listener.getConnectionCount());
assertEquals(1, listener.getPoolAcquires());
waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {
@Override
public Boolean call() {
return listener.getPoolReleases() == 1;
}
});
}
use of io.reactivex.netty.protocol.http.client.HttpClientResponse in project ribbon by Netflix.
the class NettyClientTest method testObservable.
@Test
public void testObservable() throws Exception {
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(SERVICE_URI + "testAsync/person");
LoadBalancingHttpClient<ByteBuf, ByteBuf> observableClient = RibbonTransport.newHttpClient();
Observable<HttpClientResponse<ByteBuf>> response = observableClient.submit(request);
Person person = getPersonObservable(response).toBlocking().single();
assertEquals(EmbeddedResources.defaultPerson, person);
final HttpClientListener listener = observableClient.getListener();
assertEquals(1, listener.getPoolAcquires());
assertEquals(1, listener.getConnectionCount());
waitUntilTrueOrTimeout(1000, new Func0<Boolean>() {
@Override
public Boolean call() {
return listener.getPoolReleases() == 1;
}
});
}
Aggregations