Search in sources :

Example 1 with SelectiveStreamEventConverter

use of io.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.initializeOnAfterWindowData();
    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);
    StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
    StreamEvent newEvent = eventPool.newInstance();
    converter.convertEvent(event, newEvent);
    AssertJUnit.assertTrue(converter instanceof SelectiveStreamEventConverter);
    // volume
    AssertJUnit.assertEquals(1, newEvent.getBeforeWindowData().length);
    // price
    AssertJUnit.assertEquals(1, newEvent.getOnAfterWindowData().length);
    // symbol and avgPrice
    AssertJUnit.assertEquals(2, newEvent.getOutputData().length);
    AssertJUnit.assertEquals(50, newEvent.getBeforeWindowData()[0]);
    AssertJUnit.assertEquals(200, newEvent.getOnAfterWindowData()[0]);
    AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Attribute(io.siddhi.query.api.definition.Attribute) SelectiveStreamEventConverter(io.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) SimpleStreamEventConverter(io.siddhi.core.event.stream.converter.SimpleStreamEventConverter) StreamEventConverter(io.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) SelectiveStreamEventConverter(io.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Aggregations

Event (io.siddhi.core.event.Event)1 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)1 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)1 StreamEvent (io.siddhi.core.event.stream.StreamEvent)1 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)1 SelectiveStreamEventConverter (io.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)1 SimpleStreamEventConverter (io.siddhi.core.event.stream.converter.SimpleStreamEventConverter)1 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)1 ZeroStreamEventConverter (io.siddhi.core.event.stream.converter.ZeroStreamEventConverter)1 Attribute (io.siddhi.query.api.definition.Attribute)1 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)1 Test (org.testng.annotations.Test)1