Search in sources :

Example 36 with Metadata

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

the class QueryBoltTest method testRegularMetaTupleIgnored.

@Test
public void testRegularMetaTupleIgnored() {
    CustomCollector collector = new CustomCollector();
    TestQueryBolt bolt = new TestQueryBolt(new BulletStormConfig());
    ComponentUtils.prepare(bolt, collector);
    Map<String, Querier> queries = bolt.getQueries();
    queries.put("foo", null);
    Tuple meta = makeIDTuple(Type.METADATA_TUPLE, "foo", new Metadata(Signal.ACKNOWLEDGE, null));
    bolt.execute(meta);
    Assert.assertTrue(queries.containsKey("foo"));
}
Also used : Querier(com.yahoo.bullet.querying.Querier) CustomCollector(com.yahoo.bullet.storm.testing.CustomCollector) Metadata(com.yahoo.bullet.pubsub.Metadata) Tuple(org.apache.storm.tuple.Tuple) TupleUtils.makeIDTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeIDTuple) Test(org.testng.annotations.Test)

Example 37 with Metadata

use of com.yahoo.bullet.pubsub.Metadata 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 38 with Metadata

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

the class DRPCResultPublisher method send.

@Override
public void send(PubSubMessage message) throws PubSubException {
    Metadata metadata = message.getMetadata();
    // Remove the content
    String content = metadata.getContent().toString();
    log.debug("Removing metadata {} for result {}@{}: {}", content, message.getId(), message.getSequence(), message.getContent());
    metadata.setContent(null);
    String serializedMessage = message.asJSON();
    Tuple tuple = new DRPCTuple(new Values(serializedMessage, content));
    // This sends the message through DRPC and not to the collector but it acks or fails accordingly.
    bolt.execute(tuple);
    if (!collector.isAcked()) {
        throw new PubSubException("Message not acked. Unable to send message through DRPC:\n " + serializedMessage);
    }
    // Otherwise, we're good to proceed
    collector.reset();
}
Also used : Metadata(com.yahoo.bullet.pubsub.Metadata) Values(org.apache.storm.tuple.Values) PubSubException(com.yahoo.bullet.pubsub.PubSubException) DRPCTuple(com.yahoo.bullet.storm.drpc.utils.DRPCTuple) DRPCTuple(com.yahoo.bullet.storm.drpc.utils.DRPCTuple) Tuple(org.apache.storm.tuple.Tuple)

Example 39 with Metadata

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

the class FilterBoltTest method testFilteringLatency.

