Search in sources :

Example 21 with PubSubMessage

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

the class ResultBoltTest method testExecuteMessagesAreSent.

@Test
public void testExecuteMessagesAreSent() {
    List<PubSubMessage> expected = asList(new PubSubMessage("42", "This is a PubSubMessage", new Metadata()), new PubSubMessage("43", "This is also a PubSubMessage", new Metadata()), new PubSubMessage("44", "This is still a PubSubMessage", new Metadata()));
    List<Tuple> tuples = new ArrayList<>();
    expected.forEach(m -> tuples.add(makeTuple(m.getId(), m.getContent(), 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).getContent(), expected.get(i).getContent());
        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) Metadata(com.yahoo.bullet.pubsub.Metadata) 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 22 with PubSubMessage

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

the class DRPCQueryResultPubscriberTest method testReadingOkResponse.

@Test(timeOut = 5000L)
public void testReadingOkResponse() throws Exception {
    PubSubMessage expected = new PubSubMessage("foo", "response");
    CompletableFuture<Response> response = getOkFuture(getOkResponse(expected.asJSON()));
    AsyncHttpClient mockClient = mockClientWith(response);
    pubscriber.setClient(mockClient);
    pubscriber.send(new PubSubMessage("foo", "bar"));
    // This is async (but practically still very fast since we mocked the response), so need a timeout.
    PubSubMessage actual = fetchAsync().get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getId(), expected.getId());
    Assert.assertEquals(actual.getContent(), expected.getContent());
}
Also used : Response(org.asynchttpclient.Response) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 23 with PubSubMessage

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

the class DRPCQueryResultPubscriberTest method testReadingNullResponse.

@Test(timeOut = 5000L)
public void testReadingNullResponse() throws Exception {
    CompletableFuture<Response> response = getOkFuture(null);
    AsyncHttpClient mockClient = mockClientWith(response);
    pubscriber.setClient(mockClient);
    pubscriber.send(new PubSubMessage("foo", "bar"));
    // This is async (but practically still very fast since we mocked the response), so need a timeout.
    PubSubMessage actual = fetchAsync().get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getId(), "foo");
    Assert.assertEquals(actual.getContent(), CANNOT_REACH_DRPC.asJSONClip());
}
Also used : Response(org.asynchttpclient.Response) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 24 with PubSubMessage

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

the class DRPCQueryResultPubscriberTest method testReadingNotOkResponse.

@Test(timeOut = 5000L)
public void testReadingNotOkResponse() throws Exception {
    CompletableFuture<Response> response = getOkFuture(getNotOkResponse(500));
    AsyncHttpClient mockClient = mockClientWith(response);
    pubscriber.setClient(mockClient);
    pubscriber.send(new PubSubMessage("foo", "bar"));
    // This is async (but practically still very fast since we mocked the response), so need a timeout.
    PubSubMessage actual = fetchAsync().get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getId(), "foo");
    Assert.assertEquals(actual.getContent(), CANNOT_REACH_DRPC.asJSONClip());
}
Also used : Response(org.asynchttpclient.Response) PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 25 with PubSubMessage

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

the class DRPCQueryResultPubscriberTest method testException.

@Test(timeOut = 5000L)
public void testException() throws Exception {
    // This will hit a non-existent url and fail, testing our exceptions. Our connect and retry is low so even if
    // block the full amount, it's still fast.
    pubscriber.send(new PubSubMessage("foo", "bar"));
    PubSubMessage actual = fetchAsync().get();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getId(), "foo");
    Assert.assertEquals(actual.getContent(), CANNOT_REACH_DRPC.asJSONClip());
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) 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