Search in sources :

Example 31 with Window

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

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

Example 33 with Window

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

Example 34 with Window

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

Example 35 with Window

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

Aggregations

Window (com.yahoo.bullet.query.Window)42 Test (org.testng.annotations.Test)34 Projection (com.yahoo.bullet.query.Projection)28 Query (com.yahoo.bullet.query.Query)28 Raw (com.yahoo.bullet.query.aggregations.Raw)26 BulletConfigTest (com.yahoo.bullet.common.BulletConfigTest)17 FieldExpression (com.yahoo.bullet.query.expressions.FieldExpression)12 BinaryExpression (com.yahoo.bullet.query.expressions.BinaryExpression)11 ValueExpression (com.yahoo.bullet.query.expressions.ValueExpression)11 BulletConfig (com.yahoo.bullet.common.BulletConfig)10 Expression (com.yahoo.bullet.query.expressions.Expression)10 ListExpression (com.yahoo.bullet.query.expressions.ListExpression)10 UnaryExpression (com.yahoo.bullet.query.expressions.UnaryExpression)10 BulletRecord (com.yahoo.bullet.record.BulletRecord)7 Field (com.yahoo.bullet.query.Field)6 Metadata (com.yahoo.bullet.pubsub.Metadata)5 RecordBox (com.yahoo.bullet.result.RecordBox)5 Map (java.util.Map)4 CountDistinct (com.yahoo.bullet.query.aggregations.CountDistinct)3 GroupAll (com.yahoo.bullet.query.aggregations.GroupAll)3