use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.
the class FilterBoltTest method testQueryNotDone.
@Test
public void testQueryNotDone() {
bolt = ComponentUtils.prepare(new DonableFilterBolt(), 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 = makeRecordTuple(record);
bolt.execute(matching);
Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
bolt.execute(tick);
bolt.execute(tick);
Tuple expected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", record);
Assert.assertTrue(wasRawRecordEmittedTo(TopologyConstants.DATA_STREAM, 1, expected));
}
use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.
the class FilterBoltTest method testCountDistinct.
@Test
public void testCountDistinct() {
// 256 Records will be consumed
BulletStormConfig config = new BulletStormConfig(CountDistinctTest.makeConfiguration(8, 512));
bolt = ComponentUtils.prepare(new DonableFilterBolt(256, config), collector);
Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeAggregationQuery(COUNT_DISTINCT, 1, null, Pair.of("field", "field")), METADATA);
bolt.execute(query);
IntStream.range(0, 256).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).map(FilterBoltTest::makeRecordTuple).forEach(bolt::execute);
Assert.assertEquals(collector.getEmittedCount(), 0);
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);
CountDistinct distinct = CountDistinctTest.makeCountDistinct(config, singletonList("field"));
distinct.combine(rawData);
BulletRecord actual = distinct.getRecords().get(0);
BulletRecord expected = RecordBox.get().add(CountDistinct.DEFAULT_NEW_NAME, 256.0).getRecord();
Assert.assertEquals(actual, expected);
}
use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.
the class FilterBoltTest method testDistribution.
@Test
public void testDistribution() {
// 100 Records will be consumed
BulletStormConfig config = new BulletStormConfig(DistributionTest.makeConfiguration(20, 128));
bolt = ComponentUtils.prepare(new DonableFilterBolt(101, config), collector);
Tuple query = makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", makeAggregationQuery(DISTRIBUTION, 10, Distribution.Type.PMF, "field", null, null, null, null, 3), METADATA);
bolt.execute(query);
IntStream.range(0, 101).mapToObj(i -> RecordBox.get().add("field", i).getRecord()).map(FilterBoltTest::makeRecordTuple).forEach(bolt::execute);
Assert.assertEquals(collector.getEmittedCount(), 0);
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);
Distribution distribution = DistributionTest.makeDistribution(config, makeAttributes(Distribution.Type.PMF, 3), "field", 10, null);
distribution.combine(rawData);
List<BulletRecord> records = distribution.getRecords();
BulletRecord expectedA = RecordBox.get().add(RANGE_FIELD, NEGATIVE_INFINITY_START + SEPARATOR + 0.0 + END_EXCLUSIVE).add(COUNT_FIELD, 0.0).add(PROBABILITY_FIELD, 0.0).getRecord();
BulletRecord expectedB = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 0.0 + SEPARATOR + 50.0 + END_EXCLUSIVE).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 50.0 / 101).getRecord();
BulletRecord expectedC = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 50.0 + SEPARATOR + 100.0 + END_EXCLUSIVE).add(COUNT_FIELD, 50.0).add(PROBABILITY_FIELD, 50.0 / 101).getRecord();
BulletRecord expectedD = RecordBox.get().add(RANGE_FIELD, START_INCLUSIVE + 100.0 + SEPARATOR + POSITIVE_INFINITY_END).add(COUNT_FIELD, 1.0).add(PROBABILITY_FIELD, 1.0 / 101).getRecord();
Assert.assertEquals(records.get(0), expectedA);
Assert.assertEquals(records.get(1), expectedB);
Assert.assertEquals(records.get(2), expectedC);
Assert.assertEquals(records.get(3), expectedD);
}
use of com.yahoo.bullet.storm.testing.TupleUtils.makeTuple in project bullet-storm by yahoo.
the class FilterBoltTest method testQueryNotDoneAndThenDone.
@Test
public void testQueryNotDoneAndThenDone() {
bolt = ComponentUtils.prepare(new DonableFilterBolt(), 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 = makeRecordTuple(record);
bolt.execute(matching);
Tuple tick = TupleUtils.makeTuple(TupleClassifier.Type.TICK_TUPLE);
bolt.execute(tick);
bolt.execute(tick);
Tuple expected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", record);
Assert.assertTrue(wasRawRecordEmittedTo(TopologyConstants.DATA_STREAM, 1, expected));
BulletRecord anotherRecord = RecordBox.get().add("field", "b235gf23b").add("mid", "2342").getRecord();
Tuple anotherExpected = makeDataTuple(TupleClassifier.Type.DATA_TUPLE, "42", anotherRecord);
Assert.assertFalse(wasRawRecordEmittedTo(TopologyConstants.DATA_STREAM, anotherExpected));
}
Aggregations