Search in sources :

Example 1 with TupleUtils.makeTuple

use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.

the class FilterBoltTest method testTuplesCustomSource.

@Test
public void testTuplesCustomSource() {
    bolt = ComponentUtils.prepare(new FilterBolt("CustomSource", oneRecordConfig()), collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeFieldFilterQuery("b235gf23b"), METADATA);
    bolt.execute(query);
    BulletRecord record = RecordBox.get().add("field", "b235gf23b").getRecord();
    Tuple matching = TupleUtils.makeRawTuple("CustomSource", TopologyConstants.RECORD_STREAM, record);
    bolt.execute(matching);
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    BulletRecord anotherRecord = RecordBox.get().add("field", "wontmatch").getRecord();
    Tuple nonMatching = TupleUtils.makeRawTuple("CustomSource", TopologyConstants.RECORD_STREAM, anotherRecord);
    bolt.execute(nonMatching);
    Tuple expected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", record);
    Assert.assertTrue(wasRawRecordEmittedTo(TopologyConstants.DATA_STREAM, 1, expected));
    Tuple notExpected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", anotherRecord);
    Assert.assertFalse(wasRawRecordEmitted(notExpected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) 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 2 with TupleUtils.makeTuple

use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.

the class FilterBoltTest method testTopK.

@Test
public void testTopK() {
    // 16 records
    BulletStormConfig config = new BulletStormConfig(TopKTest.makeConfiguration(ErrorType.NO_FALSE_NEGATIVES, 32));
    bolt = ComponentUtils.prepare(new DonableFilterBolt(16, config), collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeAggregationQuery(TOP_K, 5, null, "cnt", Pair.of("A", ""), Pair.of("B", "foo")), METADATA);
    bolt.execute(query);
    IntStream.range(0, 8).mapToObj(i -> RecordBox.get().add("A", i).getRecord()).map(FilterBoltTest::makeRecordTuple).forEach(bolt::execute);
    IntStream.range(0, 6).mapToObj(i -> RecordBox.get().add("A", 0).getRecord()).map(FilterBoltTest::makeRecordTuple).forEach(bolt::execute);
    IntStream.range(0, 2).mapToObj(i -> RecordBox.get().add("A", 3).getRecord()).map(FilterBoltTest::makeRecordTuple).forEach(bolt::execute);
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    bolt.execute(tick);
    Assert.assertEquals(collector.getEmittedCount(), 1);
    byte[] rawData = getRawPayloadOfNthTuple(1);
    Assert.assertNotNull(rawData);
    Map<String, String> fields = new HashMap<>();
    fields.put("A", "");
    fields.put("B", "foo");
    TopK topK = TopKTest.makeTopK(config, makeAttributes("cnt", null), fields, 2, null);
    topK.combine(rawData);
    List<BulletRecord> records = topK.getRecords();
    Assert.assertEquals(records.size(), 2);
    BulletRecord expectedA = RecordBox.get().add("A", "0").add("foo", "null").add("cnt", 7L).getRecord();
    BulletRecord expectedB = RecordBox.get().add("A", "3").add("foo", "null").add("cnt", 3L).getRecord();
    Assert.assertEquals(records.get(0), expectedA);
    Assert.assertEquals(records.get(1), expectedB);
}
Also used : TopK(com.yahoo.bullet.aggregations.TopK) BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) 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 3 with TupleUtils.makeTuple

use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.

the class FilterBoltTest method testGroupAllCount.

@Test
public void testGroupAllCount() {
    // 15 Records will be consumed
    bolt = ComponentUtils.prepare(new DonableFilterBolt(15, new BulletStormConfig()), collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeGroupFilterQuery("timestamp", asList("1", "2"), EQUALS, GROUP, 1, singletonList(new GroupOperation(COUNT, null, "cnt"))), METADATA);
    bolt.execute(query);
    BulletRecord record = RecordBox.get().add("timestamp", "1").getRecord();
    Tuple matching = makeRecordTuple(record);
    IntStream.range(0, 10).forEach(i -> bolt.execute(matching));
    BulletRecord another = RecordBox.get().getRecord();
    Tuple nonMatching = makeRecordTuple(another);
    IntStream.range(0, 5).forEach(i -> bolt.execute(nonMatching));
    bolt.execute(nonMatching);
    // Two to flush bolt
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    bolt.execute(tick);
    Assert.assertEquals(collector.getEmittedCount(), 1);
    GroupData actual = SerializerDeserializer.fromBytes(getRawPayloadOfNthTuple(1));
    BulletRecord expected = RecordBox.get().add("cnt", 10).getRecord();
    Assert.assertTrue(isEqual(actual, expected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) 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) GroupOperation(com.yahoo.bullet.aggregations.grouping.GroupOperation) GroupData(com.yahoo.bullet.aggregations.grouping.GroupData) Test(org.testng.annotations.Test) DistributionTest(com.yahoo.bullet.aggregations.DistributionTest) TopKTest(com.yahoo.bullet.aggregations.TopKTest) CountDistinctTest(com.yahoo.bullet.aggregations.CountDistinctTest)

Example 4 with TupleUtils.makeTuple

use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.

the class FilterBoltTest method testQueryDone.

@Test
public void testQueryDone() {
    bolt = ComponentUtils.prepare(new DonableFilterBolt(), collector);
    Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeFieldFilterQuery("b235gf23b"), METADATA);
    bolt.execute(query);
    BulletRecord nonMatching = RecordBox.get().add("field", "foo").getRecord();
    Tuple notMatching = makeRecordTuple(nonMatching);
    bolt.execute(notMatching);
    Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
    bolt.execute(tick);
    bolt.execute(tick);
    BulletRecord record = RecordBox.get().add("field", "b235gf23b").getRecord();
    Tuple matching = makeRecordTuple(record);
    bolt.execute(matching);
    Tuple expected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", record);
    Assert.assertFalse(wasRawRecordEmittedTo(TopologyConstants.DATA_STREAM, expected));
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) 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 5 with TupleUtils.makeTuple

use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.

the class FilterBoltTest method testUnknownTuple.

@Test
public void testUnknownTuple() {
    Tuple query = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "", "");
    bolt.execute(query);
    Assert.assertFalse(collector.wasAcked(query));
}
Also used : 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)

Aggregations

CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)9 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)9 TopKTest (com.yahoo.bullet.aggregations.TopKTest)9 TupleUtils.makeIDTuple (com.yahoo.bullet.storm.testing.TupleUtils.makeIDTuple)9 TupleUtils.makeRawTuple (com.yahoo.bullet.storm.testing.TupleUtils.makeRawTuple)9 TupleUtils.makeTuple (com.yahoo.bullet.storm.testing.TupleUtils.makeTuple)9 Tuple (org.apache.storm.tuple.Tuple)9 Test (org.testng.annotations.Test)9 BulletRecord (com.yahoo.bullet.record.BulletRecord)8 CountDistinct (com.yahoo.bullet.aggregations.CountDistinct)1 Distribution (com.yahoo.bullet.aggregations.Distribution)1 TopK (com.yahoo.bullet.aggregations.TopK)1 GroupData (com.yahoo.bullet.aggregations.grouping.GroupData)1 GroupOperation (com.yahoo.bullet.aggregations.grouping.GroupOperation)1 HashMap (java.util.HashMap)1