use of io.siddhi.core.event.stream.StreamEventFactory 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);
StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
StreamEvent newEvent = eventPool.newInstance();
converter.convertEvent(event, newEvent);
AssertJUnit.assertTrue(converter instanceof ZeroStreamEventConverter);
AssertJUnit.assertEquals(3, newEvent.getOutputData().length);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
AssertJUnit.assertEquals(200.0, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals(50, newEvent.getOutputData()[2]);
}
use of io.siddhi.core.event.stream.StreamEventFactory 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);
StreamEventFactory eventPool = new StreamEventFactory(metaStreamEvent);
StreamEvent newEvent = eventPool.newInstance();
converter.convertEvent(event, newEvent);
AssertJUnit.assertTrue(converter instanceof SimpleStreamEventConverter);
AssertJUnit.assertNull(newEvent.getBeforeWindowData());
AssertJUnit.assertNull(newEvent.getOnAfterWindowData());
AssertJUnit.assertEquals(2, newEvent.getOutputData().length);
AssertJUnit.assertEquals(200, newEvent.getOutputData()[1]);
AssertJUnit.assertEquals("WSO2", newEvent.getOutputData()[0]);
}
use of io.siddhi.core.event.stream.StreamEventFactory 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);
StreamEventFactory streamEventFactory = new StreamEventFactory(0, 0, 3);
ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventFactory);
streamEventChunk.convertAndAssign(streamEvent1);
while (streamEventChunk.hasNext()) {
streamEventChunk.next();
streamEventChunk.remove();
}
AssertJUnit.assertNull(streamEventChunk.getFirst());
}
use of io.siddhi.core.event.stream.StreamEventFactory 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);
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 || count == 2) {
streamEventChunk.remove();
}
}
StreamEvent streamEvent = streamEventChunk.getFirst();
AssertJUnit.assertEquals(streamEvent3, streamEvent);
AssertJUnit.assertEquals(streamEvent4, streamEvent.getNext());
}
Aggregations