Search in sources :

Example 16 with StreamEventPool

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

the class EventTestCase method testEventPool.

@Test
public void testEventPool() {
    StreamEventPool streamEventPool = new StreamEventPool(2, 3, 1, 4);
    StreamEvent[] streamEvents = new StreamEvent[5];
    for (int i = 0; i < 5; i++) {
        streamEvents[i] = streamEventPool.borrowEvent();
    }
    AssertJUnit.assertEquals(0, streamEventPool.getBufferedEventsSize());
    for (int i = 0; i < 5; i++) {
        streamEventPool.returnEvents(streamEvents[i]);
    }
    AssertJUnit.assertEquals(4, streamEventPool.getBufferedEventsSize());
    streamEventPool.borrowEvent();
    AssertJUnit.assertEquals(3, streamEventPool.getBufferedEventsSize());
}
Also used : StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 17 with StreamEventPool

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

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);
    StreamEventPool eventPool = new StreamEventPool(metaStreamEvent, 5);
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    converter.convertEvent(event, borrowedEvent);
    AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter);
    AssertJUnit.assertNull(borrowedEvent.getBeforeWindowData());
    AssertJUnit.assertNull(borrowedEvent.getOnAfterWindowData());
    AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
    AssertJUnit.assertEquals(200, borrowedEvent.getOutputData()[1]);
    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) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) SimpleStreamEventConverter(org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter) Test(org.testng.annotations.Test)

Example 18 with StreamEventPool

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

the class ComplexEventChunkTestCase method eventChunkRemoveTest4.

@Test
public void eventChunkRemoveTest4() {
    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);
    StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
    streamEventChunk.convertAndAssign(streamEvent1);
    while (streamEventChunk.hasNext()) {
        count++;
        streamEventChunk.next();
        if (count == 2 || count == 4) {
            streamEventChunk.remove();
        }
    }
    StreamEvent streamEvent = streamEventChunk.getFirst();
    AssertJUnit.assertEquals(streamEvent1, streamEvent);
    AssertJUnit.assertEquals(streamEvent3, streamEvent.getNext());
    AssertJUnit.assertNull(streamEvent.getNext().getNext());
}
Also used : ConversionStreamEventChunk(org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 19 with StreamEventPool

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

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);
    StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
    streamEventChunk.convertAndAssign(streamEvent1);
    while (streamEventChunk.hasNext()) {
        streamEventChunk.next();
        streamEventChunk.remove();
    }
    AssertJUnit.assertNull(streamEventChunk.getFirst());
}
Also used : ConversionStreamEventChunk(org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 20 with StreamEventPool

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

the class ComplexEventChunkTestCase method eventChunkTest.

@Test
public void eventChunkTest() {
    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 });
    streamEvent1.setNext(streamEvent2);
    streamEvent2.setNext(streamEvent3);
    StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
    streamEventChunk.convertAndAssign(streamEvent1);
    while (streamEventChunk.hasNext()) {
        count++;
        StreamEvent event = streamEventChunk.next();
        AssertJUnit.assertEquals(count * 1L, event.getOutputData()[2]);
    }
    AssertJUnit.assertEquals(3, count);
}
Also used : ConversionStreamEventChunk(org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Aggregations

StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)34 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)16 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)15 Test (org.testng.annotations.Test)11 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)9 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 Event (org.ballerinalang.siddhi.core.event.Event)6 ConversionStreamEventChunk (org.ballerinalang.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)5 ZeroStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter)5 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)5 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)4 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)3 SelectiveStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)3 Table (org.ballerinalang.siddhi.core.table.Table)3 ArrayList (java.util.ArrayList)2 StateEventCloner (org.ballerinalang.siddhi.core.event.state.StateEventCloner)2 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)2