Search in sources :

Example 36 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory 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]);
}
Also used : ZeroStreamEventConverter(io.siddhi.core.event.stream.converter.ZeroStreamEventConverter) 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) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Example 37 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory 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]);
}
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) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SimpleStreamEventConverter(io.siddhi.core.event.stream.converter.SimpleStreamEventConverter) Test(org.testng.annotations.Test)

Example 38 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory in project siddhi by wso2.

the class ComplexEventChunkTestCase method eventChunkRemoveTest3.

@Test
public void eventChunkRemoveTest3() {
    StreamEvent streamEvent1 = new StreamEvent(0, 0, 3);
    streamEvent1.setOutputData(new Object[] { "IBM", 700L, 100L });
    StreamEvent streamEvent2 = new StreamEvent(0, 0, 3);
    streamEvent2.setOutputData(new Object[] { "WSO2", 700L, 100L });
    StreamEvent streamEvent3 = new StreamEvent(0, 0, 3);
    streamEvent3.setOutputData(new Object[] { "WSO2", 700L, 100L });
    StreamEvent streamEvent4 = new StreamEvent(0, 0, 3);
    streamEvent4.setOutputData(new Object[] { "WSO2", 700L, 100L });
    streamEvent1.setNext(streamEvent2);
    streamEvent2.setNext(streamEvent3);
    streamEvent3.setNext(streamEvent4);
    StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
    streamEventChunk.convertAndAssign(streamEvent1);
    while (streamEventChunk.hasNext()) {
        streamEventChunk.next();
        streamEventChunk.remove();
    }
    AssertJUnit.assertNull(streamEventChunk.getFirst());
}
Also used : ConversionStreamEventChunk(io.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) Test(org.testng.annotations.Test)

Example 39 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory in project siddhi by wso2.

the class ComplexEventChunkTestCase method eventChunkRemoveTest2.

@Test
public void eventChunkRemoveTest2() {
    StreamEvent streamEvent1 = new StreamEvent(0, 0, 3);
    streamEvent1.setOutputData(new Object[] { "IBM", 700L, 1L });
    StreamEvent streamEvent2 = new StreamEvent(0, 0, 3);
    streamEvent2.setOutputData(new Object[] { "WSO2", 700L, 2L });
    StreamEvent streamEvent3 = new StreamEvent(0, 0, 3);
    streamEvent3.setOutputData(new Object[] { "WSO2", 700L, 3L });
    StreamEvent streamEvent4 = new StreamEvent(0, 0, 3);
    streamEvent4.setOutputData(new Object[] { "WSO2", 700L, 4L });
    streamEvent1.setNext(streamEvent2);
    streamEvent2.setNext(streamEvent3);
    streamEvent3.setNext(streamEvent4);
    StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
    streamEventChunk.convertAndAssign(streamEvent1);
    while (streamEventChunk.hasNext()) {
        count++;
        streamEventChunk.next();
        if (count == 1 || count == 2) {
            streamEventChunk.remove();
        }
    }
    StreamEvent streamEvent = streamEventChunk.getFirst();
    AssertJUnit.assertEquals(streamEvent3, streamEvent);
    AssertJUnit.assertEquals(streamEvent4, streamEvent.getNext());
}
Also used : ConversionStreamEventChunk(io.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) Test(org.testng.annotations.Test)

Aggregations

StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)39 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)23 StreamEvent (io.siddhi.core.event.stream.StreamEvent)21 Attribute (io.siddhi.query.api.definition.Attribute)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)13 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)11 StreamEventConverter (io.siddhi.core.event.stream.converter.StreamEventConverter)9 HashMap (java.util.HashMap)7 Map (java.util.Map)7 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)6 ConversionStreamEventChunk (io.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamEventClonerHolder (io.siddhi.core.event.stream.holder.StreamEventClonerHolder)6 Event (io.siddhi.core.event.Event)5 Operation (io.siddhi.core.event.stream.Operation)5 ZeroStreamEventConverter (io.siddhi.core.event.stream.converter.ZeroStreamEventConverter)5 SnapshotableStreamEventQueue (io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue)5 Snapshot (io.siddhi.core.util.snapshot.state.Snapshot)5 SnapshotStateList (io.siddhi.core.util.snapshot.state.SnapshotStateList)5 ComplexEvent (io.siddhi.core.event.ComplexEvent)4