use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter 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());
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.
the class EventTestCase method testStreamEventConverter.
@Test
public void testStreamEventConverter() {
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addData(volume);
metaStreamEvent.initializeAfterWindowData();
metaStreamEvent.addData(price);
metaStreamEvent.addOutputData(symbol);
// complex attribute
metaStreamEvent.addOutputData(null);
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 SelectiveStreamEventConverter);
// volume
AssertJUnit.assertEquals(1, borrowedEvent.getBeforeWindowData().length);
// price
AssertJUnit.assertEquals(1, borrowedEvent.getOnAfterWindowData().length);
// symbol and avgPrice
AssertJUnit.assertEquals(2, borrowedEvent.getOutputData().length);
AssertJUnit.assertEquals(50, borrowedEvent.getBeforeWindowData()[0]);
AssertJUnit.assertEquals(200, borrowedEvent.getOnAfterWindowData()[0]);
AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.
the class EventTestCase method testPassThroughStreamEventConverter.
@Test
public void testPassThroughStreamEventConverter() {
Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
Attribute price = new Attribute("price", Attribute.Type.DOUBLE);
Attribute volume = new Attribute("volume", Attribute.Type.INT);
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addOutputDataAllowingDuplicate(symbol);
metaStreamEvent.addOutputDataAllowingDuplicate(price);
metaStreamEvent.addOutputDataAllowingDuplicate(volume);
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.0, 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 ZeroStreamEventConverter);
AssertJUnit.assertEquals(3, borrowedEvent.getOutputData().length);
AssertJUnit.assertEquals("WSO2", borrowedEvent.getOutputData()[0]);
AssertJUnit.assertEquals(200.0, borrowedEvent.getOutputData()[1]);
AssertJUnit.assertEquals(50, borrowedEvent.getOutputData()[2]);
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.
the class MultiProcessStreamReceiver method receive.
@Override
public void receive(Event event) {
synchronized (this) {
stabilizeStates();
for (int anEventSequence : eventSequence) {
StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
aStreamEventConverter.convertEvent(event, borrowedEvent);
process(anEventSequence, borrowedEvent);
}
}
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.
the class MultiProcessStreamReceiver method receive.
@Override
public void receive(long timestamp, Object[] data) {
synchronized (this) {
stabilizeStates();
for (int anEventSequence : eventSequence) {
StreamEventConverter aStreamEventConverter = streamEventConverters[anEventSequence];
StreamEventPool aStreamEventPool = streamEventPools[anEventSequence];
StreamEvent borrowedEvent = aStreamEventPool.borrowEvent();
aStreamEventConverter.convertData(timestamp, data, borrowedEvent);
process(anEventSequence, borrowedEvent);
}
}
}
Aggregations