@Test
public void testFilteringLatency() {
    config = new BulletStormConfig();
    // Don't use the overridden aggregation default size but turn on built in metrics
    config.set(BulletStormConfig.TOPOLOGY_METRICS_BUILT_IN_ENABLE, true);
    collector = new CustomCollector();
    CustomTopologyContext context = new CustomTopologyContext();
    bolt = new FilterBolt(TopologyConstants.RECORD_COMPONENT, config);
    ComponentUtils.prepare(new HashMap<>(), bolt, context, collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeFieldFilterQuery("bar"), METADATA);
    bolt.execute(query);
    BulletRecord record = RecordBox.get().add("field", "foo").getRecord();
    long start = System.currentTimeMillis();
    IntStream.range(0, 10).mapToObj(i -> makeRecordTuple(record, System.currentTimeMillis())).forEach(bolt::execute);
    long end = System.currentTimeMillis();
    double actualLatecy = context.getDoubleMetric(TopologyConstants.LATENCY_METRIC);
    Assert.assertTrue(actualLatecy <= end - start);
}
Also used : Arrays(java.util.Arrays) GREATER_THAN(com.yahoo.bullet.parsing.Clause.Operation.GREATER_THAN) GROUP(com.yahoo.bullet.parsing.Aggregation.Type.GROUP) COUNT(com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.COUNT) TopK(com.yahoo.bullet.aggregations.TopK) Test(org.testng.annotations.Test) RecordBox(com.yahoo.bullet.result.RecordBox) ErrorType(com.yahoo.sketches.frequencies.ErrorType) EQUALS(com.yahoo.bullet.parsing.Clause.Operation.EQUALS) PROBABILITY_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.PROBABILITY_FIELD) QueryUtils.makeProjectionQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionQuery) QueryUtils.makeSimpleAggregationFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeSimpleAggregationFilterQuery) Collections.singletonList(java.util.Collections.singletonList) CustomCollector(com.yahoo.bullet.storm.testing.CustomCollector) Pair(org.apache.commons.lang3.tuple.Pair) TupleUtils.makeTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeTuple) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Metadata(com.yahoo.bullet.pubsub.Metadata) Mockito.doReturn(org.mockito.Mockito.doReturn) GroupData(com.yahoo.bullet.aggregations.grouping.GroupData) QueryUtils.makeAggregationQuery(com.yahoo.bullet.parsing.QueryUtils.makeAggregationQuery) ComponentUtils(com.yahoo.bullet.storm.testing.ComponentUtils) BulletRecord(com.yahoo.bullet.record.BulletRecord) BeforeMethod(org.testng.annotations.BeforeMethod) FilterUtils.getFieldFilter(com.yahoo.bullet.parsing.FilterUtils.getFieldFilter) Fields(org.apache.storm.tuple.Fields) CustomTopologyContext(com.yahoo.bullet.storm.testing.CustomTopologyContext) SlidingRecord(com.yahoo.bullet.windowing.SlidingRecord) QueryUtils.makeProjectionFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeProjectionFilterQuery) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) NOT_EQUALS(com.yahoo.bullet.parsing.Clause.Operation.NOT_EQUALS) TupleUtils.makeRawTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeRawTuple) RateLimitError(com.yahoo.bullet.querying.RateLimitError) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) Querier(com.yahoo.bullet.querying.Querier) QueryUtils.makeFieldFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeFieldFilterQuery) List(java.util.List) Distribution(com.yahoo.bullet.aggregations.Distribution) NEGATIVE_INFINITY_START(com.yahoo.bullet.aggregations.sketches.QuantileSketch.NEGATIVE_INFINITY_START) BulletConfig(com.yahoo.bullet.common.BulletConfig) AdditionalAnswers.returnsElementsOf(org.mockito.AdditionalAnswers.returnsElementsOf) Window(com.yahoo.bullet.parsing.Window) Optional(java.util.Optional) OR(com.yahoo.bullet.parsing.Clause.Operation.OR) QueryUtils.makeFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeFilterQuery) END_EXCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.END_EXCLUSIVE) TupleUtils(com.yahoo.bullet.storm.testing.TupleUtils) IntStream(java.util.stream.IntStream) TopKTest(com.yahoo.bullet.aggregations.TopKTest) SerializerDeserializer(com.yahoo.bullet.common.SerializerDeserializer) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) SEPARATOR(com.yahoo.bullet.aggregations.sketches.QuantileSketch.SEPARATOR) TestHelpers(com.yahoo.bullet.storm.testing.TestHelpers) ArrayList(java.util.ArrayList) Tuple(org.apache.storm.tuple.Tuple) Assert(org.testng.Assert) FilterUtils.makeClause(com.yahoo.bullet.parsing.FilterUtils.makeClause) CountDistinct(com.yahoo.bullet.aggregations.CountDistinct) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) TOP_K(com.yahoo.bullet.parsing.Aggregation.Type.TOP_K) COUNT_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.COUNT_FIELD) POSITIVE_INFINITY_END(com.yahoo.bullet.aggregations.sketches.QuantileSketch.POSITIVE_INFINITY_END) AND(com.yahoo.bullet.parsing.Clause.Operation.AND) Utils(org.apache.storm.utils.Utils) COUNT_DISTINCT(com.yahoo.bullet.parsing.Aggregation.Type.COUNT_DISTINCT) CustomOutputFieldsDeclarer(com.yahoo.bullet.storm.testing.CustomOutputFieldsDeclarer) START_INCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.START_INCLUSIVE) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest) RAW(com.yahoo.bullet.parsing.Aggregation.Type.RAW) DISTRIBUTION(com.yahoo.bullet.parsing.Aggregation.Type.DISTRIBUTION) QueryUtils.makeGroupFilterQuery(com.yahoo.bullet.parsing.QueryUtils.makeGroupFilterQuery) RANGE_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.RANGE_FIELD) TupleUtils.makeIDTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeIDTuple) BulletRecord(com.yahoo.bullet.record.BulletRecord) CustomCollector(com.yahoo.bullet.storm.testing.CustomCollector) CustomTopologyContext(com.yahoo.bullet.storm.testing.CustomTopologyContext) TupleUtils.makeTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeTuple) TupleUtils.makeRawTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeRawTuple) Tuple(org.apache.storm.tuple.Tuple) TupleUtils.makeIDTuple(com.yahoo.bullet.storm.testing.TupleUtils.makeIDTuple) Test(org.testng.annotations.Test) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) TopKTest(com.yahoo.bullet.aggregations.TopKTest) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest)

