示例#1
0
    def test_outputstram(self):
        logging.info("OutputStream Test 1: Test reception of events")
        siddhiManager = SiddhiManager()
        cseEventStream = "@config(async = 'true') " \
                         "define stream cseEventStream (symbol string, price float, volume int);"

        query = "@info(name = 'query 1') from cseEventStream select symbol, price, volume insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class StreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream", StreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])

        sleep(1)

        _self_shaddow.assertEqual(2, _self_shaddow.inEventCount.get(),
                                  "Invalid number of output events")

        siddhiAppRuntime.shutdown()
示例#2
0
 def setUp(self):
     # Creating SiddhiManager
     self.siddhiManager = SiddhiManager()
     self.siddhiApp = "" + "define stream cseEventStream (symbol string, price float, volume long); " \
                      + "" + "@info(name = 'query1') " + "from cseEventStream[volume < 150] " \
                      + "select symbol,price " + "insert into outputStream ;"
     # Generating runtime
     # print(self.siddhiApp)
     self.siddhiAppRuntime = self.siddhiManager.createSiddhiAppRuntime(
         self.siddhiApp)
示例#3
0
    def testStringContainsFunction(self):
        logging.info("ContainsFunctionExtensionTestCase TestCase")

        # Creating SiddhiManager
        siddhiManager = SiddhiManager()

        # Creating Query
        streamDefinition = "define stream inputStream (symbol string, price long, volume long);"
        query = "@info(name = 'query1') " + \
                "from inputStream " + \
                "select symbol , str:contains(symbol, 'WSO2') as isContains " + \
                "insert into outputStream;"

        # Setting up Siddhi App
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            streamDefinition + query)

        # Setting up callback
        _self_shaddow = self

        class ConcreteQueryCallback(QueryCallback):
            def receive(self, timestamp, inEvents, outEvents):
                PrintEvent(timestamp, inEvents, outEvents)
                for inEvent in inEvents:
                    _self_shaddow.count.addAndGet(1)
                    if _self_shaddow.count.get() == 1:
                        _self_shaddow.assertEqual(False, inEvent.getData(1))

                    if _self_shaddow.count.get() == 2:
                        _self_shaddow.assertEqual(True, inEvent.getData(1))

                    if _self_shaddow.count.get() == 3:
                        _self_shaddow.assertEqual(True, inEvent.getData(1))

                _self_shaddow.eventArrived = True

        siddhiAppRuntime.addCallback("query1", ConcreteQueryCallback())

        # Retrieving input handler to push events into Siddhi
        inputHandler = siddhiAppRuntime.getInputHandler("inputStream")
        # Starting event processing
        siddhiAppRuntime.start()

        # Sending events to Siddhi
        inputHandler.send(["IBM", 700.0, LongType(100)])
        inputHandler.send(["WSO2", 60.5, LongType(200)])
        inputHandler.send(
            ["One of the best middleware is from WSO2.", 60.5,
             LongType(200)])
        sleep(0.5)

        self.assertEqual(self.count.get(), 3)
        self.assertTrue(self.eventArrived)

        siddhiManager.shutdown()
