use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class EventTestCase method testUpdateMetaEvent.
@Test
public void testUpdateMetaEvent() {
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
Attribute price = new Attribute("price", Attribute.Type.FLOAT);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.addData(price);
metaStreamEvent.addData(symbol);
metaStreamEvent.initializeOnAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
metaStreamEvent.addOutputData(null);
MetaStateEvent metaStateEvent = new MetaStateEvent(1);
metaStateEvent.addEvent(metaStreamEvent);
VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
VariableExpressionExecutor symbolVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("symbol", Attribute.Type.STRING), 0, 0);
QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
QueryParserHelper.updateVariablePosition(metaStateEvent, Arrays.asList(priceVariableExpressionExecutor, volumeVariableExpressionExecutor, symbolVariableExpressionExecutor));
AssertJUnit.assertEquals(1, metaStreamEvent.getBeforeWindowData().size());
AssertJUnit.assertEquals(1, metaStreamEvent.getOnAfterWindowData().size());
AssertJUnit.assertEquals(2, metaStreamEvent.getOutputData().size());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 1, 0 }, priceVariableExpressionExecutor.getPosition());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 0, 0 }, volumeVariableExpressionExecutor.getPosition());
AssertJUnit.assertArrayEquals(new int[] { 0, 0, 2, 0 }, symbolVariableExpressionExecutor.getPosition());
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class EventTestCase method testPassThroughStreamEventConverter.
@Test
public void testPassThroughStreamEventConverter() {
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
metaStreamEvent.addOutputDataAllowingDuplicate(price);
metaStreamEvent.addOutputDataAllowingDuplicate(volume);
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200.0, 50 });
metaStreamEvent.addInputDefinition(streamDefinition);
StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
StreamEvent newEvent = eventPool.newInstance();
converter.convertEvent(event, newEvent);
AssertJUnit.assertTrue(converter instanceof ZeroStreamEventConverter);
AssertJUnit.assertEquals(3, newEvent.getOutputData().length);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
AssertJUnit.assertEquals(200.0, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals(50, newEvent.getOutputData()[2]);
}
use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.
the class EventTestCase method testSimpleStreamEventConverter.
@Test
public void testSimpleStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputData(symbol);
metaStreamEvent.addOutputData(price);
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.INT);
Event event = new Event(System.currentTimeMillis(), new Object[] { "WSO2", 200, 50 });
metaStreamEvent.addInputDefinition(streamDefinition);
StreamEventConverter converter = StreamEventConverterFactory.constructEventConverter(metaStreamEvent);
StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
StreamEvent newEvent = eventPool.newInstance();
converter.convertEvent(event, newEvent);
AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter);
AssertJUnit.assertNull(newEvent.getBeforeWindowData());
AssertJUnit.assertNull(newEvent.getOnAfterWindowData());
AssertJUnit.assertEquals(2, newEvent.getOutputData().length);
AssertJUnit.assertEquals(200, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
}
Aggregations