Search in sources :

Example 1 with SelectiveStreamEventConverter

use of org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter in project ballerina by ballerina-lang.

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]);
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) SimpleStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter) StreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter) ZeroStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter) SelectiveStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Event(org.ballerinalang.siddhi.core.event.Event) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) SelectiveStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Aggregations

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