示例#4
0
    def testMathRandomFunctionWithSeed(self):
        logging.info("RandomFunctionExtension TestCase, with seed")

        # Creating SiddhiManager
        siddhiManager = SiddhiManager()

        # Creating Query
        streamDefinition = "define stream inputStream (symbol string, price long, volume long);"
        query = "@info(name = 'query1') from inputStream select symbol , math:rand(12) as randNumber " + \
                "insert into outputStream;"

        # Setting up Siddhi App
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            streamDefinition + query)

        # Setting up callback
        _self_shaddow = self

        class ConcreteQueryCallback(QueryCallback):
            def receive(self, timestamp, inEvents, outEvents):
                PrintEvent(timestamp, inEvents, outEvents)
                _self_shaddow.count.addAndGet(len(inEvents))
                _self_shaddow.eventArrived = True
                if len(inEvents) == 3:
                    randNumbers = [0, 0, 0]
                    randNumbers[0] = inEvents[0].getData(1)
                    randNumbers[1] = inEvents[1].getData(1)
                    randNumbers[2] = inEvents[2].getData(1)
                    isDuplicatePresent = False

                    logging.info(randNumbers[0] + ", " + randNumbers[1])

                    if randNumbers[0] == randNumbers[1] or randNumbers[0] == randNumbers[2] or randNumbers[1] == \
                            randNumbers[2]:
                        isDuplicatePresent = True

                    _self_shaddow.assertEquals(False, isDuplicatePresent)

        siddhiAppRuntime.addCallback("query1", ConcreteQueryCallback())

        # Retrieving input handler to push events into Siddhi
        inputHandler = siddhiAppRuntime.getInputHandler("inputStream")
        # Starting event processing
        siddhiAppRuntime.start()

        # Sending events to Siddhi
        inputHandler.send(["IBM", 700.0, LongType(100)])
        inputHandler.send(["WSO2", 60.5, LongType(200)])
        inputHandler.send(["XYZ", 60.5, LongType(200)])
        sleep(0.5)

        self.assertEqual(self.count.get(), 3)
        self.assertTrue(self.eventArrived)

        siddhiManager.shutdown()
示例#5
0
    def testStringRegexpFunction(self):
        logging.info("RegexpFunctionExtensionTestCase TestCase")

        # Creating SiddhiManager
        siddhiManager = SiddhiManager()

        # Creating Query
        streamDefinition = "define stream inputStream (symbol string, price long, regex string);"
        query = "@info(name = 'query1') from inputStream select symbol , " + \
                "str:regexp(symbol, regex) as beginsWithWSO2 " + \
                "insert into outputStream"

        # Setting up Siddhi App
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            streamDefinition + query)

        # Setting up callback
        _self_shaddow = self

        class ConcreteQueryCallback(QueryCallback):
            def receive(self, timestamp, inEvents, outEvents):
                PrintEvent(timestamp, inEvents, outEvents)
                for inEvent in inEvents:
                    _self_shaddow.count.addAndGet(1)
                    if _self_shaddow.count.get() == 1:
                        _self_shaddow.assertEqual(False, inEvent.getData(1))

                    if _self_shaddow.count.get() == 2:
                        _self_shaddow.assertEqual(True, inEvent.getData(1))

                    if _self_shaddow.count.get() == 3:
                        _self_shaddow.assertEqual(False, inEvent.getData(1))

                _self_shaddow.eventArrived = True

        siddhiAppRuntime.addCallback("query1", ConcreteQueryCallback())

        # Retrieving input handler to push events into Siddhi
        inputHandler = siddhiAppRuntime.getInputHandler("inputStream")
        # Starting event processing
        siddhiAppRuntime.start()

        # Sending events to Siddhi
        inputHandler.send(["hello hi hello", 700.0, "^WSO2(.*)"])
        inputHandler.send(["WSO2 abcdh", 60.5, "WSO(.*h)"])
        inputHandler.send(["aaWSO2 hi hello", 60.5, "^WSO2(.*)"])
        sleep(0.5)

        self.assertEqual(self.count.get(), 3)
        self.assertTrue(self.eventArrived)

        siddhiManager.shutdown()
