Search in sources :

Example 81 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTQueryPublisherTest method testHandleBadResponse.

@Test
public void testHandleBadResponse() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getNotOkResponse(500));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTQueryPublisher publisher = new RESTQueryPublisher(mockClient, "my/custom/query/url", "my/custom/result/url");
    publisher.send(new PubSubMessage("foo", "bar", Metadata.Signal.COMPLETE));
    verify(mockClient).preparePost("my/custom/query/url");
    verify(mockBuilder).setBody("{\"id\":\"foo\",\"sequence\":-1,\"content\":\"bar\",\"metadata\":{\"signal\":\"COMPLETE\",\"content\":\"my/custom/result/url\"}}");
    verify(mockBuilder).setHeader(RESTPublisher.CONTENT_TYPE, RESTPublisher.APPLICATION_JSON);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) RESTPubSubTest.getNotOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 82 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTQueryPublisherTest method testSendResultUrlPutInMetadataAckPreserved.

@Test
public void testSendResultUrlPutInMetadataAckPreserved() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getOkResponse(null));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTQueryPublisher publisher = new RESTQueryPublisher(mockClient, "my/custom/query/url", "my/custom/url");
    publisher.send(new PubSubMessage("foo", "bar", Metadata.Signal.ACKNOWLEDGE));
    verify(mockClient).preparePost("my/custom/query/url");
    verify(mockBuilder).setBody("{\"id\":\"foo\",\"sequence\":-1,\"content\":\"bar\",\"metadata\":{\"signal\":\"ACKNOWLEDGE\",\"content\":\"my/custom/url\"}}");
    verify(mockBuilder).setHeader(RESTPublisher.CONTENT_TYPE, RESTPublisher.APPLICATION_JSON);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) RESTPubSubTest.getNotOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 83 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTQueryPublisherTest method testSendResultUrlPutInMetadataCompletePreserved.

@Test
public void testSendResultUrlPutInMetadataCompletePreserved() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getOkResponse(null));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTPubSubConfig config = new RESTPubSubConfig("src/test/resources/test_config.yaml");
    config.set(RESTPubSubConfig.RESULT_URL, "my/custom/url");
    RESTQueryPublisher publisher = new RESTQueryPublisher(mockClient, "my/custom/query/url", "my/custom/result/url");
    publisher.send(new PubSubMessage("foo", "bar", Metadata.Signal.COMPLETE));
    verify(mockClient).preparePost("my/custom/query/url");
    verify(mockBuilder).setBody("{\"id\":\"foo\",\"sequence\":-1,\"content\":\"bar\",\"metadata\":{\"signal\":\"COMPLETE\",\"content\":\"my/custom/result/url\"}}");
    verify(mockBuilder).setHeader(RESTPublisher.CONTENT_TYPE, RESTPublisher.APPLICATION_JSON);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) RESTPubSubTest.getNotOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) Test(org.testng.annotations.Test)

Example 84 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTResultPublisherTest method testSendBadURL.

@Test(expectedExceptions = ClassCastException.class)
public void testSendBadURL() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getOkResponse(null));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTResultPublisher publisher = new RESTResultPublisher(mockClient);
    PubSubMessage message = new PubSubMessage("someId", "someContent", new Metadata(null, 88));
    publisher.send(message);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 85 with Response

use of org.asynchttpclient.Response in project bullet-core by yahoo.

the class RESTSubscriberTest method testGetMessages500.

@Test
public void testGetMessages500() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getNotOkResponse(500));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTPubSubConfig config = new RESTPubSubConfig("src/test/resources/test_config.yaml");
    RESTSubscriber subscriber = new RESTSubscriber(88, Arrays.asList("url", "anotherURL"), mockClient, 10);
    List<PubSubMessage> messages = subscriber.getMessages();
    Assert.assertEquals(messages.size(), 0);
}
Also used : Response(org.asynchttpclient.Response) RESTPubSubTest.getOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse) RESTPubSubTest.getNotOkResponse(com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Aggregations

Response (org.asynchttpclient.Response)142 Test (org.testng.annotations.Test)85 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)79 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)55 HttpServletResponse (javax.servlet.http.HttpServletResponse)42 BoundRequestBuilder (org.asynchttpclient.BoundRequestBuilder)32 Request (org.asynchttpclient.Request)29 IOException (java.io.IOException)21 Test (org.junit.Test)20 ExecutionException (java.util.concurrent.ExecutionException)16 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)14 RESTPubSubTest.getOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse)11 TimeoutException (java.util.concurrent.TimeoutException)11 RequestBuilder (org.asynchttpclient.RequestBuilder)11 UnitEvent (org.apache.druid.java.util.emitter.service.UnitEvent)10 RESTPubSubTest.getNotOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 Map (java.util.Map)9 AuthorizationException (org.apache.shiro.authz.AuthorizationException)9 TestUtils.createTempFile (org.asynchttpclient.test.TestUtils.createTempFile)9