Example 40 with Metadata

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

the class DRPCQuerySubscriberTest method testReadingFromSpout.

@Test
public void testReadingFromSpout() throws Exception {
    // The MockDRPCSpout makes messages adds 2 zero based sequences with id foo and given string content.
    // It adds to metadata a string JSON with id: "fake" + foo, host: "testHost" and port: a total count of messages.
    injectedMockSpout.addMessageParts("foo", "{}", "{'duration': 2000}");
    injectedMockSpout.addMessageParts("bar", "{}");
    PubSubMessage actual = subscriber.receive();
    Assert.assertEquals(actual.getId(), "foo");
    Assert.assertEquals(actual.getSequence(), 0);
    Assert.assertEquals(actual.getContent(), "{}");
    Assert.assertFalse(actual.hasSignal());
    Assert.assertTrue(actual.hasMetadata());
    Metadata metadata = actual.getMetadata();
    Assert.assertEquals(metadata.getContent(), makeReturnInfo("fakefoo", "testHost", 0));
    actual = subscriber.receive();
    Assert.assertEquals(actual.getId(), "foo");
    Assert.assertEquals(actual.getSequence(), 1);
    Assert.assertEquals(actual.getContent(), "{'duration': 2000}");
    Assert.assertFalse(actual.hasSignal());
    Assert.assertTrue(actual.hasMetadata());
    metadata = actual.getMetadata();
    Assert.assertEquals(metadata.getContent(), makeReturnInfo("fakefoo", "testHost", 1));
    actual = subscriber.receive();
    Assert.assertEquals(actual.getId(), "bar");
    Assert.assertEquals(actual.getSequence(), 0);
    Assert.assertEquals(actual.getContent(), "{}");
    Assert.assertFalse(actual.hasSignal());
    Assert.assertTrue(actual.hasMetadata());
    metadata = actual.getMetadata();
    Assert.assertEquals(metadata.getContent(), makeReturnInfo("fakebar", "testHost", 2));
}
Also used : PubSubMessage(com.yahoo.bullet.pubsub.PubSubMessage) Metadata(com.yahoo.bullet.pubsub.Metadata) Test(org.testng.annotations.Test)

Aggregations

Metadata (com.yahoo.bullet.pubsub.Metadata)45 Test (org.testng.annotations.Test)35 Tuple (org.apache.storm.tuple.Tuple)31 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)25 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)25 TopKTest (com.yahoo.bullet.aggregations.TopKTest)25 BulletRecord (com.yahoo.bullet.record.BulletRecord)25 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)22 PubSubMessage (com.yahoo.bullet.pubsub.PubSubMessage)11 GroupOperation (com.yahoo.bullet.aggregations.grouping.GroupOperation)7 RateLimitError (com.yahoo.bullet.querying.RateLimitError)7 ArrayList (java.util.ArrayList)6 BulletConfig (com.yahoo.bullet.common.BulletConfig)5 Meta (com.yahoo.bullet.result.Meta)5 CountDistinct (com.yahoo.bullet.aggregations.CountDistinct)4 Distribution (com.yahoo.bullet.aggregations.Distribution)4 TopK (com.yahoo.bullet.aggregations.TopK)4 GroupData (com.yahoo.bullet.aggregations.grouping.GroupData)4 COUNT (com.yahoo.bullet.aggregations.grouping.GroupOperation.GroupOperationType.COUNT)4 COUNT_FIELD (com.yahoo.bullet.aggregations.sketches.QuantileSketch.COUNT_FIELD)4