Search in sources :

Example 11 with StreamEventFactory

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

the class SnapshotableEventQueueTestCase method incrementalPersistenceTest2.

@Test
public void incrementalPersistenceTest2() throws InterruptedException, IOException, ClassNotFoundException {
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addOutputData(new Attribute("symbol", Attribute.Type.STRING));
    metaStreamEvent.addOutputData(new Attribute("price", Attribute.Type.FLOAT));
    metaStreamEvent.addOutputData(new Attribute("volume", Attribute.Type.LONG));
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, new StreamEventFactory(metaStreamEvent));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setOutputData(new Object[] { "IBM", 500.6f, 1 });
    for (int i = 0; i < 10; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    HashMap<Long, String> snapshots = new HashMap<>();
    Snapshot snapshot1 = snapshotableStreamEventQueue.getSnapshot();
    StreamEvent streamEvents = (StreamEvent) snapshot1.getState();
    Assert.assertTrue(streamEvents != null);
    snapshots.put(3L, toString(snapshot1));
    for (int i = 7; i < 10; i++) {
        snapshotableStreamEventQueue.next();
        snapshotableStreamEventQueue.remove();
    }
    Snapshot snapshot2 = snapshotableStreamEventQueue.getSnapshot();
    ArrayList<Operation> operationLog = (ArrayList<Operation>) snapshot2.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(4L, toString(snapshot2));
    for (int i = 10; i < 15; i++) {
        streamEvent.getOutputData()[2] = i;
        snapshotableStreamEventQueue.add(streamEventCloner.copyStreamEvent(streamEvent));
    }
    Snapshot snapshot3 = snapshotableStreamEventQueue.getSnapshot();
    operationLog = (ArrayList<Operation>) snapshot3.getState();
    Assert.assertTrue(operationLog != null);
    snapshots.put(5L, toString(snapshot3));
    SnapshotableStreamEventQueue snapshotableStreamEventQueue2 = new SnapshotableStreamEventQueue(new StreamEventClonerHolder(streamEventCloner));
    SnapshotStateList snapshotStateList = new SnapshotStateList();
    for (Map.Entry<Long, String> entry : snapshots.entrySet()) {
        snapshotStateList.putSnapshotState(entry.getKey(), (Snapshot) fromString(entry.getValue()));
    }
    snapshotableStreamEventQueue2.restore(snapshotStateList);
    Assert.assertEquals(snapshotableStreamEventQueue, snapshotableStreamEventQueue2);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) HashMap(java.util.HashMap) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) Operation(io.siddhi.core.event.stream.Operation) StreamEventClonerHolder(io.siddhi.core.event.stream.holder.StreamEventClonerHolder) Snapshot(io.siddhi.core.util.snapshot.state.Snapshot) SnapshotStateList(io.siddhi.core.util.snapshot.state.SnapshotStateList) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) HashMap(java.util.HashMap) Map(java.util.Map) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) SnapshotableStreamEventQueue(io.siddhi.core.event.stream.holder.SnapshotableStreamEventQueue) Test(org.testng.annotations.Test)

Example 12 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory 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);
    StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
    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(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 13 with StreamEventFactory

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

the class ComplexEventChunkTestCase method eventChunkRemoveTest1.

@Test
public void eventChunkRemoveTest1() {
    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);
    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) {
            streamEventChunk.remove();
        }
    }
    AssertJUnit.assertEquals(streamEvent2, 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 14 with StreamEventFactory

use of io.siddhi.core.event.stream.StreamEventFactory 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);
    StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
    streamEventChunk.convertAndAssign(streamEvent1);
    streamEventChunk.remove();
    streamEventChunk.remove();
}
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 15 with StreamEventFactory

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

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);
    StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
    ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
    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(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