Search in sources :

Example 16 with PubSubMessage

use of com.yahoo.bullet.pubsub.PubSubMessage 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 17 with PubSubMessage

use of com.yahoo.bullet.pubsub.PubSubMessage 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 18 with PubSubMessage

use of com.yahoo.bullet.pubsub.PubSubMessage 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 19 with PubSubMessage

use of com.yahoo.bullet.pubsub.PubSubMessage 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)

Example 20 with PubSubMessage

use of com.yahoo.bullet.pubsub.PubSubMessage in project bullet-core by yahoo.

the class RESTSubscriber method getMessages.

@Override
public List<PubSubMessage> getMessages() throws PubSubException {
    List<PubSubMessage> messages = new ArrayList<>();
    long currentTime = System.currentTimeMillis();
    if (currentTime - lastRequest <= minWait) {
        return messages;
    }
    lastRequest = currentTime;
    for (String url : urls) {
        try {
            log.debug("Getting messages from url: ", url);
            Response response = client.prepareGet(url).execute().get();
            int statusCode = response.getStatusCode();
            if (statusCode == RESTPubSub.OK_200) {
                messages.add(PubSubMessage.fromJSON(response.getResponseBody()));
            } else if (statusCode != RESTPubSub.NO_CONTENT_204) {
                // NO_CONTENT_204 indicates there are no new messages - anything else indicates a problem
                log.error("Http call failed with status code {} and response {}.", statusCode, response);
            }
        } catch (Exception e) {
            log.error("Http call failed with error: ", e);
        }
    }
    return messages;
}
Also used : Response(org.asynchttpclient.Response) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) ArrayList(java.util.ArrayList) PubSubException(com.yahoo.bullet.pubsub.PubSubException) IOException(java.io.IOException)

Aggregations

PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)30 Test (org.testng.annotations.Test)22 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)14 Response (org.asynchttpclient.Response)14 Metadata (com.yahoo.bullet.pubsub.Metadata)11 RESTPubSubTest.getOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getOkResponse)10 BoundRequestBuilder (org.asynchttpclient.BoundRequestBuilder)10 RESTPubSubTest.getNotOkResponse (com.yahoo.bullet.pubsub.rest.RESTPubSubTest.getNotOkResponse)8 Tuple (org.apache.storm.tuple.Tuple)4 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)4 PubSubException (com.yahoo.bullet.pubsub.PubSubException)3 ArrayList (java.util.ArrayList)3 TupleUtils.makeTuple (com.yahoo.bullet.storm.testing.TupleUtils.makeTuple)2 IOException (java.io.IOException)2 List (java.util.List)1 Values (org.apache.storm.tuple.Values)1 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)1 DefaultAsyncHttpClientConfig (org.asynchttpclient.DefaultAsyncHttpClientConfig)1