use of com.yahoo.bullet.query.Window in project bullet-core by yahoo.
the class SlidingRecordTest method makeSlidingWindow.
private Window makeSlidingWindow(int size) {
Window window = WindowUtils.makeSlidingWindow(size);
window.configure(config);
return window;
}
use of com.yahoo.bullet.query.Window in project bullet-core by yahoo.
the class SlidingRecordTest method testNotClosedOnStrategyClosed.
@Test
public void testNotClosedOnStrategyClosed() {
Window window = makeSlidingWindow(5);
ClosableStrategy strategy = new ClosableStrategy();
SlidingRecord sliding = new SlidingRecord(strategy, window, config);
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
strategy.setClosed(true);
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
}
use of com.yahoo.bullet.query.Window in project bullet-core by yahoo.
the class SlidingRecordTest method testResettingForPartition.
@Test
public void testResettingForPartition() {
Window window = makeSlidingWindow(5);
SlidingRecord sliding = new SlidingRecord(strategy, window, config);
Assert.assertEquals(strategy.getResetCalls(), 0);
for (int i = 0; i < 4; ++i) {
sliding.consume(RecordBox.get().getRecord());
Assert.assertFalse(sliding.isClosed());
Assert.assertTrue(sliding.isClosedForPartition());
}
Assert.assertEquals(strategy.getConsumeCalls(), 4);
sliding.consume(RecordBox.get().getRecord());
Assert.assertTrue(sliding.isClosed());
Assert.assertTrue(sliding.isClosedForPartition());
sliding.resetForPartition();
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
Assert.assertEquals(strategy.getConsumeCalls(), 5);
Assert.assertEquals(strategy.getResetCalls(), 1);
}
use of com.yahoo.bullet.query.Window 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);
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.query.Window in project bullet-core by yahoo.
the class SlidingRecordTest method testResetting.
@Test
public void testResetting() {
Window window = makeSlidingWindow(5);
SlidingRecord sliding = new SlidingRecord(strategy, window, config);
Assert.assertEquals(strategy.getResetCalls(), 0);
for (int i = 0; i < 4; ++i) {
sliding.consume(RecordBox.get().getRecord());
Assert.assertFalse(sliding.isClosed());
Assert.assertTrue(sliding.isClosedForPartition());
}
Assert.assertEquals(strategy.getConsumeCalls(), 4);
sliding.consume(RecordBox.get().getRecord());
Assert.assertTrue(sliding.isClosed());
Assert.assertTrue(sliding.isClosedForPartition());
sliding.reset();
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
Assert.assertEquals(strategy.getConsumeCalls(), 5);
Assert.assertEquals(strategy.getResetCalls(), 1);
}
Aggregations