use of com.yahoo.bullet.pubsub.PubSubMessage in project bullet-storm by yahoo.
the class LoopBoltTest method testMessagesAreLooped.
@Test
public void testMessagesAreLooped() {
List<PubSubMessage> expected = asList(new PubSubMessage("42", Metadata.Signal.KILL), new PubSubMessage("43", Metadata.Signal.COMPLETE), new PubSubMessage("44", (Metadata.Signal) null));
List<Tuple> tuples = new ArrayList<>();
expected.forEach(m -> tuples.add(makeTuple(m.getId(), m.getMetadata())));
for (int i = 0; i < tuples.size(); i++) {
bolt.execute(tuples.get(i));
Assert.assertEquals(publisher.getSent().get(i).getId(), expected.get(i).getId());
Assert.assertEquals(publisher.getSent().get(i).getMetadata(), expected.get(i).getMetadata());
Assert.assertTrue(collector.wasNthAcked(tuples.get(i), i + 1));
Assert.assertEquals(collector.getAckedCount(), i + 1);
}
}
use of com.yahoo.bullet.pubsub.PubSubMessage in project bullet-storm by yahoo.
the class QuerySpoutTest method testSignalOnlyMessagesAreSentOnTheMetadataStream.
@Test
public void testSignalOnlyMessagesAreSentOnTheMetadataStream() {
// Add messages to be received from subscriber
PubSubMessage messageA = new PubSubMessage("42", Metadata.Signal.KILL);
PubSubMessage messageB = new PubSubMessage("43", Metadata.Signal.COMPLETE);
PubSubMessage messageC = new PubSubMessage("44", null, new Metadata());
subscriber.addMessages(messageA, messageB, messageC);
Assert.assertEquals(subscriber.getReceived().size(), 0);
Assert.assertEquals(emitter.getEmitted().size(), 0);
spout.nextTuple();
spout.nextTuple();
spout.nextTuple();
Assert.assertEquals(subscriber.getReceived().size(), 3);
Assert.assertEquals(subscriber.getReceived().get(0), messageA);
Assert.assertEquals(subscriber.getReceived().get(1), messageB);
Assert.assertEquals(subscriber.getReceived().get(2), messageC);
Assert.assertEquals(emitter.getEmitted().size(), 3);
Tuple emittedFirst = TupleUtils.makeTuple(TupleClassifier.Type.METADATA_TUPLE, messageA.getId(), messageA.getMetadata());
Tuple emittedSecond = TupleUtils.makeTuple(TupleClassifier.Type.METADATA_TUPLE, messageB.getId(), messageB.getMetadata());
Tuple emittedThird = TupleUtils.makeTuple(TupleClassifier.Type.METADATA_TUPLE, messageC.getId(), messageC.getMetadata());
Assert.assertTrue(emitter.wasTupleEmittedTo(emittedFirst, TopologyConstants.METADATA_STREAM));
Assert.assertTrue(emitter.wasTupleEmittedTo(emittedSecond, TopologyConstants.METADATA_STREAM));
Assert.assertTrue(emitter.wasTupleEmittedTo(emittedThird, TopologyConstants.METADATA_STREAM));
Assert.assertTrue(emitter.wasNthEmitted(emittedFirst, 1));
Assert.assertTrue(emitter.wasNthEmitted(emittedSecond, 2));
Assert.assertTrue(emitter.wasNthEmitted(emittedThird, 3));
}
use of com.yahoo.bullet.pubsub.PubSubMessage in project bullet-storm by yahoo.
the class QuerySpoutTest method testNextTupleMessagesAreReceivedAndTupleIsEmitted.
@Test
public void testNextTupleMessagesAreReceivedAndTupleIsEmitted() {
// Add messages to be received from subscriber
PubSubMessage messageA = new PubSubMessage("42", "This is a PubSubMessage", new Metadata());
PubSubMessage messageB = new PubSubMessage("43", "This is also a PubSubMessage", new Metadata());
subscriber.addMessages(messageA, messageB);
Assert.assertEquals(subscriber.getReceived().size(), 0);
Assert.assertEquals(emitter.getEmitted().size(), 0);
// subscriber.receive() -> messageA
spout.nextTuple();
Assert.assertEquals(subscriber.getReceived().size(), 1);
Assert.assertEquals(subscriber.getReceived().get(0), messageA);
Tuple emittedFirst = TupleUtils.makeTuple(TupleClassifier.Type.QUERY_TUPLE, messageA.getId(), messageA.getContent(), messageA.getMetadata());
Assert.assertEquals(emitter.getEmitted().size(), 1);
Assert.assertTrue(emitter.wasNthEmitted(emittedFirst, 1));
// subscriber.receive() -> messageB
spout.nextTuple();
Assert.assertEquals(subscriber.getReceived().size(), 2);
Assert.assertEquals(subscriber.getReceived().get(0), messageA);
Assert.assertEquals(subscriber.getReceived().get(1), messageB);
Tuple emittedSecond = TupleUtils.makeTuple(TupleClassifier.Type.QUERY_TUPLE, messageB.getId(), messageB.getContent(), messageB.getMetadata());
Assert.assertEquals(emitter.getEmitted().size(), 2);
Assert.assertTrue(emitter.wasNthEmitted(emittedFirst, 1));
Assert.assertTrue(emitter.wasNthEmitted(emittedSecond, 2));
}
use of com.yahoo.bullet.pubsub.PubSubMessage 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);
}
use of com.yahoo.bullet.pubsub.PubSubMessage in project bullet-core by yahoo.
the class RESTQueryPublisherTest method testException.
@Test(timeOut = 5000L)
public void testException() throws Exception {
// This will hit a non-existent url and fail, testing our exceptions
AsyncHttpClientConfig clientConfig = new DefaultAsyncHttpClientConfig.Builder().setConnectTimeout(100).setMaxRequestRetry(1).setReadTimeout(-1).setRequestTimeout(-1).build();
AsyncHttpClient client = new DefaultAsyncHttpClient(clientConfig);
AsyncHttpClient spyClient = spy(client);
RESTQueryPublisher publisher = new RESTQueryPublisher(spyClient, "http://this/does/not/exist:8080", "my/custom/result/url");
publisher.send(new PubSubMessage("foo", "bar"));
verify(spyClient).preparePost("http://this/does/not/exist:8080");
}
Aggregations