Search in sources :

Example 6 with TupleUtils.makeTuple

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));
}
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 7 with TupleUtils.makeTuple

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);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) CountDistinct(com.yahoo.bullet.aggregations.CountDistinct) 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 8 with TupleUtils.makeTuple

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);
}
Also used : BulletRecord(com.yahoo.bullet.record.BulletRecord) Distribution(com.yahoo.bullet.aggregations.Distribution) 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 9 with TupleUtils.makeTuple

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

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