use of io.siddhi.core.event.stream.StreamEvent 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());
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class JunctionTestCase method oneToOneTest.
@Test
public void oneToOneTest() throws InterruptedException {
log.info("one to one");
StreamDefinition streamA = StreamDefinition.id("streamA").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
StreamJunction streamJunctionA = new StreamJunction(streamA, executorService, 1024, null, siddhiAppContext);
StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
StreamDefinition streamB = StreamDefinition.id("streamB").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).annotation(Annotation.annotation("parallel"));
StreamJunction streamJunctionB = new StreamJunction(streamB, executorService, 1024, null, siddhiAppContext);
final StreamJunction.Publisher streamPublisherB = streamJunctionB.constructPublisher();
StreamCallback streamCallbackA = new StreamCallback() {
@Override
public void receive(Event[] streamEvents) {
for (Event streamEvent : streamEvents) {
StreamEvent innerStreamEvent = new StreamEvent(2, 2, 2);
innerStreamEvent.setTimestamp(streamEvent.getTimestamp());
innerStreamEvent.setOutputData(streamEvent.getData());
streamPublisherB.send(innerStreamEvent);
}
}
};
StreamCallback streamCallbackB = new StreamCallback() {
@Override
public void receive(Event[] streamEvents) {
count += streamEvents.length;
eventArrived = true;
for (Event streamEvent : streamEvents) {
AssertJUnit.assertTrue(streamEvent.getData()[0].equals("IBM") || (streamEvent.getData()[0].equals("WSO2")));
}
}
};
streamJunctionA.subscribe(streamCallbackA);
streamJunctionA.startProcessing();
streamJunctionB.subscribe(streamCallbackB);
streamJunctionB.startProcessing();
// Thread.sleep(100);
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(2, count);
streamJunctionA.stopProcessing();
streamJunctionB.stopProcessing();
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class JunctionTestCase method multiThreadedTest1.
@Test
public void multiThreadedTest1() throws InterruptedException {
log.info("multi threaded 1");
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, null, 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, null, siddhiAppContext);
final StreamJunction.Publisher streamPublisherB1 = streamJunctionB.constructPublisher();
final StreamJunction.Publisher streamPublisherB2 = streamJunctionB.constructPublisher();
final StreamJunction.Publisher streamPublisherB3 = streamJunctionB.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());
innerStreamEvent.setOutputData(streamEvent.getData());
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());
innerStreamEvent.setOutputData(streamEvent.getData());
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());
innerStreamEvent.setOutputData(streamEvent.getData());
streamPublisherB3.send(innerStreamEvent);
}
}
};
StreamCallback streamCallbackB = new StreamCallback() {
@Override
public void receive(Event[] streamEvents) {
for (Event streamEvent : streamEvents) {
count++;
eventArrived = true;
AssertJUnit.assertTrue(streamEvent.getData()[0].equals("IBM") || (streamEvent.getData()[0].equals("WSO2")));
}
}
};
streamJunctionA.subscribe(streamCallbackA1);
streamJunctionA.subscribe(streamCallbackA2);
streamJunctionA.subscribe(streamCallbackA3);
streamJunctionA.startProcessing();
streamJunctionB.subscribe(streamCallbackB);
streamJunctionB.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(6, count);
streamJunctionA.stopProcessing();
streamJunctionB.stopProcessing();
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class EventTestCase method testEventCreation.
@Test
public void testEventCreation() {
EventExchangeHolderFactory eventExchangeHolderFactory = new EventExchangeHolderFactory(2);
AssertJUnit.assertEquals(2, eventExchangeHolderFactory.newInstance().getEvent().getData().length);
StreamEventFactory streamEventFactory = new StreamEventFactory(2, 3, 4);
StreamEvent streamEvent = streamEventFactory.newInstance();
AssertJUnit.assertEquals(2, streamEvent.getBeforeWindowData().length);
AssertJUnit.assertEquals(3, streamEvent.getOnAfterWindowData().length);
AssertJUnit.assertEquals(4, streamEvent.getOutputData().length);
}
use of io.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IncrementalDataAggregator method aggregateInMemoryData.
public ComplexEventChunk<StreamEvent> aggregateInMemoryData(Map<TimePeriod.Duration, Executor> incrementalExecutorMap) {
int startIndex = incrementalDurations.indexOf(durationToAggregate);
Set<String> groupByKeys = new HashSet<>();
for (int k = startIndex; k >= 0; k--) {
TimePeriod.Duration duration = incrementalDurations.get(k);
Executor incrementalExecutor = incrementalExecutorMap.get(duration);
if (incrementalExecutor instanceof IncrementalExecutor) {
BaseIncrementalValueStore aBaseIncrementalValueStore = ((IncrementalExecutor) incrementalExecutor).getBaseIncrementalValueStore();
Map<String, StreamEvent> groupedByEvents = aBaseIncrementalValueStore.getGroupedByEvents();
for (Map.Entry<String, StreamEvent> eventEntry : groupedByEvents.entrySet()) {
long startTimeOfAggregates = IncrementalTimeConverterUtil.getStartTimeOfAggregates(eventEntry.getValue().getTimestamp(), durationToAggregate, timeZone);
String groupByKey = eventEntry.getKey() + "-" + startTimeOfAggregates;
synchronized (this) {
groupByKeys.add(groupByKey);
SiddhiAppContext.startGroupByFlow(groupByKey);
ValueState state = (ValueState) valueStateHolder.getState();
try {
boolean shouldUpdate = true;
if (shouldUpdateTimestamp != null) {
shouldUpdate = shouldUpdate(shouldUpdateTimestamp.execute(eventEntry.getValue()), state);
} else {
state.lastTimestamp = oldestEventTimestamp;
}
// keeping timestamp value location as null
for (int i = 0; i < baseExecutorsForFind.size(); i++) {
ExpressionExecutor expressionExecutor = baseExecutorsForFind.get(i);
if (shouldUpdate) {
state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
} else if (!(expressionExecutor instanceof VariableExpressionExecutor)) {
state.setValue(expressionExecutor.execute(eventEntry.getValue()), i + 1);
}
}
} finally {
valueStateHolder.returnState(state);
SiddhiAppContext.stopGroupByFlow();
}
}
}
}
}
// clean all executors
for (String groupByKey : groupByKeys) {
SiddhiAppContext.startGroupByFlow(groupByKey);
try {
for (ExpressionExecutor expressionExecutor : baseExecutorsForFind) {
expressionExecutor.execute(resetEvent);
}
} finally {
SiddhiAppContext.stopGroupByFlow();
}
}
return getProcessedEventChunk();
}
Aggregations