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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations