use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class FrequentItemsSketchTest method testApproximateCounting.
@Test
public void testApproximateCounting() {
FrequentItemsSketch sketch = new FrequentItemsSketch(ErrorType.NO_FALSE_POSITIVES, 32, 40);
IntStream.range(0, 40).forEach(i -> sketch.update(String.valueOf(i)));
IntStream.of(10, 20, 25, 30).forEach(i -> IntStream.range(0, i).forEach(j -> sketch.update(String.valueOf(i))));
Clip result = sketch.getResult("meta", ALL_METADATA);
Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
Assert.assertEquals(metadata.size(), 5);
Assert.assertTrue((Boolean) metadata.get("isEst"));
Long error = (Long) metadata.get("error");
List<BulletRecord> records = result.getRecords();
// We should have our four frequent items
Assert.assertTrue(records.size() >= 4);
for (BulletRecord actual : records) {
Assert.assertEquals(actual.fieldCount(), 2);
Integer item = Integer.valueOf(actual.get(FrequentItemsSketch.ITEM_FIELD).toString());
Long count = (Long) actual.get(FrequentItemsSketch.COUNT_FIELD);
if (item == 10 || item == 20 || item == 25 || item == 30) {
Assert.assertTrue(count >= item + 1);
Assert.assertTrue(count <= item + 1 + error);
} else {
Assert.assertTrue(count >= 1);
Assert.assertTrue(count <= 1 + error);
}
}
Assert.assertEquals(sketch.getRecords(), result.getRecords());
Assert.assertEquals(sketch.getMetadata("meta", ALL_METADATA).asMap(), result.getMeta().asMap());
}
use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class QuerierTest method testExceptionWrapping.
@Test
public void testExceptionWrapping() {
FailingScheme failingScheme = new FailingScheme(null, null, new BulletConfig());
Querier querier = make(Querier.Mode.ALL, new Query());
querier.setWindow(failingScheme);
querier.consume(RecordBox.get().getRecord());
querier.combine(new byte[0]);
Assert.assertNull(querier.getData());
Assert.assertNull(querier.getRecords());
Meta meta = querier.getMetadata();
Map<String, Object> actualMeta = meta.asMap();
Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
BulletError expected = BulletError.makeError("Getting metadata failure", Querier.TRY_AGAIN_LATER);
Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
Clip actual = querier.getResult();
Assert.assertNotNull(actual.getMeta());
Assert.assertEquals(actual.getRecords().size(), 0);
actualMeta = actual.getMeta().asMap();
Assert.assertEquals(actualMeta.size(), 1);
Assert.assertNotNull(actualMeta.get(Meta.ERROR_KEY));
expected = BulletError.makeError("Getting result failure", Querier.TRY_AGAIN_LATER);
Assert.assertEquals(actualMeta.get(Meta.ERROR_KEY), singletonList(expected));
Assert.assertEquals(failingScheme.consumptionFailure, 1);
Assert.assertEquals(failingScheme.combiningFailure, 1);
Assert.assertEquals(failingScheme.serializingFailure, 1);
Assert.assertEquals(failingScheme.aggregationFailure, 3);
}
use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class AdditiveTumblingTest method testMetadata.
@Test
public void testMetadata() throws Exception {
long started = System.currentTimeMillis();
AdditiveTumbling additiveTumbling = make(1, 1);
Assert.assertFalse(additiveTumbling.initialize().isPresent());
Thread.sleep(1);
additiveTumbling.consume(RecordBox.get().getRecord());
Assert.assertTrue(additiveTumbling.isClosed());
Assert.assertTrue(additiveTumbling.isClosedForPartition());
Assert.assertEquals(strategy.getMetadataCalls(), 0);
Meta meta = additiveTumbling.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"), Tumbling.NAME);
long closedTime = (Long) asMap.get("close");
long shouldCloseTime = (Long) asMap.get("should_close");
Assert.assertTrue(closedTime >= started);
Assert.assertTrue(shouldCloseTime >= started);
Assert.assertTrue(shouldCloseTime <= closedTime);
Assert.assertEquals(strategy.getMetadataCalls(), 1);
additiveTumbling.reset();
meta = additiveTumbling.getMetadata();
Assert.assertNotNull(meta);
asMap = (Map<String, Object>) meta.asMap().get("window_stats");
Assert.assertEquals(asMap.get("num"), 2L);
Assert.assertEquals(asMap.get("name"), AdditiveTumbling.NAME);
Assert.assertEquals(strategy.getMetadataCalls(), 2);
}
use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class BasicTest method testDisablingWindowMetadataDoesGetStrategyMetadata.
@Test
public void testDisablingWindowMetadataDoesGetStrategyMetadata() {
// Metadata is enabled but no keys for the window metadata. Strategy metadata will be collected.
addMetadata(config, Collections.emptyList());
Basic basic = new Basic(strategy, null, config);
Assert.assertEquals(strategy.getMetadataCalls(), 0);
Meta meta = basic.getMetadata();
Assert.assertNotNull(meta);
Assert.assertTrue(meta.asMap().isEmpty());
Assert.assertEquals(strategy.getMetadataCalls(), 1);
}
use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.
the class BasicTest method testDisablingMetadataDoesNotGetStrategyMetadata.
@Test
public void testDisablingMetadataDoesNotGetStrategyMetadata() {
// Metadata is disabled so Strategy metadata will not be collected.
addMetadata(config, (List<Map.Entry<Meta.Concept, String>>) null);
Basic basic = new Basic(strategy, null, config);
Assert.assertEquals(strategy.getMetadataCalls(), 0);
Meta meta = basic.getMetadata();
Assert.assertNotNull(meta);
Assert.assertTrue(meta.asMap().isEmpty());
Assert.assertEquals(strategy.getMetadataCalls(), 0);
}
Aggregations