use of org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery67.
// ************************************************************************************************************
// Test cases for less than or equal
@Test
public void testFilterQuery67() throws InterruptedException {
log.info("Filter test67");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(60d))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 50d, 60L });
inputHandler.send(new Object[] { "WSO2", 70d, 40L });
inputHandler.send(new Object[] { "WSO2", 44d, 200L });
Thread.sleep(100);
AssertJUnit.assertEquals(2, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class FilterTestCase1 method testFilterQuery75.
@Test
public void testFilterQuery75() throws InterruptedException {
log.info("Filter test75");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(3L))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 500f, 60d, 6 });
inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
inputHandler.send(new Object[] { "WSO2", 60f, 300d, 4 });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class SingleClientDistributedSink method initTransport.
@Override
public void initTransport(OptionHolder sinkOptionHolder, List<OptionHolder> destinationOptionHolders, Annotation sinkAnnotation, ConfigReader sinkConfigReader, SiddhiAppContext siddhiAppContext) {
final String transportType = sinkOptionHolder.validateAndGetStaticValue(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
Extension sinkExtension = DefinitionParserHelper.constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SINK, transportType, sinkAnnotation, SiddhiConstants.NAMESPACE_SINK);
Set<String> allDynamicOptionKeys = findAllDynamicOptions(destinationOptionHolders);
destinationOptionHolders.forEach(optionHolder -> {
optionHolder.merge(sinkOptionHolder);
allDynamicOptionKeys.forEach(optionKey -> {
String optionValue = optionHolder.getOrCreateOption(optionKey, null).getValue();
if (optionValue == null || optionValue.isEmpty()) {
throw new SiddhiAppValidationException("Destination properties can only contain " + "non-empty static values.");
}
Option sinkOption = sinkOptionHolder.getOrAddStaticOption(optionKey, optionValue);
sinkOption.addVariableValue(optionValue);
destinationCount++;
});
});
this.sink = (Sink) SiddhiClassLoader.loadExtensionImplementation(sinkExtension, SinkExecutorExtensionHolder.getInstance(siddhiAppContext));
this.sink.initOnlyTransport(streamDefinition, sinkOptionHolder, sinkConfigReader, siddhiAppContext);
}
use of org.wso2.siddhi.query.api.definition.StreamDefinition 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, 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, 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 org.wso2.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class JunctionTestCase method junctionToReceiverTest.
@Test
public void junctionToReceiverTest() throws InterruptedException {
log.info("junction to receiver");
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, siddhiAppContext);
StreamJunction.Publisher streamPublisherA = streamJunctionA.constructPublisher();
StreamCallback streamCallback = new StreamCallback() {
@Override
public void receive(Event[] streamEvents) {
count += streamEvents.length;
eventArrived = true;
}
};
streamJunctionA.subscribe(streamCallback);
streamJunctionA.startProcessing();
streamPublisherA.send(new StreamEvent(2, 2, 2));
streamPublisherA.send(new StreamEvent(2, 2, 2));
Thread.sleep(100);
AssertJUnit.assertTrue(eventArrived);
AssertJUnit.assertEquals(2, count);
streamJunctionA.stopProcessing();
}
Aggregations