Search in sources :

Example 1 with PubSubMessage

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

the class RESTResultPublisherTest method testSend.

@Test
public void testSend() 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, "custom/url"));
    publisher.send(message);
    verify(mockClient).preparePost("custom/url");
    verify(mockBuilder).setBody("{\"id\":\"someId\",\"sequence\":-1,\"content\":\"someContent\",\"metadata\":{\"signal\":null,\"content\":\"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) 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 2 with PubSubMessage

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

the class RESTSubscriberTest method testGetMessages.

@Test
public void testGetMessages() throws Exception {
    PubSubMessage responseData = new PubSubMessage("someID", "someContent");
    CompletableFuture<Response> response = getOkFuture(getOkResponse(responseData.asJSON()));
    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(), 2);
    Assert.assertEquals(messages.get(0).asJSON(), "{\"id\":\"someID\",\"sequence\":-1,\"content\":\"someContent\",\"metadata\":null}");
}
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 3 with PubSubMessage

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

the class RESTSubscriberTest method testGetMessages204.

@Test
public void testGetMessages204() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getNotOkResponse(204));
    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 4 with PubSubMessage

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

the class RESTSubscriberTest method testGetMessagesDoesNotThrow.

@Test
public void testGetMessagesDoesNotThrow() throws Exception {
    // PubSubMessage will throw an error when it fails to parse this into a PubSubMessage
    CompletableFuture<Response> response = getOkFuture(getOkResponse("thisCannotBeTurnedIntoAPubSubMessage"));
    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 5 with PubSubMessage

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

the class RESTSubscriberTest method testMinWait.

@Test
public void testMinWait() throws Exception {
    PubSubMessage responseData = new PubSubMessage("someID", "someContent");
    CompletableFuture<Response> response = getOkFuture(getOkResponse(responseData.asJSON()));
    BoundRequestBuilder mockBuilder = mockBuilderWith(response);
    AsyncHttpClient mockClient = mockClientWith(mockBuilder);
    RESTSubscriber subscriber = new RESTSubscriber(88, Arrays.asList("url", "anotherURL"), mockClient, 1000);
    // First response should give content (2 events since we have 2 endpoints in the config)
    List<PubSubMessage> messages = subscriber.getMessages();
    Assert.assertEquals(messages.size(), 2);
    // Second and third response should give nothing since the wait duration hasn't passed
    messages = subscriber.getMessages();
    Assert.assertEquals(messages.size(), 0);
    messages = subscriber.getMessages();
    Assert.assertEquals(messages.size(), 0);
    // After waiting a second it should return messages again
    Thread.sleep(3000);
    messages = subscriber.getMessages();
    Assert.assertEquals(messages.size(), 2);
}
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

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