use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class ReactiveTest method testMetadata.
@Test
public void testMetadata() {
Window window = makeReactiveWindow();
Reactive reactive = new Reactive(strategy, window, config);
Assert.assertFalse(reactive.initialize().isPresent());
Assert.assertFalse(reactive.isClosed());
Assert.assertFalse(reactive.isClosedForPartition());
reactive.consume(RecordBox.get().getRecord());
Assert.assertTrue(reactive.isClosed());
Assert.assertTrue(reactive.isClosedForPartition());
Assert.assertEquals(strategy.getMetadataCalls(), 0);
long timeNow = System.currentTimeMillis();
Meta meta = reactive.getMetadata();
Assert.assertNotNull(meta);
Map<String, Object> asMap = (Map<String, Object>) meta.asMap().get("window_stats");
Assert.assertEquals(asMap.get("num"), 1L);
Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
Assert.assertEquals(asMap.get("size"), 1);
Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
Assert.assertEquals(strategy.getMetadataCalls(), 1);
reactive.reset();
Assert.assertFalse(reactive.isClosed());
Assert.assertFalse(reactive.isClosedForPartition());
meta = reactive.getMetadata();
Assert.assertNotNull(meta);
asMap = (Map<String, Object>) meta.asMap().get("window_stats");
Assert.assertEquals(asMap.get("num"), 2L);
Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
Assert.assertEquals(asMap.get("size"), 0);
Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
Assert.assertEquals(strategy.getMetadataCalls(), 2);
reactive.consume(RecordBox.get().getRecord());
Assert.assertTrue(reactive.isClosed());
Assert.assertTrue(reactive.isClosedForPartition());
meta = reactive.getMetadata();
Assert.assertNotNull(meta);
asMap = (Map<String, Object>) meta.asMap().get("window_stats");
Assert.assertEquals(asMap.get("num"), 2L);
Assert.assertEquals(asMap.get("name"), SlidingRecord.NAME);
Assert.assertEquals(asMap.get("size"), 1);
Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
Assert.assertEquals(strategy.getMetadataCalls(), 3);
}
use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.
the class JoinBolt method emitRateLimitError.
private void emitRateLimitError(String id, Querier querier, RateLimitError error) {
Metadata metadata = bufferedMetadata.get(id);
Meta meta = error.makeMeta();
Clip clip = querier.finish();
clip.getMeta().merge(meta);
emitResult(id, withSignal(metadata, Metadata.Signal.FAIL), clip);
emitMetaSignal(id, Metadata.Signal.KILL);
updateCount(rateExceededQueries, 1L);
removeQuery(id);
}
use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.
the class JoinBoltTest method testUnknownConceptMetadata.
@Test
public void testUnknownConceptMetadata() {
config = configWithRawMaxAndEmptyMeta();
enableMetadataInConfig(config, Concept.QUERY_METADATA.getName(), "meta");
enableMetadataInConfig(config, Concept.QUERY_ID.getName(), "id");
enableMetadataInConfig(config, "foo", "bar");
setup(new JoinBolt(config));
Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{}", EMPTY);
bolt.execute(query);
List<BulletRecord> sent = sendRawRecordTuplesTo(bolt, "42");
Meta meta = new Meta();
meta.add("meta", singletonMap("id", "42"));
Tuple expected = TupleUtils.makeTuple(TupleClassifier.Type.RESULT_TUPLE, "42", Clip.of(sent).add(meta).asJSON(), COMPLETED);
Assert.assertTrue(wasResultEmittedTo(TopologyConstants.RESULT_STREAM, expected));
Tuple metadata = TupleUtils.makeTuple(TupleClassifier.Type.FEEDBACK_TUPLE, "42", new Metadata(Metadata.Signal.COMPLETE, null));
Assert.assertTrue(wasMetadataEmittedTo(TopologyConstants.FEEDBACK_STREAM, metadata));
Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.FEEDBACK_STREAM).count(), 1);
}
use of com.yahoo.bullet.result.Meta in project bullet-storm by yahoo.
the class JoinBoltTest method testErrorInQueryWithoutMetadata.
@Test
public void testErrorInQueryWithoutMetadata() {
Tuple query = TupleUtils.makeIDTuple(TupleClassifier.Type.QUERY_TUPLE, "42", "{\"aggregation\": {\"type\": \"garbage\"}}");
bolt.execute(query);
Assert.assertEquals(collector.getEmittedCount(), 1);
BulletError expectedError = Aggregation.TYPE_NOT_SUPPORTED_ERROR;
Meta expectedMetadata = Meta.of(expectedError);
List<Object> expected = TupleUtils.makeTuple("42", Clip.of(expectedMetadata).asJSON(), FAILED).getValues();
List<Object> actual = collector.getNthTupleEmittedTo(TopologyConstants.RESULT_STREAM, 1).get();
Assert.assertTrue(isSameResult(actual, expected));
Assert.assertEquals(collector.getAllEmittedTo(TopologyConstants.RESULT_STREAM).count(), 1);
Assert.assertEquals(collector.getEmittedCount(), 1);
}
use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class FrequentItemsSketchTest method testUnioning.
@Test
public void testUnioning() {
FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
IntStream.range(0, 10).forEach(i -> IntStream.range(0, 10).forEach(j -> sketch.update(String.valueOf(i))));
IntStream.range(10, 100).forEach(i -> sketch.update("bar"));
FrequentItemsSketch another = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
another.update("foo");
another.update("bar");
another.update("baz");
FrequentItemsSketch union = new FrequentItemsSketch(ErrorType.NO_FALSE_NEGATIVES, 32, 32);
union.union(sketch.serialize());
union.union(another.serialize());
Clip result = union.getResult("meta", ALL_METADATA);
Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
Assert.assertEquals(metadata.size(), 5);
Assert.assertFalse((Boolean) metadata.get("isEst"));
List<BulletRecord> records = result.getRecords();
Assert.assertEquals(records.size(), 13);
for (BulletRecord actual : records) {
String item = actual.get(FrequentItemsSketch.ITEM_FIELD).toString();
Assert.assertEquals(actual.fieldCount(), 2);
if ("bar".equals(item)) {
Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 91L);
} else if ("foo".equals(item) || "baz".equals(item)) {
Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 1L);
} else if (Integer.valueOf(item) < 10) {
Assert.assertEquals(actual.get(FrequentItemsSketch.COUNT_FIELD), 10L);
} else {
Assert.fail("This should not be a case");
}
}
Assert.assertEquals(union.getRecords(), records);
Assert.assertEquals(union.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
Aggregations