Search in sources :

Example 11 with PubSubMessage

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);
    }
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) ArrayList(java.util.ArrayList) Tuple(org.apache.storm.tuple.Tuple) TupleUtils.makeTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeTuple) Test(org.testng.annotations.Test)

Example 12 with PubSubMessage

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));
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) Tuple(org.apache.storm.tuple.Tuple) Test(org.testng.annotations.Test)

Example 13 with PubSubMessage

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));
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) Tuple(org.apache.storm.tuple.Tuple) Test(org.testng.annotations.Test)

Example 14 with PubSubMessage

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);
}
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 15 with PubSubMessage

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");
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient) 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