use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter 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.converter.StreamEventConverter 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);
StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
streamEventChunk.convertAndAssign(streamEvent1);
while (streamEventChunk.hasNext()) {
streamEventChunk.next();
streamEventChunk.remove();
}
AssertJUnit.assertNull(streamEventChunk.getFirst());
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter 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);
StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
streamEventChunk.convertAndAssign(streamEvent1);
streamEventChunk.remove();
streamEventChunk.remove();
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter in project siddhi by wso2.
the class ComplexEventChunkTestCase method init.
@BeforeMethod
public void init() {
count = 0;
streamEventConverter = new ZeroStreamEventConverter();
}
use of org.wso2.siddhi.core.event.stream.converter.StreamEventConverter 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);
StreamEventPool streamEventPool = new StreamEventPool(0, 0, 3, 5);
ConversionStreamEventChunk streamEventChunk = new ConversionStreamEventChunk(streamEventConverter, streamEventPool);
streamEventChunk.convertAndAssign(streamEvent1);
while (streamEventChunk.hasNext()) {
count++;
StreamEvent event = streamEventChunk.next();
AssertJUnit.assertEquals(count * 1L, event.getOutputData()[2]);
}
AssertJUnit.assertEquals(3, count);
}
Aggregations