use of org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter in project siddhi by wso2.
the class EventTestCase method testStreamEventConverter.
@Test
public void testStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.initializeAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
// complex attribute
metaStreamEvent.addOutputData(null);
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);
StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
StreamEvent borrowedEvent = eventPool.borrowEvent();
converter.convertEvent(event, borrowedEvent);
AssertJUnit.assertTrue(converter instanceof SelectiveStreamEventConverter);
// volume
AssertJUnit.assertEquals(1, borrowedEvent.getBeforeWindowData().length);
// price
AssertJUnit.assertEquals(1, borrowedEvent.getOnAfterWindowData().length);
// symbol and avgPrice
AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
AssertJUnit.assertEquals(50, borrowedEvent.getBeforeWindowData()[0]);
AssertJUnit.assertEquals(200, borrowedEvent.getOnAfterWindowData()[0]);
AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
}
Aggregations