use of org.wso2.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);
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());
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class EventTestCase method testConditionExpressionExecutors.
@Test
public void testConditionExpressionExecutors() {
// StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
// .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
priceVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 1 });
VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
volumeVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 2 });
ExpressionExecutor compareLessThanExecutor = new LessThanCompareConditionExpressionExecutorFloatFloat(new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(compareLessThanExecutor, compareGreaterThanExecutor);
int count = 0;
for (int i = 0; i < 3; i++) {
StreamEvent event = new StreamEvent(0, 0, 3);
event.setOutputData(new Object[] { "WSO2", i * 11f, 5 });
if ((Boolean) andExecutor.execute(event)) {
count++;
}
}
AssertJUnit.assertEquals("Two events should pass through executor", 2, count);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent 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]);
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project carbon-apimgt by wso2.
the class EmitOnStateChange method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, ComplexEventPopulater complexEventPopulater) {
while (streamEventChunk.hasNext()) {
StreamEvent event = streamEventChunk.next();
Boolean currentThrottleState = (Boolean) isThrottledExpressionExecutor.execute(event);
String key = (String) keyExpressionExecutor.execute(event);
Boolean lastThrottleState = throttleStateMap.get(key);
if (lastThrottleState == currentThrottleState && !currentThrottleState) {
streamEventChunk.remove();
} else {
throttleStateMap.put(key, currentThrottleState);
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.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, 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();
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();
}
Aggregations