示例#6
0
    def test_debugger12(self):
        logging.info(
            "Siddi Debugger Test 12: Test debugging two queries with concurrent input"
        )

        siddhiManager = SiddhiManager()

        cseEventStream = "@config(async = 'true') " + \
                         "define stream cseEventStream (symbol string, price float, volume int); " + \
                         "define stream stockEventStream (symbol string, price float, volume int); "

        query = "@info(name = 'query1')" + \
                "from cseEventStream " + \
                "select * " + \
                "insert into OutputStream1; " + \
                "@info(name = 'query2')" + \
                "from stockEventStream " + \
                "select * " + \
                "insert into OutputStream2;"

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl1(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream1",
                                     OutputStreamCallbackImpl1())

        class OutputStreamCallbackImpl2(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream2",
                                     OutputStreamCallbackImpl2())

        cseEventStreamInputHandler = siddhiAppRuntime.getInputHandler(
            "cseEventStream")
        stockEventStreamInputHandler = siddhiAppRuntime.getInputHandler(
            "stockEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)
        siddhiDebugger.acquireBreakPoint("query2",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def __init__(self):
                SiddhiDebuggerCallback.__init__(self)
                self.queryOneResumed = AtomicInt(0)

            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                if ("query1IN" == queryName):
                    sleep(1)
                    self.queryOneResumed.set(1)

                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received")
                elif "query2IN" == queryName:
                    # If query2IN is reached, query1IN must left that break point
                    _self_shaddow.assertTrue(
                        self.queryOneResumed.get(),
                        "Query 2 thread enterted the checkpoint before query 1 is debugged"
                    )
                    _self_shaddow.assertListEqual(
                        ["IBM", 45.0, 80], event.getOutputData(),
                        "Incorrect debug event received")
                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        def thread1_worker():
            cseEventStreamInputHandler.send(["WSO2", 50.0, 60])

        thread1 = threading.Thread(target=thread1_worker)
        thread1.start()

        def thread2_worker():
            stockEventStreamInputHandler.send(["IBM", 45.0, 80])

        thread2 = threading.Thread(target=thread2_worker)
        thread2.start()

        sleep(2)

        self.assertEquals(2, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(4, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#7
0
    def test_debugger11(self):
        logging.info("Siddi Debugger Test 11: Modify events during debug mode")

        siddhiManager = SiddhiManager()

        cseEventStream = "@config(async = 'true') " + \
                         "define stream cseEventStream (symbol string, price float, volume int); " + \
                         "define stream stockEventStream (symbol string, price float, volume int); "

        query = "@info(name = 'query1')" + \
                "from cseEventStream " + \
                "select symbol, price, volume " + \
                "insert into stockEventStream; " + \
                "@info(name = 'query2')" + \
                "from stockEventStream " + \
                "select * " + \
                "insert into OutputStream;"

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                if (count == 1 or count == 2):
                    # WSO2 in stream 1
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received")
                else:
                    # IBM in stream 2
                    _self_shaddow.assertListEqual(
                        ["IBM", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received")

                if count == 2:
                    # Modify the event at the end of the first stream
                    # TODO Improve the logic to use assignment operator (writeBacks by assignment operator)
                    event.setOutputData("IBM", 0)

                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])

        sleep(0.1)

        self.assertEquals(1, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(4, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#8
0
    def test_debugger10(self):
        logging.info(
            "Siddi Debugger Test 10: Test next traversal in a query with two consequent streams"
        )

        siddhiManager = SiddhiManager()

        cseEventStream = "@config(async = 'true') " + \
                         "define stream cseEventStream (symbol string, price float, volume int); " + \
                         "define stream stockEventStream (symbol string, price float, volume int); "

        query = "@info(name = 'query1')" + \
                "from cseEventStream " + \
                "select symbol, price, volume " + \
                "insert into stockEventStream; " + \
                "@info(name = 'query2')" + \
                "from stockEventStream " + \
                "select * " + \
                "insert into OutputStream;"

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))
                if 1 <= count <= 4:
                    # First four events
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received")
                else:
                    # Next four events
                    _self_shaddow.assertListEqual(
                        ["WSO2", 70.0, 40], event.getOutputData(),
                        "Incorrect debug event received")

                if (count == 1 or count == 5):
                    _self_shaddow.assertEquals("query1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                elif (count == 2 or count == 6):
                    _self_shaddow.assertEquals("query1OUT",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                elif (count == 3 or count == 7):
                    _self_shaddow.assertEquals("query2IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                else:
                    _self_shaddow.assertEquals("query2OUT",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")

                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])

        sleep(0.1)

        self.assertEquals(2, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(8, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#9
0
    def test_debugger9(self):
        logging.info(
            "Siddi Debugger Test 9: Test state traversal in a simple query")

        siddhiManager = SiddhiManager()

        cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, " + \
                         "volume int);"
        query = "@info(name = 'query1')" + \
                "from cseEventStream#window.length(3) " + \
                "select symbol, price, sum(volume) as volume " + \
                "insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                if count == 2:
                    queryState = debugger.getQueryState(queryName)
                    logging.info(queryState)

                    streamEvent = None
                    # Order of the query state items is unpredictable
                    for (k, v) in queryState.items():
                        if k.startswith("AbstractStreamProcessor"):
                            streamEvent = v["ExpiredEventChunk"]
                            break

                    _self_shaddow.assertListEqual(streamEvent.getOutputData(),
                                                  ["WSO2", 50.0, None])

                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])

        sleep(1)

        self.assertEquals(2, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(4, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#10
0
    def test_debugger8(self):
        logging.info(
            "Siddi Debugger Test 8: Test play traversal in a query with time batch window where play call delays" + \
            " 1 sec")

        siddhiManager = SiddhiManager()

        cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"
        query = "@info(name = 'query1')" + \
                "from cseEventStream#window.timeBatch(1 sec) " + \
                "select symbol, price, volume " + \
                "insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                _self_shaddow.assertEquals(
                    1, _self_shaddow.getCount(event),
                    "Only one event can be emitted from the window")

                if count != 1 and "query1IN" == queryName:
                    sleep(1)

                debugger.play()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])
        inputHandler.send(["WSO2", 60.0, 50])

        sleep(1.5)

        self.assertEquals(3, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(3, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#11
0
    def test_debugger7(self):
        logging.info(
            "Siddi Debugger Test 7: Test play traversal in a query with time batch window"
        )

        siddhiManager = SiddhiManager()

        cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"
        query = "@info(name = 'query1')" + \
                "from cseEventStream#window.timeBatch(3 sec) " + \
                "select symbol, price, volume " + \
                "insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        current_milli_time = lambda: int(round(time.time() * 1000))

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + "\t" +
                             str(current_milli_time()))
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                if count == 1:
                    _self_shaddow.assertEquals("query1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received at IN")
                elif count == 2:
                    _self_shaddow.assertEquals("query1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 70.0, 40], event.getOutputData(),
                        "Incorrect debug event received at IN")
                elif count == 3:
                    _self_shaddow.assertEquals("query1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 60.0, 50], event.getOutputData(),
                        "Incorrect debug event received at IN")

                debugger.play()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])
        inputHandler.send(["WSO2", 60.0, 50])

        sleep(3.5)

        self.assertEquals(3, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(3, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#12
0
    def test_Debugger1(self):
        logging.info(
            "Siddi Debugger Test 1: Test next traversal in a simple query")

        siddhiManager = SiddhiManager()
        cseEventStream = "@config(async = 'true') " \
                         "define stream cseEventStream (symbol string, price float, volume int);"

        query = "@info(name = 'query 1') from cseEventStream select symbol, price, volume insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class StreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     StreamCallbackImpl())  # Causes GC Error

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()
        siddhiDebugger.acquireBreakPoint("query 1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))
                if count == 1:
                    _self_shaddow.assertEquals("query 1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received at IN")

                elif count == 2:
                    _self_shaddow.assertEqual("query 1OUT",
                                              queryName + queryTerminal.name,
                                              "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received at OUT")

                elif count == 3:
                    _self_shaddow.assertEqual("query 1IN",
                                              queryName + queryTerminal.name,
                                              "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 70.0, 40], event.getOutputData(),
                        "Incorrect debug event received at IN")
                elif count == 4:
                    _self_shaddow.assertEquals("query 1OUT",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 70.0, 40], event.getOutputData(),
                        "Incorrect debug event received at OUT")

                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])

        sleep(0.1)

        self.assertEquals(2, _self_shaddow.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(4, _self_shaddow.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#13
0
    def test_debugger4(self):
        logging.info(
            "Siddi Debugger Test 4: Test next traversal in a query with time batch window where next call delays 1 sec"
        )

        siddhiManager = SiddhiManager()

        cseEventStream = "define stream cseEventStream (symbol string, price float, volume int);"
        query = "@info(name = 'query1')" + \
                "from cseEventStream#window.timeBatch(1 sec) " + \
                "select symbol, price, volume " + \
                "insert into OutputStream;"

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class OutputStreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))
                _self_shaddow.assertEquals(
                    1, len(events), "Cannot emit all three in one time")

        siddhiAppRuntime.addCallback("OutputStream",
                                     OutputStreamCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        siddhiDebugger.acquireBreakPoint("query1",
                                         SiddhiDebugger.QueryTerminal.IN)

        class SiddhiDebuggerCallbackImpl(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))

                if count != 1 and queryTerminal.name == SiddhiDebugger.QueryTerminal.IN.name:
                    sleep(1.1)

                # next call will not reach OUT since there is a window
                debugger.next()

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl())

        inputHandler.send(["WSO2", 50.0, 60])
        inputHandler.send(["WSO2", 70.0, 40])
        inputHandler.send(["WSO2", 60.0, 50])

        sleep(1.5)

        self.assertEquals(3, self.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(3, self.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#14
0
    def test_set_debugger_callback(self):
        logging.info("Siddi Debugger Wrapper Test 1: Set Debugger Callback")

        siddhiManager = SiddhiManager()
        cseEventStream = "@config(async = 'true') define stream cseEventStream (symbol string, price float, volume int);"

        query = "@info(name = 'query 1') from cseEventStream select symbol, price, volume insert into OutputStream; "

        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
            cseEventStream + query)

        _self_shaddow = self

        class StreamCallbackImpl(StreamCallback):
            def receive(self, events):
                _self_shaddow.inEventCount.addAndGet(len(events))

        siddhiAppRuntime.addCallback("OutputStream",
                                     StreamCallbackImpl())  # Causes GC Error

        inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream")

        siddhiDebugger = siddhiAppRuntime.debug()

        # Callback1
        class SiddhiDebuggerCallbackImpl1(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))
                if count == 1:
                    _self_shaddow.assertEquals("query 1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 50.0, 60], event.getOutputData(),
                        "Incorrect debug event received at IN")
                else:
                    # No more events should be received
                    _self_shaddow.fail("The callback has not been released")

                debugger.play()

        # Callback2
        class SiddhiDebuggerCallbackImpl2(SiddhiDebuggerCallback):
            def debugEvent(self, event, queryName, queryTerminal, debugger):
                logging.info("Query: " + queryName + ":" + queryTerminal.name)
                logging.info(event)

                count = _self_shaddow.debugEventCount.addAndGet(
                    _self_shaddow.getCount(event))
                if count == 2:
                    _self_shaddow.assertEquals("query 1IN",
                                               queryName + queryTerminal.name,
                                               "Incorrect break point")
                    _self_shaddow.assertListEqual(
                        ["WSO2", 70.0, 40], event.getOutputData(),
                        "Incorrect debug event received at IN")
                else:
                    # No more events should be received
                    _self_shaddow.fail("Invalid event count")

                debugger.play()

        siddhiDebugger.acquireBreakPoint("query 1",
                                         SiddhiDebugger.QueryTerminal.IN)

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl1())

        inputHandler.send(["WSO2", 50.0, 60])

        siddhiDebugger.setDebuggerCallback(SiddhiDebuggerCallbackImpl2())

        inputHandler.send(["WSO2", 70.0, 40])

        self.assertEquals(2, _self_shaddow.inEventCount.get(),
                          "Invalid number of output events")
        self.assertEquals(2, _self_shaddow.debugEventCount.get(),
                          "Invalid number of debug events")

        siddhiAppRuntime.shutdown()
        siddhiManager.shutdown()
示例#15
0
    def testTimeSeriesSimpleLinearRegression(self):
        logging.info("Simple Regression TestCase")

        siddhiManager = SiddhiManager()

        siddhiManager.setExtension(
            "timeseries:regress",
            "org.wso2.extension.siddhi.execution.timeseries.LinearRegressionStreamProcessor"
        )

        inputStream = "define stream InputStream (y int, x int);"
        siddhiApp = "@info(name = 'query1') from InputStream#timeseries:regress(1, 100, 0.95, y, x) " + \
                    "select * " + \
                    "insert into OutputStream;"
        siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inputStream +
                                                                siddhiApp)
        self.betaZero = 0
        _self_shaddow = self

        class QueryCallbackImpl(QueryCallback):
            def receive(self, timestamp, inEvents, outEvents):
                PrintEvent(timestamp, inEvents, outEvents)
                _self_shaddow.count.addAndGet(len(inEvents))
                _self_shaddow.betaZero = inEvents[len(inEvents) - 1].getData(3)

        siddhiAppRuntime.addCallback("query1", QueryCallbackImpl())

        inputHandler = siddhiAppRuntime.getInputHandler("InputStream")
        siddhiAppRuntime.start()

        inputHandler.send([2500.00, 17.00])
        inputHandler.send([2600.00, 18.00])
        inputHandler.send([3300.00, 31.00])
        inputHandler.send([2475.00, 12.00])
        inputHandler.send([2313.00, 8.00])
        inputHandler.send([2175.00, 26.00])
        inputHandler.send([600.00, 14.00])
        inputHandler.send([460.00, 3.00])
        inputHandler.send([240.00, 1.00])
        inputHandler.send([200.00, 10.00])
        inputHandler.send([177.00, 0.00])
        inputHandler.send([140.00, 6.00])
        inputHandler.send([117.00, 1.00])
        inputHandler.send([115.00, 0.00])
        inputHandler.send([2600.00, 19.00])
        inputHandler.send([1907.00, 13.00])
        inputHandler.send([1190.00, 3.00])
        inputHandler.send([990.00, 16.00])
        inputHandler.send([925.00, 6.00])
        inputHandler.send([365.00, 0.00])
        inputHandler.send([302.00, 10.00])
        inputHandler.send([300.00, 6.00])
        inputHandler.send([129.00, 2.00])
        inputHandler.send([111.00, 1.00])
        inputHandler.send([6100.00, 18.00])
        inputHandler.send([4125.00, 19.00])
        inputHandler.send([3213.00, 1.00])
        inputHandler.send([2319.00, 38.00])
        inputHandler.send([2000.00, 10.00])
        inputHandler.send([1600.00, 0.00])
        inputHandler.send([1394.00, 4.00])
        inputHandler.send([935.00, 4.00])
        inputHandler.send([850.00, 0.00])
        inputHandler.send([775.00, 5.00])
        inputHandler.send([760.00, 6.00])
        inputHandler.send([629.00, 1.00])
        inputHandler.send([275.00, 6.00])
        inputHandler.send([120.00, 0.00])
        inputHandler.send([2567.00, 12.00])
        inputHandler.send([2500.00, 28.00])
        inputHandler.send([2350.00, 21.00])
        inputHandler.send([2317.00, 3.00])
        inputHandler.send([2000.00, 12.00])
        inputHandler.send([715.00, 1.00])
        inputHandler.send([660.00, 9.00])
        inputHandler.send([650.00, 0.00])
        inputHandler.send([260.00, 0.00])
        inputHandler.send([250.00, 1.00])
        inputHandler.send([200.00, 13.00])
        inputHandler.send([180.00, 6.00])

        sleep(1)

        self.assertEqual(50, self.count.get(), "No of events: ")
        self.assertTrue(
            573.1418421169493 - 0.001 < self.betaZero <
            573.1418421169493 + 0.001,
            "Beta0: " + str(573.1418421169493 - self.betaZero))

        siddhiAppRuntime.shutdown()