use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.
the class ReactiveTest method testReachingWindowSizeOnCombine.
@Test
public void testReachingWindowSizeOnCombine() {
Window window = makeReactiveWindow();
Reactive reactive = new Reactive(strategy, window, config);
Assert.assertFalse(reactive.initialize().isPresent());
reactive.consume(RecordBox.get().getRecord());
Assert.assertTrue(reactive.isClosed());
Assert.assertTrue(reactive.isClosedForPartition());
Assert.assertEquals(strategy.getConsumeCalls(), 1);
byte[] data = reactive.getData();
// Recreate
strategy = new MockStrategy();
reactive = new Reactive(strategy, window, config);
Assert.assertFalse(reactive.initialize().isPresent());
Assert.assertFalse(reactive.isClosed());
Assert.assertFalse(reactive.isClosedForPartition());
reactive.combine(data);
Assert.assertTrue(reactive.isClosed());
Assert.assertTrue(reactive.isClosedForPartition());
Assert.assertEquals(strategy.getConsumeCalls(), 0);
Assert.assertEquals(strategy.getCombineCalls(), 1);
}
use of com.yahoo.bullet.parsing.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.initialize().isPresent());
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
strategy.setClosed(true);
Assert.assertFalse(sliding.isClosed());
Assert.assertFalse(sliding.isClosedForPartition());
}
use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.
the class SlidingRecordTest method makeSlidingWindow.
private Window makeSlidingWindow(int size) {
Window window = WindowUtils.makeWindow(Window.Unit.RECORD, size);
window.configure(config);
window.initialize();
return window;
}
use of com.yahoo.bullet.parsing.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.assertFalse(sliding.initialize().isPresent());
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);
}
use of com.yahoo.bullet.parsing.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);
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);
}
Aggregations