Search in sources :

Example 11 with Window

use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.

the class ReactiveTest method testMetadata.

@Test
public void testMetadata() {
    Window window = makeReactiveWindow();
    Reactive reactive = new Reactive(strategy, window, config);
    Assert.assertFalse(reactive.initialize().isPresent());
    Assert.assertFalse(reactive.isClosed());
    Assert.assertFalse(reactive.isClosedForPartition());
    reactive.consume(RecordBox.get().getRecord());
    Assert.assertTrue(reactive.isClosed());
    Assert.assertTrue(reactive.isClosedForPartition());
    Assert.assertEquals(strategy.getMetadataCalls(), 0);
    long timeNow = System.currentTimeMillis();
    Meta meta = reactive.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"), 1);
    Assert.assertTrue(((Long) asMap.get("close")) >= timeNow);
    Assert.assertEquals(strategy.getMetadataCalls(), 1);
    reactive.reset();
    Assert.assertFalse(reactive.isClosed());
    Assert.assertFalse(reactive.isClosedForPartition());
    meta = reactive.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(), 2);
    reactive.consume(RecordBox.get().getRecord());
    Assert.assertTrue(reactive.isClosed());
    Assert.assertTrue(reactive.isClosedForPartition());
    meta = reactive.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(), 3);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Meta(com.yahoo.bullet.result.Meta) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 12 with Window

use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.

the class ReactiveTest method testCreation.

@Test
public void testCreation() {
    Window window = makeReactiveWindow();
    Reactive reactive = new Reactive(strategy, window, config);
    Assert.assertFalse(reactive.initialize().isPresent());
    Assert.assertFalse(reactive.isClosed());
    Assert.assertFalse(reactive.isClosedForPartition());
}
Also used : Window(com.yahoo.bullet.parsing.Window) Test(org.testng.annotations.Test)

Example 13 with Window

use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.

the class SlidingRecordTest method testImproperInitialization.

@Test
public void testImproperInitialization() {
    SlidingRecord sliding = new SlidingRecord(strategy, new Window(), config);
    Optional<List<BulletError>> errors = sliding.initialize();
    Assert.assertTrue(errors.isPresent());
    Assert.assertEquals(errors.get(), singletonList(SlidingRecord.NOT_RECORD));
}
Also used : Window(com.yahoo.bullet.parsing.Window) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.testng.annotations.Test)

Example 14 with Window

use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.

the class WindowingOperationsTest method testTumblingWindow.

@Test
public void testTumblingWindow() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Window window = WindowUtils.makeTumblingWindow(1000);
    window.configure(config);
    query.setWindow(window);
    Assert.assertEquals(WindowingOperations.findScheme(query, null, config).getClass(), Tumbling.class);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) Test(org.testng.annotations.Test)

Example 15 with Window

use of com.yahoo.bullet.parsing.Window in project bullet-core by yahoo.

the class WindowingOperationsTest method testNotForcingRawToReactive.

@Test
public void testNotForcingRawToReactive() {
    BulletConfig config = new BulletConfig();
    Query query = new Query();
    Window window = WindowUtils.makeWindow(Window.Unit.TIME, 1000, Window.Unit.ALL, null);
    window.configure(config);
    query.setWindow(window);
    Aggregation aggregation = new Aggregation();
    aggregation.setType(Aggregation.Type.RAW);
    query.setAggregation(aggregation);
    Assert.assertEquals(WindowingOperations.findScheme(query, null, config).getClass(), AdditiveTumbling.class);
}
Also used : Window(com.yahoo.bullet.parsing.Window) Aggregation(com.yahoo.bullet.parsing.Aggregation) Query(com.yahoo.bullet.parsing.Query) BulletConfig(com.yahoo.bullet.common.BulletConfig) 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