use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AsyncHttpClientRegistryTest method testRegisterIfNew.
@Test(groups = "standalone")
public void testRegisterIfNew() throws IOException {
try (AsyncHttpClient ahc = AsyncHttpClientFactory.getAsyncHttpClient()) {
try (AsyncHttpClient ahc2 = AsyncHttpClientFactory.getAsyncHttpClient()) {
Assert.assertNull(AsyncHttpClientRegistryImpl.getInstance().addOrReplace(TEST_AHC, ahc));
Assert.assertFalse(AsyncHttpClientRegistryImpl.getInstance().registerIfNew(TEST_AHC, ahc2));
Assert.assertTrue(AsyncHttpClientRegistryImpl.getInstance().get(TEST_AHC) == ahc);
Assert.assertNotNull(AsyncHttpClientRegistryImpl.getInstance().addOrReplace(TEST_AHC, ahc2));
Assert.assertTrue(AsyncHttpClientRegistryImpl.getInstance().get(TEST_AHC) == ahc2);
Assert.assertTrue(AsyncHttpClientRegistryImpl.getInstance().registerIfNew(TEST_AHC + 1, ahc));
Assert.assertTrue(AsyncHttpClientRegistryImpl.getInstance().get(TEST_AHC + 1) == ahc);
}
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AsyncHttpClientRegistryTest method testGetAndRegister.
@Test(groups = "standalone")
public void testGetAndRegister() throws IOException {
try (AsyncHttpClient ahc = AsyncHttpClientFactory.getAsyncHttpClient()) {
Assert.assertNull(AsyncHttpClientRegistryImpl.getInstance().get(TEST_AHC));
Assert.assertNull(AsyncHttpClientRegistryImpl.getInstance().addOrReplace(TEST_AHC, ahc));
Assert.assertNotNull(AsyncHttpClientRegistryImpl.getInstance().get(TEST_AHC));
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AsyncHttpObservableTest method testObserveMultiple.
@Test(groups = "standalone")
public void testObserveMultiple() {
final TestSubscriber<Response> tester = new TestSubscriber<>();
try (AsyncHttpClient client = asyncHttpClient()) {
Observable<Response> o1 = AsyncHttpObservable.observe(() -> client.prepareGet("http://gatling.io"));
Observable<Response> o2 = AsyncHttpObservable.observe(() -> client.prepareGet("http://www.wisc.edu").setFollowRedirect(true));
Observable<Response> o3 = AsyncHttpObservable.observe(() -> client.prepareGet("http://www.umn.edu").setFollowRedirect(true));
Observable<Response> all = Observable.merge(o1, o2, o3);
all.subscribe(tester);
tester.awaitTerminalEvent();
tester.assertTerminalEvent();
tester.assertNoErrors();
tester.assertCompleted();
List<Response> responses = tester.getOnNextEvents();
assertNotNull(responses);
assertEquals(responses.size(), 3);
for (Response response : responses) {
assertEquals(response.getStatusCode(), 200);
}
} catch (Exception e) {
Thread.currentThread().interrupt();
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class AsyncHttpSingleTest method testAbort.
@Test(groups = "standalone")
public void testAbort() throws Exception {
final TestSubscriber<Response> subscriber = new TestSubscriber<>();
try (AsyncHttpClient client = asyncHttpClient()) {
final Single<Response> underTest = AsyncHttpSingle.create(client.prepareGet("http://gatling.io"), () -> new AsyncCompletionHandlerBase() {
@Override
public State onStatusReceived(HttpResponseStatus status) {
return State.ABORT;
}
});
underTest.subscribe(subscriber);
subscriber.awaitTerminalEvent();
}
subscriber.assertTerminalEvent();
subscriber.assertNoErrors();
subscriber.assertCompleted();
subscriber.assertValue(null);
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class TextMessageTest method echoDoubleListenerText.
@Test(groups = "standalone", timeOut = 60000)
public void echoDoubleListenerText() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(2);
final AtomicReference<String> text = new AtomicReference<>("");
WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
text.set(message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
text.set(text.get() + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
websocket.sendMessage("ECHO");
latch.await();
assertEquals(text.get(), "ECHOECHO");
}
}
Aggregations