Search in sources :

Example 61 with StreamEvent

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

the class JunctionTestCase method multiThreadedTest2.

@Test
public void multiThreadedTest2() throws InterruptedException {
    log.info("multi threaded 2");
    StreamDefinition streamA = StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("async"));
    StreamJunction streamJunctionA = new StreamJunction(streamA, executorService, 1024, siddhiAppContext);
    StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
    StreamDefinition streamB = StreamDefinition.id("streamB").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("async"));
    StreamJunction streamJunctionB = new StreamJunction(streamB, executorService, 1024, siddhiAppContext);
    final StreamJunction.Publisher streamPublisherB1 = streamJunctionB.constructPublisher();
    final StreamJunction.Publisher streamPublisherB2 = streamJunctionB.constructPublisher();
    final StreamJunction.Publisher streamPublisherB3 = streamJunctionB.constructPublisher();
    StreamDefinition streamC = StreamDefinition.id("streamC").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("async"));
    StreamJunction streamJunctionC = new StreamJunction(streamC, executorService, 1024, siddhiAppContext);
    final StreamJunction.Publisher streamPublisherC1 = streamJunctionC.constructPublisher();
    final StreamJunction.Publisher streamPublisherC2 = streamJunctionC.constructPublisher();
    StreamCallback streamCallbackA1 = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                Object[] data = new Object[] { streamEvent.getData()[0], streamEvent.getData()[1] };
                data[0] = ((String) data[0]).concat("A1");
                innerStreamEvent.setOutputData(data);
                streamPublisherB1.send(innerStreamEvent);
            }
        }
    };
    StreamCallback streamCallbackA2 = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                Object[] data = new Object[] { streamEvent.getData()[0], streamEvent.getData()[1] };
                data[0] = ((String) data[0]).concat("A2");
                innerStreamEvent.setOutputData(data);
                streamPublisherB2.send(innerStreamEvent);
            }
        }
    };
    StreamCallback streamCallbackA3 = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                Object[] data = new Object[] { streamEvent.getData()[0], streamEvent.getData()[1] };
                data[0] = ((String) data[0]).concat("A3");
                innerStreamEvent.setOutputData(data);
                streamPublisherB3.send(innerStreamEvent);
            }
        }
    };
    StreamCallback streamCallbackB1 = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                Object[] data = new Object[] { streamEvent.getData()[0], streamEvent.getData()[1] };
                data[0] = ((String) data[0]).concat("B1");
                innerStreamEvent.setOutputData(data);
                streamPublisherC1.send(innerStreamEvent);
            }
        }
    };
    StreamCallback streamCallbackB2 = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
                innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
                Object[] data = new Object[] { streamEvent.getData()[0], streamEvent.getData()[1] };
                data[0] = ((String) data[0]).concat("B2");
                innerStreamEvent.setOutputData(data);
                streamPublisherC2.send(innerStreamEvent);
            }
        }
    };
    final boolean[] eventsArrived = { false, false, false, false, false, false, false, false, false, false, false, false };
    StreamCallback streamCallbackC = new StreamCallback() {

        @Override
        public void receive(Event[] streamEvents) {
            for (Event streamEvent : streamEvents) {
                count++;
                eventArrived = true;
                Object symbol = streamEvent.getData()[0];
                if (symbol.equals("IBMA1B1")) {
                    eventsArrived[0] = true;
                } else if (symbol.equals("IBMA1B2")) {
                    eventsArrived[1] = true;
                } else if (symbol.equals("IBMA2B1")) {
                    eventsArrived[2] = true;
                } else if (symbol.equals("IBMA2B2")) {
                    eventsArrived[3] = true;
                } else if (symbol.equals("IBMA3B1")) {
                    eventsArrived[4] = true;
                } else if (symbol.equals("IBMA3B2")) {
                    eventsArrived[5] = true;
                }
                if (symbol.equals("WSO2A1B1")) {
                    eventsArrived[6] = true;
                } else if (symbol.equals("WSO2A1B2")) {
                    eventsArrived[7] = true;
                } else if (symbol.equals("WSO2A2B1")) {
                    eventsArrived[8] = true;
                } else if (symbol.equals("WSO2A2B2")) {
                    eventsArrived[9] = true;
                } else if (symbol.equals("WSO2A3B1")) {
                    eventsArrived[10] = true;
                } else if (symbol.equals("WSO2A3B2")) {
                    eventsArrived[11] = true;
                }
            }
        }
    };
    streamJunctionA.subscribe(streamCallbackA1);
    streamJunctionA.subscribe(streamCallbackA2);
    streamJunctionA.subscribe(streamCallbackA3);
    streamJunctionA.startProcessing();
    streamJunctionB.subscribe(streamCallbackB1);
    streamJunctionB.subscribe(streamCallbackB2);
    streamJunctionB.startProcessing();
    streamJunctionC.subscribe(streamCallbackC);
    streamJunctionC.startProcessing();
    StreamEvent streamEvent1 = new StreamEvent(2, 2, 2);
    streamEvent1.setTimestamp(System.currentTimeMillis());
    streamEvent1.setOutputData(new Object[] { "IBM", 12 });
    StreamEvent streamEvent2 = new StreamEvent(2, 2, 2);
    streamEvent2.setTimestamp(System.currentTimeMillis());
    streamEvent2.setOutputData(new Object[] { "WSO2", 112 });
    streamPublisherA.send(streamEvent1);
    streamPublisherA.send(streamEvent2);
    Thread.sleep(100);
    AssertJUnit.assertTrue(eventArrived);
    AssertJUnit.assertEquals(12, count);
    for (boolean arrived : eventsArrived) {
        AssertJUnit.assertTrue(arrived);
    }
    streamJunctionA.stopProcessing();
    streamJunctionB.stopProcessing();
    streamJunctionC.stopProcessing();
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) Event(org.wso2.siddhi.core.event.Event) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 62 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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 63 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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 64 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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)

Example 65 with StreamEvent

use of org.wso2.siddhi.core.event.stream.StreamEvent 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);
    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 == 1 || count == 2) {
            streamEventChunk.remove();
        }
    }
    StreamEvent streamEvent = streamEventChunk.getFirst();
    AssertJUnit.assertEquals(streamEvent3, streamEvent);
    AssertJUnit.assertEquals(streamEvent4, streamEvent.getNext());
}
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)121 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)42 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)41 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)23 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)20 Test (org.testng.annotations.Test)19 Event (org.wso2.siddhi.core.event.Event)16 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)16 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)10 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)9 HashSet (java.util.HashSet)8 StreamEventConverter (org.wso2.siddhi.core.event.stream.converter.StreamEventConverter)8 Attribute (org.wso2.siddhi.query.api.definition.Attribute)8 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)7 ConversionStreamEventChunk (org.wso2.siddhi.core.event.stream.converter.ConversionStreamEventChunk)6 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)6 HashMap (java.util.HashMap)5