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