Search in sources :

Example 16 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class BasicTest method testResettingIncrementsWindowCount.

@Test
public void testResettingIncrementsWindowCount() {
    addMetadata(config, ALL_METADATA);
    Basic basic = new Basic(strategy, null, config);
    Assert.assertEquals(strategy.getResetCalls(), 0);
    Meta meta = basic.getMetadata();
    Assert.assertNotNull(meta);
    Map<String, Object> asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 1L);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    basic.reset();
    Assert.assertEquals(strategy.getResetCalls(), 1);
    basic.reset();
    Assert.assertEquals(strategy.getResetCalls(), 2);
    basic.reset();
    Assert.assertEquals(strategy.getResetCalls(), 3);
    meta = basic.getMetadata();
    Assert.assertNotNull(meta);
    asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("num"), 4L);
    Assert.assertEquals(strategy.getMetadataCalls(), 2);
    Assert.assertEquals(strategy.getResetCalls(), 3);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 17 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class BasicTest method testAllDataMethodsProxyToStrategy.

@Test
public void testAllDataMethodsProxyToStrategy() {
    addMetadata(config, ALL_METADATA);
    Basic basic = new Basic(strategy, null, config);
    Assert.assertEquals(strategy.getConsumeCalls(), 0);
    Assert.assertEquals(strategy.getCombineCalls(), 0);
    Assert.assertEquals(strategy.getDataCalls(), 0);
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    Assert.assertEquals(strategy.getRecordCalls(), 0);
    Assert.assertEquals(strategy.getResetCalls(), 0);
    basic.consume(null);
    Assert.assertEquals(strategy.getConsumeCalls(), 1);
    basic.combine(null);
    Assert.assertEquals(strategy.getCombineCalls(), 1);
    Assert.assertNull(basic.getData());
    Assert.assertEquals(strategy.getDataCalls(), 1);
    long timeNow = System.currentTimeMillis();
    Meta meta = basic.getMetadata();
    Assert.assertNotNull(meta);
    Map<String, Object> asMap = (Map<String, Object>) meta.asMap().get("window_stats");
    Assert.assertEquals(asMap.get("name"), Basic.NAME);
    Assert.assertEquals(asMap.get("num"), 1L);
    Assert.assertTrue(((Long) asMap.get("closed")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    Assert.assertNull(basic.getRecords());
    Assert.assertEquals(strategy.getRecordCalls(), 1);
    Clip clip = basic.getResult();
    Map<String, Object> expected = (Map<String, Object>) meta.asMap().get("window_stats");
    Map<String, Object> actual = (Map<String, Object>) clip.getMeta().asMap().get("window_stats");
    Assert.assertEquals(actual.get("name"), expected.get("name"));
    Assert.assertEquals(actual.get("num"), expected.get("num"));
    Assert.assertTrue(((Long) actual.get("closed")) >= timeNow);
    Assert.assertEquals(clip.getRecords(), Collections.emptyList());
    // We will not call getResult because we use getMetadata and getRecords
    Assert.assertEquals(strategy.getResultCalls(), 0);
    basic.reset();
    Assert.assertEquals(strategy.getResetCalls(), 1);
    basic.resetForPartition();
    Assert.assertEquals(strategy.getResetCalls(), 2);
}
Also used : Clip(com.yahoo.bullet.result.Clip) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 18 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class SlidingRecordTest method testMetadata.

@Test
public void testMetadata() {
    Window window = makeSlidingWindow(5);
    SlidingRecord sliding = new SlidingRecord(strategy, window, config);
    Assert.assertFalse(sliding.initialize().isPresent());
    for (int i = 0; i < 4; ++i) {
        sliding.consume(RecordBox.get().getRecord());
        Assert.assertFalse(sliding.isClosed());
        Assert.assertTrue(sliding.isClosedForPartition());
    }
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    long timeNow = System.currentTimeMillis();
    Meta meta = sliding.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"), 4);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    sliding.consume(RecordBox.get().getRecord());
    Assert.assertTrue(sliding.isClosed());
    Assert.assertTrue(sliding.isClosedForPartition());
    meta = sliding.getMetadata();
    Assert.assertNotNull(meta);
    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"), 5);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 2);
    sliding.reset();
    Assert.assertFalse(sliding.isClosed());
    Assert.assertFalse(sliding.isClosedForPartition());
    meta = sliding.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(), 3);
    sliding.consume(RecordBox.get().getRecord());
    Assert.assertFalse(sliding.isClosed());
    Assert.assertTrue(sliding.isClosedForPartition());
    meta = sliding.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(), 4);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 19 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class TumblingTest method testMetadata.

@Test
public void testMetadata() throws Exception {
    long started = System.currentTimeMillis();
    Tumbling tumbling = make(1, 1);
    Assert.assertFalse(tumbling.initialize().isPresent());
    Thread.sleep(1);
    tumbling.consume(RecordBox.get().getRecord());
    Assert.assertTrue(tumbling.isClosed());
    Assert.assertTrue(tumbling.isClosedForPartition());
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    Meta meta = tumbling.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);
    tumbling.reset();
    meta = tumbling.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);
}
Also used : Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 20 with Meta

use of com.yahoo.bullet.result.Meta in project bullet-core by yahoo.

the class Querier method getMetadata.

/**
 * Returns the {@link Meta} of the result so far. See {@link #getResult()} for the full result with the data.
 *
 * @return The metadata part of the result.
 */
@Override
public Meta getMetadata() {
    Meta meta;
    try {
        meta = window.getMetadata();
        meta.merge(getResultMetadata());
    } catch (RuntimeException e) {
        log.error("Unable to get metadata for query {}", this);
        meta = getErrorMeta(e);
    }
    return meta;
}
Also used : Meta(com.yahoo.bullet.result.Meta)

Aggregations

Meta (com.yahoo.bullet.result.Meta)24 Test (org.testng.annotations.Test)20 Map (java.util.Map)11 Clip (com.yahoo.bullet.result.Clip)8 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 CountDistinctTest (com.yahoo.bullet.aggregations.CountDistinctTest)6 DistributionTest (com.yahoo.bullet.aggregations.DistributionTest)6 GroupByTest (com.yahoo.bullet.aggregations.GroupByTest)6 TopKTest (com.yahoo.bullet.aggregations.TopKTest)6 HashMap (java.util.HashMap)6 Tuple (org.apache.storm.tuple.Tuple)6 BulletError (com.yahoo.bullet.common.BulletError)5 Family (com.yahoo.sketches.Family)5 SketchesArgumentException (com.yahoo.sketches.SketchesArgumentException)5 ErrorType (com.yahoo.sketches.frequencies.ErrorType)5 List (java.util.List)5 IntStream (java.util.stream.IntStream)5 Assert (org.testng.Assert)5 JsonObject (com.google.gson.JsonObject)4 Metadata (com.yahoo.bullet.pubsub.Metadata)3