Search in sources :

Example 21 with Window

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);
}
Also used : Window(com.yahoo.bullet.parsing.Window) MockStrategy(com.yahoo.bullet.aggregations.MockStrategy) Test(org.testng.annotations.Test)

Example 22 with Window

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());
}
Also used : Window(com.yahoo.bullet.parsing.Window) Test(org.testng.annotations.Test)

Example 23 with Window

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;
}
Also used : Window(com.yahoo.bullet.parsing.Window)

Example 24 with 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);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Test(org.testng.annotations.Test)

Example 25 with Window

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);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Aggregations

Window (com.yahoo.bullet.parsing.Window)32 Test (org.testng.annotations.Test)24 BulletConfig (com.yahoo.bullet.common.BulletConfig)6 Query (com.yahoo.bullet.parsing.Query)6 Aggregation (com.yahoo.bullet.parsing.Aggregation)5 MockStrategy (com.yahoo.bullet.aggregations.MockStrategy)2 Meta (com.yahoo.bullet.result.Meta)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 Map (java.util.Map)2 AdditiveTumbling (com.yahoo.bullet.windowing.AdditiveTumbling)1 Basic (com.yahoo.bullet.windowing.Basic)1 Reactive (com.yahoo.bullet.windowing.Reactive)1 Tumbling (com.yahoo.bullet.windowing.Tumbling)1