Search in sources :

Example 6 with PubSubMessage

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

the class QuerySpout method nextTuple.

@Override
public void nextTuple() {
    PubSubMessage message = null;
    try {
        message = subscriber.receive();
    } catch (Exception e) {
        log.error(e.getMessage());
    }
    if (message == null) {
        Utils.sleep(1);
        return;
    }
    String content = message.getContent();
    // If no content, it's a metadata only message. Send it on the METADATA_STREAM.
    if (content == null) {
        collector.emit(METADATA_STREAM, new Values(message.getId(), message.getMetadata()), message.getId());
    } else {
        collector.emit(QUERY_STREAM, new Values(message.getId(), message.getContent(), message.getMetadata()), message.getId());
    }
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Values(org.apache.storm.tuple.Values) PubSubException(com.yahoo.bullet.pubsub.PubSubException)

Example 7 with PubSubMessage

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

the class DRPCQueryResultPubscriberTest method fetch.

private PubSubMessage fetch() {
    try {
        PubSubMessage message;
        do {
            message = pubscriber.receive();
            Thread.sleep(1);
        } while (message == null);
        return message;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) IOException(java.io.IOException)

Example 8 with PubSubMessage

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

the class DRPCResultPublisherTest method testFailing.

@Test(expectedExceptions = PubSubException.class)
public void testFailing() throws Exception {
    injectedMockBolt.setFailNumber(1);
    Assert.assertEquals(injectedMockBolt.getCount(), 0);
    PubSubMessage message = new PubSubMessage("foo", "{}", new Metadata(null, makeReturnInfo("a", "testHost", 80)));
    publisher.send(message);
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) Test(org.testng.annotations.Test)

Example 9 with PubSubMessage

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

the class DRPCResultPublisherTest method testSending.

@Test
public void testSending() throws Exception {
    Assert.assertEquals(injectedMockBolt.getCount(), 0);
    PubSubMessage message = new PubSubMessage("foo", "{}", new Metadata(null, makeReturnInfo("a", "testHost", 80)));
    publisher.send(message);
    Assert.assertEquals(injectedMockBolt.getCount(), 1);
    Assert.assertTrue(collector.isAcked());
    Assert.assertFalse(collector.isFailed());
    // Output is no longer present
    Assert.assertFalse(collector.haveOutput());
    Assert.assertNull(collector.reset());
    message = new PubSubMessage("bar", "{}", new Metadata(null, makeReturnInfo("b", "testHost", 80)));
    publisher.send(message);
    Assert.assertEquals(injectedMockBolt.getCount(), 2);
    Assert.assertTrue(collector.isAcked());
    Assert.assertFalse(collector.isFailed());
    Assert.assertFalse(collector.haveOutput());
    Assert.assertNull(collector.reset());
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) Test(org.testng.annotations.Test)

Example 10 with PubSubMessage

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

the class CustomSubscriber method receive.

@Override
public PubSubMessage receive() throws PubSubException {
    if (queue.isEmpty()) {
        throw new PubSubException("");
    }
    PubSubMessage message = queue.remove();
    received.add(message);
    return message;
}
Also used : PubSubException(com.yahoo.bullet.pubsub.PubSubException) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage)

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