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);
}
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}");
}
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);
}
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);
}
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);
}
Aggregations