Java Code Examples for io.siddhi.core.stream.input.InputHandler#send()
The following examples show how to use
io.siddhi.core.stream.input.InputHandler#send() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogicalAbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"testQueryAbsent34"}) public void testQueryAbsent35() throws InterruptedException { log.info("Test the query (not e1 for 1 sec or not e2 for 1 sec) -> e3 with e2 and e3"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from (not Stream1[price>10] for 1 sec or not Stream2[price>20] for 1 sec) -> e3=Stream3[price>30] " + "select e3.symbol as symbol " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1", new Object[]{"WSO2"}); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); siddhiAppRuntime.start(); Thread.sleep(500); stream2.send(new Object[]{"IBM", 25.0f, 100}); Thread.sleep(600); stream3.send(new Object[]{"WSO2", 35.0f, 100}); Thread.sleep(100); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 1, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertTrue("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 2
Source File: MinForeverAggregatorExtensionTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void minForeverAttributeAggregatorTest7() throws InterruptedException { log.info("minForeverAttributeAggregator Test 7"); SiddhiManager siddhiManager = new SiddhiManager(); String execPlan = "" + "@app:name('minForeverAttributeAggregatorTests') " + "" + "define stream cseEventStream (price1 double, price2 double, price3 double);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select minForever(price1) as max " + "insert into outputStream;"; SiddhiAppRuntime execPlanRunTime = siddhiManager.createSiddhiAppRuntime(execPlan); execPlanRunTime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); AssertJUnit.assertEquals(10.0, inEvents[1].getData()[0]); } }); InputHandler inputHandler = execPlanRunTime.getInputHandler("cseEventStream"); execPlanRunTime.start(); inputHandler.send(new Object[]{null, 20.0, null}); inputHandler.send(new Object[]{10.0, 20.0, 25.0}); Thread.sleep(100); execPlanRunTime.shutdown(); }
Example 3
Source File: UpdateFromTableTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void updateFromTableTest2() throws InterruptedException { log.info("updateFromTableTest2"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "update StockTable " + " on StockTable.symbol==symbol ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 75.6f, 100L}); stockStream.send(new Object[]{"WSO2", 57.6f, 100L}); updateStockStream.send(new Object[]{"WSO2", 10f, 100L}); Thread.sleep(500); siddhiAppRuntime.shutdown(); }
Example 4
Source File: ExternalTimeBatchWindowTestCase.java From siddhi with Apache License 2.0 | 5 votes |
private int sendEvent(InputHandler input, int ite, long externalTs) throws Exception { int len = 3; Event[] events = new Event[len]; for (int i = 0; i < len; i++) { // cpu int, memory int, bytesIn long, bytesOut long, timestamp long events[i] = new Event(externalTs, new Object[]{15 + 10 * i * ite, 1500 + 10 * i * ite, 1000L, 2000L, externalTs + ite * 10000 + i * 50}); } input.send(events); return len; }
Example 5
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery17() throws InterruptedException { log.info("Partition test17"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiApp siddhiApp = new SiddhiApp("plan17"); StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT); siddhiApp.defineStream(streamDefinition); Partition partition = Partition.partition(). with("cseEventStream", Partition.range("LessValue", Expression.compare( Expression.value(200), Compare.Operator.GREATER_THAN, Expression.variable("volume")) ), Partition.range("HighValue", Expression.compare( Expression.value(200), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")) )); Query query = Query.query(); query.from(InputStream.stream("cseEventStream")); query.select( Selector.selector(). select("sumvolume", Expression.function("sum", Expression.variable("volume"))) ); query.insertInto("StockStream"); partition.addQuery(query); siddhiApp.addPartition(partition); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("StockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(100L, event.getData()[0]); } else if (count.get() == 2) { AssertJUnit.assertEquals(600L, event.getData()[0]); } else if (count.get() == 3) { AssertJUnit.assertEquals(200L, event.getData()[0]); } else if (count.get() == 4) { AssertJUnit.assertEquals(250L, event.getData()[0]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"WSO2", 75.6f, 600}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"ORACLE", 75.6f, 50}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example 6
Source File: PrimaryKeyTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void primaryKeyTableTest12() throws InterruptedException { log.info("primaryKeyTableTest12"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long);" + "@PrimaryKey('volume') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select price, volume " + "update StockTable " + " on StockTable.volume < volume;" + "" + "@info(name = 'query3') " + "from CheckStockStream join StockTable " + " on CheckStockStream.volume >= StockTable.volume " + "select StockTable.price, StockTable.volume " + "insert into OutStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); try { siddhiAppRuntime.addCallback("query3", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { for (Event event : inEvents) { inEventsList.add(event.getData()); inEventCount.incrementAndGet(); } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 200L}); stockStream.send(new Object[]{"IBM", 55.6f, 100L}); checkStockStream.send(new Object[]{"WSO2", 200L}); updateStockStream.send(new Object[]{"FOO", 77.6f, 200L}); checkStockStream.send(new Object[]{"BAR", 200L}); List<Object[]> expected1 = Arrays.asList( new Object[]{55.6f, 200L}, new Object[]{55.6f, 100L} ); List<Object[]> expected2 = Arrays.asList( new Object[]{55.6f, 200L}, new Object[]{55.6f, 100L} ); SiddhiTestHelper.waitForEvents(100, 4, inEventCount, 60000); AssertJUnit.assertEquals("In first events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList.subList(0, 2), expected1)); AssertJUnit.assertEquals("In second events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList.subList(2, 4), expected2)); AssertJUnit.assertEquals("Number of success events", 4, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); } finally { siddhiAppRuntime.shutdown(); } }
Example 7
Source File: AbsentSequenceTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"testQueryAbsent21"}) public void testQueryAbsent22() throws InterruptedException { log.info("Test the query e1, e2, not e3 for 1 sec, e4 with e1, e2, e3, and e4"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); " + "define stream Stream3 (symbol string, price float, volume int); " + "define stream Stream4 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>10], e2=Stream2[price>20], not Stream3[price>30] for 1 sec, " + "e4=Stream4[price>40] " + "select e1.symbol as symbol1, e2.symbol as symbol2, e4.symbol as symbol4 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); TestUtil.TestCallback callback = TestUtil.addQueryCallback(siddhiAppRuntime, "query1"); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); InputHandler stream3 = siddhiAppRuntime.getInputHandler("Stream3"); InputHandler stream4 = siddhiAppRuntime.getInputHandler("Stream4"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 15.6f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 28.7f, 100}); Thread.sleep(100); stream3.send(new Object[]{"GOOGLE", 38.7f, 100}); Thread.sleep(1100); stream4.send(new Object[]{"ORACLE", 44.7f, 100}); TestUtil.waitForInEvents(100, callback, 5); callback.throwAssertionErrors(); AssertJUnit.assertEquals("Number of success events", 0, callback.getInEventCount()); AssertJUnit.assertEquals("Number of remove events", 0, callback.getRemoveEventCount()); AssertJUnit.assertFalse("Event arrived", callback.isEventArrived()); siddhiAppRuntime.shutdown(); }
Example 8
Source File: SandboxTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void sandboxTest2() throws InterruptedException { log.info("sandbox test2"); SiddhiManager siddhiManager = new SiddhiManager(); String app = "" + "@source(type='foo')" + "@source(type='foo1')" + "@sink(type='foo1')" + "@source(type='inMemory', topic='myTopic')" + "define stream StockStream (symbol string, price float, vol long);\n" + "" + "@sink(type='foo1')" + "@sink(type='inMemory', topic='myTopic1')" + "define stream DeleteStockStream (symbol string, price float, vol long);\n" + "" + "@store(type='rdbms')" + "define table StockTable (symbol string, price float, volume long);\n" + "" + "define stream CountStockStream (symbol string);\n" + "" + "@info(name = 'query1') " + "from StockStream " + "select symbol, price, vol as volume " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from DeleteStockStream[vol>=100] " + "delete StockTable " + " on StockTable.symbol==symbol ;" + "" + "@info(name = 'query3') " + "from CountStockStream#window.length(0) join StockTable" + " on CountStockStream.symbol==StockTable.symbol " + "select CountStockStream.symbol as symbol " + "insert into CountResultsStream ;"; SiddhiApp siddhiApp = SiddhiCompiler.parse(app); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSandboxSiddhiAppRuntime(siddhiApp); Assert.assertEquals(siddhiAppRuntime.getSources().size(), 1); Assert.assertEquals(siddhiAppRuntime.getSinks().size(), 1); Assert.assertEquals(siddhiAppRuntime.getTables().size(), 1); for (List<Source> sources : siddhiAppRuntime.getSources()) { for (Source source : sources) { Assert.assertTrue(source.getType().equalsIgnoreCase("inMemory")); } } for (List<Sink> sinks : siddhiAppRuntime.getSinks()) { for (Sink sink : sinks) { Assert.assertTrue(sink.getType().equalsIgnoreCase("inMemory")); } } for (Table table : siddhiAppRuntime.getTables()) { Assert.assertTrue(table instanceof InMemoryTable); } InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler deleteStockStream = siddhiAppRuntime.getInputHandler("DeleteStockStream"); InputHandler countStockStream = siddhiAppRuntime.getInputHandler("CountStockStream"); siddhiAppRuntime.addCallback("CountResultsStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); } }); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 75.6f, 100L}); stockStream.send(new Object[]{"WSO2", 57.6f, 100L}); deleteStockStream.send(new Object[]{"IBM", 57.6f, 100L}); countStockStream.send(new Object[]{"WSO2"}); Thread.sleep(500); Assert.assertEquals(count.get(), 2); siddhiAppRuntime.shutdown(); }
Example 9
Source File: PrimaryKeyTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void primaryKeyTableTest13() throws InterruptedException { log.info("primaryKeyTableTest13"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long);" + "@PrimaryKey('volume') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select price, volume " + "update StockTable " + " on StockTable.volume >= volume;" + "" + "@info(name = 'query3') " + "from CheckStockStream join StockTable " + " on CheckStockStream.volume <= StockTable.volume " + "select StockTable.price, StockTable.volume " + "insert into OutStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); try { siddhiAppRuntime.addCallback("query3", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { for (Event event : inEvents) { inEventsList.add(event.getData()); inEventCount.incrementAndGet(); } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 200L}); stockStream.send(new Object[]{"IBM", 55.6f, 100L}); checkStockStream.send(new Object[]{"WSO2", 200L}); updateStockStream.send(new Object[]{"FOO", 77.6f, 200L}); checkStockStream.send(new Object[]{"BAR", 200L}); List<Object[]> expected = Arrays.asList( new Object[]{55.6f, 200L}, new Object[]{77.6f, 200L} ); SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000); AssertJUnit.assertEquals("In first events matched", true, SiddhiTestHelper.isEventsMatch(inEventsList, expected)); AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); } finally { siddhiAppRuntime.shutdown(); } }
Example 10
Source File: Aggregation2TestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"incrementalStreamProcessorTest57"}) public void incrementalStreamProcessorTest5SGTTimeZoneHour() throws InterruptedException { LOG.info("incrementalStreamProcessorTest5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> systemConfigs = new HashMap<>(); systemConfigs.put("aggTimeZone", "Asia/Singapore"); ConfigManager configManager = new InMemoryConfigManager(null, null, systemConfigs); siddhiManager.setConfigManager(configManager); String stockStream = "define stream stockStream (symbol string, price float, timestamp long);"; String query = " define aggregation stockAggregation " + "from stockStream " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "aggregate by timestamp every hour ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(stockStream + query); InputHandler stockStreamInputHandler = siddhiAppRuntime.getInputHandler("stockStream"); siddhiAppRuntime.start(); // Monday December 31, 2019 00:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 50f, 1577721601000L}); // Tuesday December 31, 2019 00:59:59 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 70f, 1577725199000L}); // Tuesday December 31, 2019 01:00:01 (am) in time zone Asia/Singapore (+08) stockStreamInputHandler.send(new Object[]{"WSO2", 80f, 1577725201000L}); Thread.sleep(2000); Event[] events = siddhiAppRuntime.query("from stockAggregation " + "within \"2019-**-** **:**:**\" " + "per \"hour\""); EventPrinter.print(events); Assert.assertNotNull(events, "Queried results cannot be null."); AssertJUnit.assertEquals(2, events.length); List<Object[]> eventsOutputList = new ArrayList<>(); for (Event event : events) { eventsOutputList.add(event.getData()); } List<Object[]> expected = Arrays.asList( new Object[]{1577721600000L, "WSO2", 60.0}, new Object[]{1577725200000L, "WSO2", 80.0} ); AssertJUnit.assertTrue("In events matched", SiddhiTestHelper.isUnsortedEventsMatch(eventsOutputList, expected)); siddhiAppRuntime.shutdown(); }
Example 11
Source File: ExtensionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void extensionTest5() throws InterruptedException, ClassNotFoundException { log.info("extension test5"); SiddhiManager siddhiManager = new SiddhiManager(); Map<String, String> configMap = new HashMap<>(); configMap.put("email.getAllNew.append.abc", "true"); siddhiManager.setConfigManager(new InMemoryConfigManager(configMap, null)); siddhiManager.setExtension("custom:plus", CustomFunctionExtension.class); siddhiManager.setExtension("email:getAllNew", StringConcatAggregatorExecutorString.class); String cseEventStream = "" + "" + "define stream cseEventStream (symbol string, price float, volume long);"; String query = ("" + "@info(name = 'query1') " + "from cseEventStream " + "select price , email:getAllNew(symbol,'') as toConcat " + "group by volume " + "insert into mailOutput;"); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count = count + inEvents.length; if (count == 3) { AssertJUnit.assertEquals("WSO2ABC-abc", inEvents[inEvents.length - 1].getData(1)); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 100L}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 60.5f, 200L}); Thread.sleep(100); inputHandler.send(new Object[]{"ABC", 60.5f, 200L}); Thread.sleep(100); AssertJUnit.assertEquals(3, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 12
Source File: CustomJoinWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
/** * Window shares locks event outside of queries. This test is to ensure that there is no * deadlock according to the implementation. * * @throws InterruptedException throw exception if interrupted the input handler sender. */ @Test public void testJoinWindowWithWindowForDeadLock() throws InterruptedException { log.info("Test join window with another window for deadlock"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream TempStream(deviceID long, roomNo int, temp double); " + "define stream RegulatorStream(deviceID long, roomNo int, isOn bool); " + "define window TempWindow(deviceID long, roomNo int, temp double) time(1 min); " + "define window RegulatorWindow(deviceID long, roomNo int, isOn bool) length(1); " + "define window RegulatorActionWindow(deviceID long, roomNo int, action string) timeBatch(1 sec); "; String query = "" + "@info(name = 'query1') " + "from TempStream[temp > 30.0] " + "insert into TempWindow; " + "" + "@info(name = 'query2') " + "from RegulatorStream[isOn == false] " + "insert into RegulatorWindow; " + "" + "@info(name = 'query3') " + "from TempWindow " + "join RegulatorWindow " + "on TempWindow.roomNo == RegulatorWindow.roomNo " + "select RegulatorWindow.deviceID as deviceID, TempWindow.roomNo as roomNo, 'start' as action " + "insert into RegulatorActionWindow; " + "" + "@info(name = 'query5') " + "from RegulatorActionWindow join TempWindow " + "on TempWindow.roomNo == RegulatorActionWindow.roomNo " + "select RegulatorActionWindow.deviceID as deviceID, TempWindow.roomNo as roomNo, true as isOn " + "insert into OutputStream; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); inEventCount += events.length; } }); InputHandler tempStream = siddhiAppRuntime.getInputHandler("TempStream"); InputHandler regulatorStream = siddhiAppRuntime.getInputHandler("RegulatorStream"); siddhiAppRuntime.start(); tempStream.send(new Object[]{100L, 1, 20.0}); tempStream.send(new Object[]{100L, 2, 25.0}); tempStream.send(new Object[]{100L, 3, 30.0}); tempStream.send(new Object[]{100L, 4, 35.0}); tempStream.send(new Object[]{100L, 5, 40.0}); regulatorStream.send(new Object[]{100L, 1, false}); regulatorStream.send(new Object[]{100L, 2, false}); regulatorStream.send(new Object[]{100L, 3, false}); regulatorStream.send(new Object[]{100L, 4, false}); regulatorStream.send(new Object[]{100L, 5, false}); Thread.sleep(1500); assertEquals("Number of success events", 2, inEventCount); siddhiAppRuntime.shutdown(); }
Example 13
Source File: PatternPartitionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPatternPartitionQuery12() throws InterruptedException { log.info("testPatternCount4 - OUT 1"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); "; String partitionStart = "partition with (volume of Stream1,volume of Stream2) begin "; String query = "" + "@info(name = 'query1') " + "from e1=Stream1[price>20] <2:5> -> e2=Stream2[price>20] " + "select e1[0].price as price1_0, e1[1].price as price1_1, e1[2].price as price1_2, " + " e1[3].price as price1_3, e2.price as price2 " + "insert into OutputStream ;"; String partitionEnd = "end"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + partitionStart + query + partitionEnd); siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { if (event.isExpired()) { removeEventCount.incrementAndGet(); } else { inEventCount.incrementAndGet(); } eventArrived = true; } } }); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"WSO2", 25.6f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 45.7f, 100}); Thread.sleep(100); AssertJUnit.assertEquals("Number of success events", 0, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount.get()); AssertJUnit.assertEquals("Event arrived", false, eventArrived); siddhiAppRuntime.shutdown(); }
Example 14
Source File: JoinTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testTableJoinQuery2() throws InterruptedException { log.info("testTableJoinQuery2 - OUT 1"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string); " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream#window.length(1) join StockTable " + " on CheckStockStream.symbol==StockTable.symbol " + "select CheckStockStream.symbol as checkSymbol, StockTable.symbol as symbol, StockTable.volume as " + "volume " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("query2", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); if (inEvents != null) { for (Event event : inEvents) { inEventCount++; switch (inEventCount) { case 1: AssertJUnit.assertArrayEquals(new Object[]{"WSO2", "WSO2", 100L}, event.getData()); break; default: AssertJUnit.assertSame(1, inEventCount); } } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 100L}); stockStream.send(new Object[]{"IBM", 75.6f, 10L}); checkStockStream.send(new Object[]{"WSO2"}); Thread.sleep(500); AssertJUnit.assertEquals("Number of success events", 1, inEventCount); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); siddhiAppRuntime.shutdown(); }
Example 15
Source File: PrimaryKeyTableTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void primaryKeyTableTest25() throws InterruptedException { log.info("primaryKeyTableTest25"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "@PrimaryKey('volume') " + "define table StockTable (symbol string, price float, volume long); "; String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from CheckStockStream[(volume <= StockTable.volume) in StockTable] " + "insert into OutStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); try { siddhiAppRuntime.addCallback("query2", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { for (Event event : inEvents) { inEventsList.add(event.getData()); inEventCount.incrementAndGet(); } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream"); InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream"); siddhiAppRuntime.start(); stockStream.send(new Object[]{"WSO2", 55.6f, 200L}); stockStream.send(new Object[]{"BAR", 55.6f, 150L}); stockStream.send(new Object[]{"IBM", 55.6f, 100L}); checkStockStream.send(new Object[]{"FOO", 170L}); checkStockStream.send(new Object[]{"FOO", 200L}); List<Object[]> expected = new ArrayList<Object[]>(); expected.add(new Object[]{"FOO", 170L}); expected.add(new Object[]{"FOO", 200L}); SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000); AssertJUnit.assertEquals("In events matched", true, SiddhiTestHelper.isUnsortedEventsMatch(inEventsList, expected)); AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); } finally { siddhiAppRuntime.shutdown(); } }
Example 16
Source File: EveryPatternTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testQuery6() throws InterruptedException { log.info("testPatternEvery6 - OUT 2"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream Stream1 (symbol string, price float, volume int); " + "define stream Stream2 (symbol string, price float, volume int); "; String query = "" + "@info(name = 'query1') " + "from e4=Stream1[symbol=='MSFT'] -> every ( e1=Stream1[price>20] -> e3=Stream1[price>20]) -> " + " e2=Stream2[price>e1.price] " + "select e1.price as price1, e3.price as price3, e2.price as price2 " + "insert into OutputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { for (Event event : inEvents) { inEventCount++; switch (inEventCount) { case 1: AssertJUnit.assertArrayEquals(new Object[]{55.7f, 54f, 57.7f}, event.getData()); break; case 2: AssertJUnit.assertArrayEquals(new Object[]{53.6f, 53f, 57.7f}, event.getData()); break; default: AssertJUnit.assertSame(2, inEventCount); } } eventArrived = true; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); InputHandler stream2 = siddhiAppRuntime.getInputHandler("Stream2"); siddhiAppRuntime.start(); stream1.send(new Object[]{"MSFT", 55.6f, 100}); Thread.sleep(100); stream1.send(new Object[]{"WSO2", 55.7f, 100}); Thread.sleep(100); stream1.send(new Object[]{"GOOG", 54f, 100}); Thread.sleep(100); stream1.send(new Object[]{"WSO2", 53.6f, 100}); Thread.sleep(100); stream1.send(new Object[]{"GOOG", 53f, 100}); Thread.sleep(100); stream2.send(new Object[]{"IBM", 57.7f, 100}); Thread.sleep(100); AssertJUnit.assertEquals("Number of success events", 2, inEventCount); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount); AssertJUnit.assertEquals("Event arrived", true, eventArrived); siddhiAppRuntime.shutdown(); }
Example 17
Source File: PersistenceTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "persistenceTest5") public void persistenceTest6() throws InterruptedException { log.info("persistence test 6 - batch window query"); PersistenceStore persistenceStore = new InMemoryPersistenceStore(); SiddhiManager siddhiManager = new SiddhiManager(); siddhiManager.setPersistenceStore(persistenceStore); String siddhiApp = "" + "@app:name('Test') " + "" + "define stream StockStream ( symbol string, price float, volume int );" + "" + "@info(name = 'query1')" + "from StockStream[price>10]#window.timeBatch(10) " + "select symbol, price, sum(volume) as totalVol " + "insert into OutStream "; QueryCallback queryCallback = new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); eventArrived = true; for (Event inEvent : inEvents) { count++; AssertJUnit.assertTrue("IBM".equals(inEvent.getData(0)) || "WSO2".equals(inEvent.getData(0))); } } }; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", queryCallback); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("StockStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); Thread.sleep(500); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertEquals(2, count); //persisting Thread.sleep(500); siddhiAppRuntime.persist(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); //restarting siddhi app Thread.sleep(500); siddhiAppRuntime.shutdown(); siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", queryCallback); inputHandler = siddhiAppRuntime.getInputHandler("StockStream"); siddhiAppRuntime.start(); //loading try { siddhiAppRuntime.restoreLastRevision(); } catch (CannotRestoreSiddhiAppStateException e) { log.error(e.getMessage(), e); Assert.fail("Restoring of Siddhi app " + siddhiAppRuntime.getName() + " failed"); } inputHandler.send(new Object[]{"IBM", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); //shutdown siddhi app Thread.sleep(500); siddhiAppRuntime.shutdown(); AssertJUnit.assertEquals(count, 6); AssertJUnit.assertEquals(true, eventArrived); }
Example 18
Source File: SortWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void sortWindowTest2() throws InterruptedException { log.info("sortWindow test2"); SiddhiManager siddhiManager = new SiddhiManager(); String planName = "@app:name('sortWindow2') "; String cseEventStream = "" + "define stream cseEventStream (symbol string, price int, volume long);"; String query = "" + "@info(name = 'query1') " + "from cseEventStream#window.sort(2,volume, 'asc', price, 'desc') " + "select price, volume " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(planName + cseEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { inEventCount = inEventCount + inEvents.length; } if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50, 100L}); inputHandler.send(new Object[]{"IBM", 20, 100L}); inputHandler.send(new Object[]{"WSO2", 40, 50L}); inputHandler.send(new Object[]{"WSO2", 100, 20L}); inputHandler.send(new Object[]{"WSO2", 50, 50L}); Thread.sleep(1000); AssertJUnit.assertEquals(5, inEventCount); AssertJUnit.assertEquals(3, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 19
Source File: ExpressionWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void expressionWindowTest6() throws InterruptedException { log.info("Testing expression window 6"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int, expr string);"; String query = "@info(name = 'query1') " + "from cseEventStream#window.expression(expr) " + "select symbol, price " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); inEventCount = inEventCount + inEvents.length; AssertJUnit.assertEquals(1, inEvents.length); if (removeEvents != null) { removeEventCount = removeEventCount + removeEvents.length; AssertJUnit.assertEquals(1, removeEvents.length); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); String expr = "eventTimestamp(last) - eventTimestamp(first) < 2"; inputHandler.send(0, new Object[]{"WSO2", 60.5f, 0, expr}); inputHandler.send(1, new Object[]{"WSO2", 61.5f, 1, expr}); expr = "eventTimestamp(last) - eventTimestamp(first) < 4"; inputHandler.send(2, new Object[]{"WSO2", 62.5f, 2, expr}); inputHandler.send(3, new Object[]{"WSO2", 63.5f, 3, expr}); inputHandler.send(4, new Object[]{"WSO2", 64.5f, 4, expr}); AssertJUnit.assertEquals(5, inEventCount); AssertJUnit.assertEquals(1, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example 20
Source File: QuerySyncTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void querySyncTest1() throws InterruptedException { log.info("querySync test1"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "" + "define stream cseEventStream (symbol string, price float, volume int);"; String query = "" + "@info(name = 'query1') " + "@synchronized('true') " + "from cseEventStream#window.time(2 sec) " + "select symbol,price,volume " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timestamp, inEvents, removeEvents); if (inEvents != null) { inEventCount.addAndGet(inEvents.length); } if (removeEvents != null) { AssertJUnit.assertTrue("InEvents arrived before RemoveEvents", inEventCount.get() > removeEventCount .get()); removeEventCount.addAndGet(removeEvents.length); } eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 0}); inputHandler.send(new Object[]{"WSO2", 60.5f, 1}); Thread.sleep(4000); AssertJUnit.assertEquals(2, inEventCount.get()); AssertJUnit.assertEquals(2, removeEventCount.get()); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }