Search in sources :

Example 1 with SelectiveStreamEventConverter

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

Aggregations

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