io.siddhi.core.stream.output.StreamCallback Java Examples
The following examples show how to use
io.siddhi.core.stream.output.StreamCallback.
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: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery2() throws InterruptedException { log.info("Partition test2"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest2') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream StockStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream , symbol of StockStream1) begin @info(name = 'query1') " + "from cseEventStream[700>price] select symbol,sum(price) as price,volume insert into OutStockStream ;" + " end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example #2
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery() throws InterruptedException { log.info("Partition test"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "partition with (symbol of streamA) " + "begin " + " @info(name = 'query1') " + " from streamA " + " select symbol, price " + " insert into StockQuote ; " + "end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); StreamCallback streamCallback = new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0))); count.addAndGet(events.length); eventArrived = true; } }; siddhiAppRuntime.addCallback("StockQuote", streamCallback); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700}); inputHandler.send(new Object[]{"WSO2", 60}); inputHandler.send(new Object[]{"WSO2", 60}); SiddhiTestHelper.waitForEvents(100, 3, count, 60000); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertEquals(3, count.get()); siddhiAppRuntime.shutdown(); }
Example #3
Source File: TriggerTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = "testQuery6") public void testQuery7() throws InterruptedException { log.info("testTrigger7 - OUT 2"); SiddhiManager siddhiManager = new SiddhiManager(); String plan = "" + "define stream cseEventStream (symbol string, price float, volume long);" + "define trigger triggerStream at '*/1 * * * * ?' ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(plan); siddhiAppRuntime.addCallback("triggerStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { long timestamp = event.getTimestamp(); count++; if (count > 1) { float triggerTimeDiff = timestamp / 1000 - lastTimeStamp / 1000; AssertJUnit.assertTrue(1 == Math.round(triggerTimeDiff)); } lastTimeStamp = timestamp; } eventArrived = true; } }); siddhiAppRuntime.start(); Thread.sleep(1000); siddhiAppRuntime.shutdown(); AssertJUnit.assertEquals(true, eventArrived); }
Example #4
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery23() throws InterruptedException { log.info("Partition test23"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest10') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream#window.time(1 sec) " + "select symbol, avg(price) as avgPrice, volume " + "having avgPrice >= 0 or avgPrice is null " + "insert expired events into OutStockStream ;" + "end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(null, event.getData()[1]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75f, 100}); SiddhiTestHelper.waitForEvents(200, 1, count, 60000); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example #5
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery31() throws InterruptedException { log.info("Partition test30"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest30') " + "define stream cseEventStream (atr1 string, atr2 float, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>atr5 OR atr4 == atr7 OR atr6 == atr8 OR atr3 " + "== atr7 OR atr5 == atr6 OR atr7 == atr3 OR atr8 == atr7 OR atr11 == atr6 OR atr8" + "== atr6 OR atr7 == atr5 OR atr6 == atr7 OR atr3 == atr2 OR atr2 == atr8 OR atr4 " + "== atr8 OR atr6 == atr3 OR atr2 == atr3 OR atr3 == atr11 OR atr10 == atr9] select" + " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ; end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105}); inputHandler.send(new Object[]{"WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106}); inputHandler.send(new Object[]{"IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 108}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example #6
Source File: TimeWindowTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void timeWindowTest3() throws InterruptedException { SiddhiManager siddhiManager = new SiddhiManager(); String queries = "define stream fireAlarmEventStream (deviceID string, sonar double);\n" + "@info(name = 'query1')\n" + "from fireAlarmEventStream#window.time(30 milliseconds)\n" + "select deviceID\n" + "insert expired events into analyzeStream;\n" + "" + "@info(name = 'query2')\n" + "from analyzeStream\n" + "select deviceID\n" + "insert into bulbOnStream;\n"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(queries); siddhiAppRuntime.addCallback("analyzeStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("fireAlarmEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"id1", 20d}); inputHandler.send(new Object[]{"id2", 20d}); Thread.sleep(2000); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #7
Source File: InMemoryTransportTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(dependsOnMethods = {"inMemorySourceSinkAndEventMappingWithSiddhiQLAndRef"}) public void inMemoryTestCase10() throws InterruptedException, SubscriberUnAvailableException { log.info("Test inMemory 10"); String streams = "" + "@app:name('TestSiddhiApp')" + "@source(type='testTrpInMemory', topic='Foo', prop1='hi', prop2='7.5', " + " @map(type='testTrp', @attributes(symbol='trp:symbol'," + " volume='2',price='trp:price'))) " + "define stream FooStream (symbol string, price double, volume long); " + "define stream BarStream (symbol string, price double, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("BarStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); wso2Count.incrementAndGet(); for (Event event : events) { AssertJUnit.assertArrayEquals(event.getData(), new Object[]{"hi", 7.5, 100L}); } } }); siddhiAppRuntime.start(); InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[]{"WSO2", 5.5, 100L})); InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[]{"IBM", 5.5, 100L})); InMemoryBroker.publish("Foo", new Event(System.currentTimeMillis(), new Object[]{"WSO2", 5.5, 100L})); Thread.sleep(100); //assert event count AssertJUnit.assertEquals("Number of events", 3, wso2Count.get()); siddhiAppRuntime.shutdown(); }
Example #8
Source File: StartStopTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = InterruptedException.class) public void startStopTest1() throws InterruptedException { log.info("startStop test 1"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select 1 as eventFrom " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream2 " + "select 2 as eventFrom " + "insert into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream2"); siddhiAppRuntime.start(); siddhiAppRuntime.shutdown(); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 55.6f, 100}); siddhiAppRuntime.shutdown(); }
Example #9
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPartitionQuery32() throws InterruptedException { log.info("Partition test31"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest31') " + "define stream cseEventStream (atr1 string, atr2 float, atr3 int, atr4 double, " + "atr5 long, atr6 long, atr7 double, atr8 float , atr9 bool, atr10 bool, atr11 int);" + "partition with (atr1 of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>atr5 OR atr8< atr3 OR atr6 < atr2 OR atr4 " + "< atr6 OR atr2 < atr7 OR atr3 < atr4 OR atr4 < atr3 OR atr6 < atr3 OR atr3" + "< atr2 OR atr8 < atr5 OR atr6 < atr4 OR atr3 < atr6 OR atr7 < atr8 OR atr7 " + "< atr4 OR atr6 < atr5 OR atr11 < atr3 OR atr8 < atr2] select" + " atr1 as symbol, sum(atr2) as price" + " insert into " + "OutStockStream ; end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100, 101.0, 500L, 200L, 102.0, 75.7f, false, true, 105}); inputHandler.send(new Object[]{"WSO2", 75.6f, 100, 101.0, 501L, 201L, 103.0, 76.7f, false, true, 106}); inputHandler.send(new Object[]{"IBM", 75.6f, 100, 102.0, 502L, 202L, 104.0, 77.7f, false, true, 107}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100, 101.0, 502L, 202L, 104.0, 77.7f, false, true, 108}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example #10
Source File: SiddhiPolicyTest.java From eagle with Apache License 2.0 | 5 votes |
@Ignore @Test public void testPolicy_seq() throws Exception { String sql = "" + " from every e1=syslog_stream[regex:find(\"UPDOWN\", op)] -> " + " e2=syslog_stream[dims_hostname == e1.dims_hostname and regex:find(\"Abort\", op)] within 1 min " + " select e1.timestamp as timestamp, e1.op as a_op, e2.op as b_op " + " insert into syslog_severity_check_output; "; AtomicBoolean checked = new AtomicBoolean(); StreamCallback sc = new StreamCallback() { @Override public void receive(Event[] arg0) { checked.set(true); } ; }; String executionPlan = streams + sql; SiddhiAppRuntime runtime = sm.createSiddhiAppRuntime(executionPlan); runtime.addCallback("syslog_severity_check_output", sc); runtime.start(); InputHandler handler = runtime.getInputHandler("syslog_stream"); sendPatternInput(handler); Thread.sleep(1000); Assert.assertTrue(checked.get()); runtime.shutdown(); }
Example #11
Source File: StringSubtractFunctionExtensionTest.java From eagle with Apache License 2.0 | 5 votes |
@Test public void testStringSubtract() throws Exception { Semaphore semp = new Semaphore(1); String ql = " define stream log(timestamp long, switchLabel string, port string, message string); " + " from log select str:subtract(switchLabel, message) as alertKey insert into output; "; SiddhiManager manager = new SiddhiManager(); SiddhiAppRuntime runtime = manager.createSiddhiAppRuntime(ql); runtime.addCallback("output", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); Assert.assertTrue(events.length == 1); Assert.assertTrue(events[0].getData(0).toString().equals("a\nc\ne")); semp.release(); } }); runtime.start(); InputHandler logInput = runtime.getInputHandler("log"); semp.acquire(); Event e = new Event(); e.setTimestamp(System.currentTimeMillis()); String ths = "[\"a\", \"b\", \"c\", \"d\", \"e\"]"; String rhs = "[\"b\", \"d\"]"; e.setData(new Object[] {System.currentTimeMillis(), ths, "port01", rhs}); logInput.send(e); semp.acquire(); runtime.shutdown(); }
Example #12
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery9() throws InterruptedException { log.info("Partition test9"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest9') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStream1 (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream)" + "begin" + "@info(name = 'query') from cseEventStream select symbol,min(price) as min_price,volume insert into" + " OutStockStream ;" + "end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(75.0f, event.getData()[1]); } else if (count.get() == 2) { AssertJUnit.assertEquals(705.0f, event.getData()[1]); } else if (count.get() == 3) { AssertJUnit.assertEquals(35.0f, event.getData()[1]); } else if (count.get() == 4) { AssertJUnit.assertEquals(50.0f, event.getData()[1]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75f, 100}); inputHandler.send(new Object[]{"WSO2", 705f, 100}); inputHandler.send(new Object[]{"IBM", 35f, 100}); inputHandler.send(new Object[]{"ORACLE", 50.0f, 100}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example #13
Source File: TestDebugger.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testDebugger10() throws InterruptedException { log.info("Siddi Debugger Test 10: Test next traversal in a query with two consequent streams"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "@config(async = 'true') " + "define stream cseEventStream (symbol string, price float, volume int); " + "define stream stockEventStream (symbol string, price float, volume int); "; final String query = "@info(name = 'query1')" + "from cseEventStream " + "select symbol, price, volume " + "insert into stockEventStream; " + "@info(name = 'query2')" + "from stockEventStream " + "select * " + "insert into OutputStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() { @Override public void receive(Event[] events) { inEventCount.addAndGet(events.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); SiddhiDebugger siddhiDebugger = siddhiAppRuntime.debug(); siddhiDebugger.acquireBreakPoint("query1", SiddhiDebugger.QueryTerminal.IN); siddhiDebugger.setDebuggerCallback(new SiddhiDebuggerCallback() { @Override public void debugEvent(ComplexEvent event, String queryName, SiddhiDebugger.QueryTerminal queryTerminal, SiddhiDebugger debugger) { log.info("Query: " + queryName + ":" + queryTerminal); log.info(event); int count = debugEventCount.addAndGet(getCount(event)); if ((count - 1) / 4 == 0) { // First four events AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[]{"WSO2", 50f, 60}, event .getOutputData()); } else { // Next four events AssertJUnit.assertArrayEquals("Incorrect debug event received", new Object[]{"WSO2", 70f, 40}, event .getOutputData()); } if (count == 1 || count == 5) { AssertJUnit.assertEquals("Incorrect break point", "query1IN", queryName + queryTerminal); } else if (count == 2 || count == 6) { AssertJUnit.assertEquals("Incorrect break point", "query1OUT", queryName + queryTerminal); } else if (count == 3 || count == 7) { AssertJUnit.assertEquals("Incorrect break point", "query2IN", queryName + queryTerminal); } else { AssertJUnit.assertEquals("Incorrect break point", "query2OUT", queryName + queryTerminal); } debugger.next(); } }); inputHandler.send(new Object[]{"WSO2", 50f, 60}); inputHandler.send(new Object[]{"WSO2", 70f, 40}); Thread.sleep(100); AssertJUnit.assertEquals("Invalid number of output events", 2, inEventCount.get()); AssertJUnit.assertEquals("Invalid number of debug events", 8, debugEventCount.get()); siddhiAppRuntime.shutdown(); }
Example #14
Source File: TimeOutputRateLimitTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testTimeOutputRateLimitQuery13") public void testTimeOutputRateLimitQuery14() throws InterruptedException { log.info("TimeOutputRateLimit test14"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "@app:name('EventOutputRateLimitTest5') " + "" + "define stream LoginEvents (timestamp long, ip string, symbol string);" + "@info(name = 'query1') " + "partition with (symbol of LoginEvents) " + "begin " + "from LoginEvents " + "select ip " + "group by symbol " + "output last every 1 sec " + "insert into uniqueIps; " + "end;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); log.info("Running : " + siddhiAppRuntime.getName()); siddhiAppRuntime.addCallback("uniqueIps", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); AssertJUnit.assertTrue("192.10.1.3".equals(events[0].getData(0)) || "192.10.1.4".equals(events[0].getData(0)) || "192.10.1.30".equals(events[0].getData(0))); eventArrived.set(true); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5", "WSO2"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3", "WSO2"}); Thread.sleep(1100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.9", "WSO2"}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.4", "WSO2"}); Thread.sleep(1100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.30", "WSO2"}); Thread.sleep(1100); AssertJUnit.assertEquals("Event arrived", true, eventArrived.get()); AssertJUnit.assertTrue("Number of output event value", 3 == count.get()); siddhiAppRuntime.shutdown(); }
Example #15
Source File: SnapshotOutputRateLimitTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"testSnapshotOutputRateLimitQuery6"}) public void testSnapshotOutputRateLimitQuery7() throws InterruptedException { log.info("SnapshotOutputRateLimit test7"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest7') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select sum(calls) as totalCalls " + "group by ip " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); log.info("Running : " + siddhiAppRuntime.getName()); siddhiAppRuntime.addCallback("uniqueIps", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; count.incrementAndGet(); value += events.length; if (count.get() == 1 || count.get() == 2) { AssertJUnit.assertTrue((Long) events[0].getData(0) == 3L || (Long) events[1].getData(0) == 6L); } else if (count.get() == 3) { AssertJUnit.assertTrue((Long) events[0].getData(0) == 5L || (Long) events[1].getData(0) == 16L); } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents"); siddhiAppRuntime.start(); Thread.sleep(1100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5", 3}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3", 6}); Thread.sleep(2300); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5", 2}); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3", 10}); Thread.sleep(7200); AssertJUnit.assertEquals("Event arrived", true, eventArrived); AssertJUnit.assertEquals("Number of output event bundles", 7, count.get()); AssertJUnit.assertTrue("Number of output event value", 14 == value); siddhiAppRuntime.shutdown(); }
Example #16
Source File: WindowPartitionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testWindowPartitionQuery4() throws InterruptedException { log.info("Window Partition test4"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "define stream cseEventStream (symbol string, price float,volume int);" + "partition with (symbol of cseEventStream) begin @info(name = 'query1') from cseEventStream#window" + ".length(2) select symbol,sum(price) as price,volume insert into OutStockStream ; end "; SiddhiAppRuntime executionRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); executionRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { if (event.isExpired()) { removeEventCount++; } else { inEventCount++; if (inEventCount == 1) { AssertJUnit.assertEquals(70.0, event.getData()[1]); } else if (inEventCount == 2) { AssertJUnit.assertEquals(700.0, event.getData()[1]); } else if (inEventCount == 3) { AssertJUnit.assertEquals(170.0, event.getData()[1]); } else if (inEventCount == 4) { AssertJUnit.assertEquals(300.0, event.getData()[1]); } else if (inEventCount == 5) { AssertJUnit.assertEquals(75.5999984741211, event.getData()[1]); } else if (inEventCount == 6) { AssertJUnit.assertEquals(1700.0, event.getData()[1]); } else if (inEventCount == 7) { AssertJUnit.assertEquals(1500.0, event.getData()[1]); } } eventArrived = true; } } }); InputHandler inputHandler = executionRuntime.getInputHandler("cseEventStream"); executionRuntime.start(); inputHandler.send(new Object[]{"IBM", 70f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 700f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"IBM", 100f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"IBM", 200f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 1000f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"WSO2", 500f, 100}); Thread.sleep(1000); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertTrue(7 >= inEventCount); AssertJUnit.assertEquals(0, removeEventCount); executionRuntime.shutdown(); }
Example #17
Source File: SessionWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(description = "Check whether joins are working with session window") public void testSessionWindow19() throws InterruptedException { log.info("SessionWindow Test19: testing joins"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "define stream purchaseEventStream (user string, item_number int, price float, quantity int); " + "define stream twitterStream (user string, tweet string); "; String query = "" + "@info(name = 'query0') " + "from purchaseEventStream#window.session(1 sec, user) " + "join twitterStream#window.length(2) " + "on purchaseEventStream.user == twitterStream.user " + "select purchaseEventStream.user, twitterStream.tweet, " + "purchaseEventStream.price, purchaseEventStream.quantity " + "insert all events into outputStream; "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); if (events != null) { count.addAndGet(events.length); } AssertJUnit.assertTrue(events[0].toString().contains("user0, Hello Tweet 1, 34.4, 5") || events[0].toString().contains("user1, Hello Tweet 2, 24.5, 12") || events[0].toString().contains("user1, Hello Tweet 2, 44.5, 12")); eventArrived = true; innerAssertionsPassed = true; } }); InputHandler purchaseEventStreamHandler = siddhiAppRuntime.getInputHandler("purchaseEventStream"); InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream"); siddhiAppRuntime.start(); purchaseEventStreamHandler.send(new Object[]{"user0", 101, 34.4, 5}); purchaseEventStreamHandler.send(new Object[]{"user1", 102, 24.5, 12}); purchaseEventStreamHandler.send(new Object[]{"user1", 102, 44.5, 12}); twitterStreamHandler.send(new Object[]{"user0", "Hello Tweet 1"}); twitterStreamHandler.send(new Object[]{"user1", "Hello Tweet 2"}); SiddhiTestHelper.waitForEvents(100, 10, count, 4200); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertTrue(innerAssertionsPassed); siddhiAppRuntime.shutdown(); }
Example #18
Source File: KafkaSourceTestCase.java From siddhi-io-kafka with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testKafkaMultipleTopic_MultiplePartition_OnePartitionSubscribe_Source") public void testKafkaMultipleTopic_MultiplePartition_AllPartitionSubscribe_Source() throws InterruptedException { try { log.info("-------------------------------------------------------------------------------------------"); log.info("Creating test to configure Kafka source with multiple topics having multiple partitions " + "subscribing for all partition ids"); log.info("-------------------------------------------------------------------------------------------"); String topics[] = new String[]{"multiple_topic1_two_par_all_sub", "multiple_topic2_two_par_all_sub"}; receivedEventNameList = new ArrayList<>(4); receivedValueList = new ArrayList<>(4); KafkaTestUtil.createTopic(topics, 2); Thread.sleep(1000); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( "@App:name('TestExecutionPlan') " + "define stream BarStream (symbol string, price float, volume long); " + "@info(name = 'query1') " + "@source(type='kafka', " + "topic.list='multiple_topic1_two_par_all_sub,multiple_topic2_two_par_all_sub', " + "partition.no.list='0,1', " + "group.id='test_multiple_topic1_two_par_all_sub', " + "threading.option='single.thread', " + "bootstrap.servers='localhost:9092'," + "@map(type='xml'))" + "Define stream FooStream (symbol string, price float, volume long);" + "from FooStream select symbol, price, volume insert into BarStream;"); siddhiAppRuntime.addCallback("BarStream", new StreamCallback() { @Override public void receive(Event[] events) { for (Event event : events) { log.info(event); eventArrived = true; count++; receivedEventNameList.add(event.getData(0).toString()); receivedValueList.add((long) event.getData(2)); } } }); siddhiAppRuntime.start(); KafkaTestUtil.kafkaPublisher(topics, 2, 2, false, null, true); Thread.sleep(100); List<String> expectedNames = new ArrayList<>(2); expectedNames.add("multiple_topic1_two_par_all_sub"); expectedNames.add("multiple_topic1_two_par_all_sub"); expectedNames.add("multiple_topic2_two_par_all_sub"); expectedNames.add("multiple_topic2_two_par_all_sub"); List<Long> expectedValues = new ArrayList<>(2); expectedValues.add(0L); expectedValues.add(1L); expectedValues.add(0L); expectedValues.add(1L); AssertJUnit.assertEquals("Kafka Source expected input not received", expectedNames, receivedEventNameList); AssertJUnit.assertEquals("Kafka Source expected input not received", expectedValues, receivedValueList); AssertJUnit.assertEquals(4, count); KafkaTestUtil.deleteTopic(topics); siddhiAppRuntime.shutdown(); } catch (ZkTimeoutException ex) { log.warn("No zookeeper may not be available.", ex); } }
Example #19
Source File: DelayWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void delayWindowTest8() { log.info("DelayWindow Test8 : Testing delay window for dinamic value"); SiddhiManager siddhiManager = new SiddhiManager(); String eventStream = "" + "define stream CargoStream (weight int); " + "define stream OutputStream(weight int, totalWeight long, averageWeight double); "; String query = "" + "@info(name='CargoWeightQuery') " + "from CargoStream#window.delay(1/2) " + "select weight, sum(weight) as totalWeight, avg(weight) as averageWeight " + "insert into OutputStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(eventStream + query); siddhiAppRuntime.addCallback("CargoWeightQuery", 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; } }); StreamCallback callBack = new StreamCallback() { @Override public void receive(Event[] events) { for (Event event : events) { lastValue = (Long) event.getData(1); averageValue = (Double) event.getData(2); } } }; siddhiAppRuntime.addCallback("OutputStream", callBack); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("CargoStream"); siddhiAppRuntime.start(); try { inputHandler.send(new Object[]{1000}); inputHandler.send(new Object[]{1500}); SiddhiTestHelper.waitForEvents(100, 2, count, 3000); AssertJUnit.assertEquals(2, inEventCount); AssertJUnit.assertEquals(0, removeEventCount); AssertJUnit.assertEquals(Long.valueOf(2500), lastValue); AssertJUnit.assertEquals(Double.valueOf(1250), averageValue); } catch (Exception e) { log.error(e.getMessage()); } finally { siddhiAppRuntime.shutdown(); } }
Example #20
Source File: CronWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void cronWindowTest1() throws InterruptedException { log.info("Testing cron window for current events"); SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"; String query = "@info(name = 'query1') " + "from cseEventStream#window.cron('*/5 * * * * ?') " + "select symbol,price,volume " + "insert into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { if (event.isExpired()) { removeEventCount++; } else { inEventCount++; } } 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(7000); inputHandler.send(new Object[]{"IBM1", 700f, 0}); inputHandler.send(new Object[]{"WSO22", 60.5f, 1}); Thread.sleep(7000); inputHandler.send(new Object[]{"IBM43", 700f, 0}); inputHandler.send(new Object[]{"WSO4343", 60.5f, 1}); Thread.sleep(7000); AssertJUnit.assertEquals(6, inEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #21
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery1() throws InterruptedException { log.info("Partition test1"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "@app:name('PartitionTest1') " + "define stream cseEventStream (symbol string, price float,volume int);" + "define stream cseEventStreamOne (symbol string, price float,volume int);" + "@info(name = 'query')from cseEventStreamOne select symbol,price,volume insert into cseEventStream;" + "partition with (symbol of cseEventStream) begin @info(name = 'query1') from " + "cseEventStream[700>price] select symbol,sum(price) as price,volume insert into OutStockStream ; end "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); eventArrived = true; if (count.get() == 1) { AssertJUnit.assertEquals(75.5999984741211, event.getData()[1]); } else if (count.get() == 2) { AssertJUnit.assertEquals(151.1999969482422, event.getData()[1]); } else if (count.get() == 3) { AssertJUnit.assertEquals(75.5999984741211, event.getData()[1]); } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStreamOne"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"WSO2", 70005.6f, 100}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100}); SiddhiTestHelper.waitForEvents(100, 3, count, 60000); AssertJUnit.assertEquals(3, count.get()); siddhiAppRuntime.shutdown(); }
Example #22
Source File: LengthBatchWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void lengthBatchWindowTest10() throws InterruptedException { log.info("LengthBatchWindow Test10"); final int length = 4; SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream#window.lengthBatch(" + length + ", true) " + "select symbol,price,volume " + "insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; if (events.length == 1) { inEventCount++; } else if (events.length == 5) { removeEventCount++; } else { AssertJUnit.assertFalse("Event batch with unexpected number of events " + events.length, false); } for (Event event : events) { count++; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 1}); inputHandler.send(new Object[]{"WSO2", 60.5f, 2}); inputHandler.send(new Object[]{"IBM", 700f, 3}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); AssertJUnit.assertEquals("Total events", 17, count); AssertJUnit.assertEquals("single batch", 7, inEventCount); AssertJUnit.assertEquals("5 event batch", 2, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #23
Source File: CountPatternTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testQuery16() throws InterruptedException { log.info("testQuery16"); SiddhiManager siddhiManager = new SiddhiManager(); String streams = "" + "@app:playback\n " + "define stream Stream1 (id string, symbol string, price float, volume int); "; String query = "" + " @info(name = 'query1') " + " from every e1=Stream1[symbol=='WSO2'] " + " -> e2=Stream1[symbol=='WSO2']<2:> -> e3=Stream1[symbol=='GOOG'] " + " within 10 milliseconds " + " select e1.price as price1, e2.price as price2, e3.price as price3 " + " insert into OutputStream;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); siddhiAppRuntime.addCallback("OutputStream", new StreamCallback() { @Override public void receive(Event[] inEvents) { EventPrinter.print(inEvents); eventArrived = true; inEventCount += inEvents.length; } }); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); siddhiAppRuntime.start(); long startTime = System.currentTimeMillis(); long now = 1; for (int i = 1; i < 401; i++) { stream1.send(++now, new Object[]{ ++now, "WSO2", 25.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "WSO2", 23.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "WSO2", 23.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "WSO2", 23.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "WSO2", 23.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "GOOG", 27.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "GOOG", 28.6f, 100 }); stream1.send(++now, new Object[]{ ++now, "GOOG", 28.6f, 100 }); now += 100; } long endTime = System.currentTimeMillis(); long timeElapsed = endTime - startTime; AssertJUnit.assertEquals("Event arrived", true, eventArrived); AssertJUnit.assertEquals("Event count", 400 * 3, inEventCount); AssertJUnit.assertTrue("Event processing time", timeElapsed < 1000); siddhiAppRuntime.shutdown(); }
Example #24
Source File: KafkaSourceTestCase.java From siddhi-io-kafka with Apache License 2.0 | 4 votes |
public void testKafkaSingleTopic_MultiplePartition_AllPartitionSubscribe_Source_106() throws InterruptedException { try { log.info("-------------------------------------------------------------------------------------------"); log.info("Creating test to configure Kafka source with multiple topics having multiple partitions " + "subscribing for all partition ids"); log.info("-------------------------------------------------------------------------------------------"); String topics[] = new String[]{"single_topic1_two_par_two_servers"}; KafkaTestUtil.setupKafkaBroker2(); receivedEventNameList = new ArrayList<>(2); receivedValueList = new ArrayList<>(2); Thread.sleep(10000); KafkaTestUtil.createTopic(topics, 2); Thread.sleep(5000); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime( "@App:name('TestExecutionPlan') " + "define stream BarStream (symbol string, price float, volume long); " + "@info(name = 'query1') " + "@source(type='kafka', " + "topic.list='single_topic1_two_par_two_servers', " + "partition.no.list='0,1', " + "group.id='test', " + "threading.option='single.thread', " + "bootstrap.servers='localhost:9092,localhost:9093'," + "@map(type='xml'))" + "Define stream FooStream (symbol string, price float, volume long);" + "from FooStream select symbol, price, volume insert into BarStream;"); siddhiAppRuntime.addCallback("BarStream", new StreamCallback() { @Override public void receive(Event[] events) { for (Event event : events) { log.info(event); eventArrived = true; count++; receivedEventNameList.add(event.getData(0).toString()); receivedValueList.add((long) event.getData(2)); } } }); siddhiAppRuntime.start(); Thread.sleep(2000); KafkaTestUtil.kafkaPublisher(topics, 2, 2, false, "localhost:9093,localhost:9092", true); Thread.sleep(1000); List<String> expectedNames = new ArrayList<>(2); expectedNames.add("single_topic1_two_par_two_servers"); expectedNames.add("single_topic1_two_par_two_servers"); expectedNames.add("single_topic1_two_par_two_servers"); expectedNames.add("single_topic1_two_par_two_servers"); List<Long> expectedValues = new ArrayList<>(2); AssertJUnit.assertEquals("Kafka Source expected input not received", expectedNames, receivedEventNameList); AssertJUnit.assertEquals(2, count); KafkaTestUtil.deleteTopic(topics); Thread.sleep(1000); KafkaTestUtil.stopKafkaBroker2(); siddhiAppRuntime.shutdown(); } catch (ZkTimeoutException ex) { log.warn("No zookeeper may not be available.", ex); } }
Example #25
Source File: SnapshotOutputRateLimitTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = {"testSnapshotOutputRateLimitQuery8"}) public void testSnapshotOutputRateLimitQuery9() throws InterruptedException { log.info("SnapshotOutputRateLimit test9"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "@app:name('SnapshotOutputRateLimitTest9') " + "" + "define stream LoginEvents (timestamp long, ip string, calls int);" + "" + "@info(name = 'query1') " + "from LoginEvents#window.time(5 sec) " + "select sum(calls) as totalCalls " + "output snapshot every 1 sec " + "insert all events into uniqueIps ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); log.info("Running : " + siddhiAppRuntime.getName()); siddhiAppRuntime.addCallback("uniqueIps", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertTrue((Long) events[0].getData(0) == 9L); } else if (count.get() == 2) { AssertJUnit.assertTrue((Long) events[0].getData(0) == 9L); } else if (count.get() == 3) { AssertJUnit.assertTrue((Long) events[0].getData(0) == 21L); } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("LoginEvents"); siddhiAppRuntime.start(); Thread.sleep(1100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5", 3}); Thread.sleep(100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3", 6}); Thread.sleep(2200); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.5", 2}); Thread.sleep(100); inputHandler.send(new Object[]{System.currentTimeMillis(), "192.10.1.3", 10}); SiddhiTestHelper.waitForEvents(1000, 3, count, 60000); AssertJUnit.assertEquals("Event arrived", true, eventArrived); AssertJUnit.assertTrue("Number of output event with value", count.get() == 3); siddhiAppRuntime.shutdown(); Thread.sleep(100); }
Example #26
Source File: JoinPartitionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testJoinPartition9") public void testJoinPartition10() throws InterruptedException { log.info("Join partition test10"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "" + "define stream cseEventStream (symbol string, user string,volume int); " + "define stream twitterStream (user string, tweet string, company string); " + "" + "partition with (user of cseEventStream, user of twitterStream) " + "begin " + " @info(name = 'query1') " + " from cseEventStream#window.length(1) unidirectional join twitterStream#window.length(1) " + " select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume, " + "cseEventStream.user" + " insert all events into outputStream1 ;" + "" + "end;" + "" + "partition with (user of outputStream1) " + "begin " + " @info(name = 'query2') " + " from outputStream1#window.length(1) join twitterStream#window.length(1) " + " select outputStream1.symbol as symbol, twitterStream.tweet, outputStream1.volume " + " insert all events into outputStream ;" + "" + "end;" + " "; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); eventArrived = true; } }); InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream"); siddhiAppRuntime.start(); twitterStreamHandler.send(new Object[]{"User1", "Hello World", "WSO2"}); cseEventStreamHandler.send(new Object[]{"WSO2", "User1", 100}); cseEventStreamHandler.send(new Object[]{"WSO2", "User2", 100}); twitterStreamHandler.send(new Object[]{"User2", "Hello World", "WSO2"}); twitterStreamHandler.send(new Object[]{"User3", "Hello World", "WSO2"}); cseEventStreamHandler.send(new Object[]{"WSO2", "User3", 100}); SiddhiTestHelper.waitForEvents(100, 3, count, 60000); AssertJUnit.assertEquals(3, count.get()); siddhiAppRuntime.shutdown(); }
Example #27
Source File: StartStopTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test() public void startStopTest2() throws InterruptedException { log.info("startStop test 2"); SiddhiManager siddhiManager = new SiddhiManager(); String siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume int);" + "define stream cseEventStream2 (symbol string, price float, volume int);" + "" + "@info(name = 'query1') " + "from cseEventStream " + "select 1 as eventFrom " + "insert into outputStream ;" + "" + "@info(name = 'query2') " + "from cseEventStream2 " + "select 2 as eventFrom " + "insert into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); Assert.assertEquals(events[0].getData(0), 1); eventArrived = true; count.incrementAndGet(); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream2"); inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); siddhiAppRuntime.shutdown(); siddhiAppRuntime.start(); inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); inputHandler.send(new Object[]{"WSO2", 55.6f, 100}); siddhiAppRuntime.shutdown(); AssertJUnit.assertTrue(eventArrived); AssertJUnit.assertEquals(1, count.get()); }
Example #28
Source File: OrAggregatorExtensionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test(dependsOnMethods = "testOrAggregatorTrueFalseScenario") public void testORAggregatorMoreEventsBatchScenario() throws InterruptedException { log.info("AndAggregator TestCase 4"); SiddhiManager siddhiManager = new SiddhiManager(); String inStreamDefinition = "define stream cscStream(messageID string, isFraud bool, price double);"; String query = ("@info(name = 'query1') " + "from cscStream#window.lengthBatch(2) " + "select messageID, or(isFraud) as isValidTransaction " + "group by messageID " + "insert all events into outputStream;"); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; for (Event event : events) { count++; switch (count) { case 1: AssertJUnit.assertEquals(false, event.getData(1)); break; case 2: AssertJUnit.assertEquals(true, event.getData(1)); break; default: AssertJUnit.fail(); } } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cscStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"messageId1", false, 35.75}); inputHandler.send(new Object[]{"messageId1", false, 35.75}); inputHandler.send(new Object[]{"messageId1", true, 35.75}); inputHandler.send(new Object[]{"messageId1", true, 35.75}); Thread.sleep(2000); AssertJUnit.assertEquals(2, count); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #29
Source File: LengthWindowTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testLengthWindow2() throws InterruptedException { log.info("Testing length window with no of events greater than window size"); final int length = 4; SiddhiManager siddhiManager = new SiddhiManager(); String cseEventStream = "define stream cseEventStream (symbol string, price float, volume int); " + "define window cseWindow (symbol string, price float, volume int) length(" + length + ") output all " + "events; "; String query = "@info(name = 'query1') from cseEventStream select symbol,price,volume insert into cseWindow ;" + "@info(name = 'query2') from cseWindow insert all events into outputStream ;"; SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query); siddhiAppRuntime.addCallback("outputStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); eventArrived = true; for (Event event : events) { if (count >= length && count % 2 == 0) { removeEventCount++; AssertJUnit.assertEquals("Remove event order", removeEventCount, event.getData(2)); AssertJUnit.assertEquals("Expired event triggering position", inEventCount + 1, length + removeEventCount); } else { inEventCount++; AssertJUnit.assertEquals("In event order", inEventCount, event.getData(2)); } count++; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 700f, 1}); inputHandler.send(new Object[]{"WSO2", 60.5f, 2}); inputHandler.send(new Object[]{"IBM", 700f, 3}); inputHandler.send(new Object[]{"WSO2", 60.5f, 4}); inputHandler.send(new Object[]{"IBM", 700f, 5}); inputHandler.send(new Object[]{"WSO2", 60.5f, 6}); Thread.sleep(500); AssertJUnit.assertEquals("In event count", 6, inEventCount); AssertJUnit.assertEquals("Remove event count", 2, removeEventCount); AssertJUnit.assertTrue(eventArrived); siddhiAppRuntime.shutdown(); }
Example #30
Source File: PatternPartitionTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPatternPartitionQuery7() throws InterruptedException { log.info("Partition - testPatternEvery7 - 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 partitionStart = "partition with (volume of Stream1,volume of Stream2) begin "; String query = "" + "@info(name = 'query1') " + "from every ( e1=Stream1[price>20] -> e3=Stream1[price>20]) " + "select e1.price as price1, e3.price as price3 " + "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(); switch (inEventCount.get()) { case 1: AssertJUnit.assertArrayEquals(new Object[]{55.6f, 57.6f}, event.getData()); break; case 2: AssertJUnit.assertArrayEquals(new Object[]{54f, 53.6f}, event.getData()); break; default: AssertJUnit.assertSame(2, inEventCount.get()); } } eventArrived = true; } } }); InputHandler stream1 = siddhiAppRuntime.getInputHandler("Stream1"); siddhiAppRuntime.start(); stream1.send(new Object[]{"MSFT", 55.6f, 100}); Thread.sleep(100); stream1.send(new Object[]{"WSO2", 57.6f, 100}); Thread.sleep(100); stream1.send(new Object[]{"GOOG", 54f, 100}); Thread.sleep(100); stream1.send(new Object[]{"WSO2", 53.6f, 100}); SiddhiTestHelper.waitForEvents(100, 2, inEventCount, 60000); AssertJUnit.assertEquals("Number of success events", 2, inEventCount.get()); AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount.get()); AssertJUnit.assertEquals("Event arrived", true, eventArrived); siddhiAppRuntime.shutdown(); }