Search in sources :

Example 6 with StreamEventConverter

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

Example 7 with StreamEventConverter

use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter 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);
    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.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 8 with StreamEventConverter

use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.

the class ComplexEventChunkTestCase method eventChunkRemoveTest5.

@Test(expectedExceptions = IllegalStateException.class)
public void eventChunkRemoveTest5() {
    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 });
    streamEvent1.setNext(streamEvent2);
    StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
    streamEventChunk.convertAndAssign(streamEvent1);
    streamEventChunk.remove();
    streamEventChunk.remove();
}
Also used : ConversionStreamEventChunk(org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Example 9 with StreamEventConverter

use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.

the class ComplexEventChunkTestCase method init.

@BeforeMethod
public void init() {
    count = 0;
    streamEventConverter = new ZeroStreamEventConverter();
}
Also used : ZeroStreamEventConverter(org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 10 with StreamEventConverter

use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.

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.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) Test(org.testng.annotations.Test)

Aggregations

StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)15 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)15 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)10 Test (org.testng.annotations.Test)9 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)9 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)7 Event (org.wso2.siddhi.core.event.Event)5 ZeroStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.ZeroStreamEventConverter)5 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)4 Attribute (org.wso2.siddhi.query.api.definition.Attribute)4 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 SelectiveStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.wso2.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)3 BeforeMethod (org.testng.annotations.BeforeMethod)1 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)1 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)1 StateEventPool (org.wso2.siddhi.core.event.state.StateEventPool)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1 DeleteTableCallback (org.wso2.siddhi.core.query.output.callback.DeleteTableCallback)1