def test_send_with_handler(self):
     latch = CountDownLatch()
     ebus = EventBus()
     ebus.connect()
     
     def handler(message):
         self.assertEqual(message['body']['hello'], 'world')
         latch.count_down()
     ebus.send("echo", body={'hello': 'world'}, reply_handler=handler)
     latch.awaits(5)
     ebus.close()
 def test_send(self):
     latch = CountDownLatch()
     ebus = EventBus()
     ebus.connect()
     
     def handler(message):
         self.assertEqual(message['body']['hello'], 'world')
         ebus.close()
         latch.count_down()
     ebus.register_handler("echo-back", handler)
     ebus.send("echo", reply_address="echo-back", body={'hello': 'world'})
     latch.awaits(5)
 def test_publish(self):
     latch = CountDownLatch()
     ebus = EventBus()
     ebus.connect()
     
     def handler(message):
         print("got publish messages back")
         self.assertEqual(message['body']['hello'], 'world')
         self.assertEqual(message['headers']['name'], 'vertx-python')
         ebus.close()
         latch.count_down()
     ebus.register_handler("publish-back", handler)
     ebus.publish("publish-back", headers={'name': 'vertx-python'}, body={'hello': 'world'})
     latch.awaits(5)
 def test_re_connect_with_registered_handlers(self):
     latch = CountDownLatch()
     
     def local_handler(message):
         self.assertEqual(message['type'], 'message')
         self.assertEqual(message['body']['name'], 'python')
         ebus.close()
         latch.count_down()
     ebus = EventBus()
     # register local before getting connect
     ebus._register_local("local-handler", local_handler)
     ebus.connect()
     ebus.send('local-handler', body={'name': 'python'})
     latch.awaits(5)
    def test_tls_client_auth_on(self):
        """
        Tests when tls.CLIENT_AUTH is enabled.
        """
        latch = CountDownLatch()
        starter = EventBusBridgeStarter(
            debug=True,
            conf={
                "server-options": {
                    "ssl": "true",
                    "clientAuth": "REQUIRED",
                    "pemKeyCertOptions": {
                        "keyPath": "test/systemtesting/ca.key",
                        "certPath": "test/systemtesting/ca.crt"
                    },
                    "pemTrustOptions": {
                        "certPaths": ["test/systemtesting/ca.crt"]
                    }
                }
            })
        try:
            starter.start()
            starter.wait_started()

            ebus = EventBus(
                options={
                    "debug": "True",
                    "ssl_options": {
                        "ca_file": "test/systemtesting/ca.crt",
                        "cert_file": "test/systemtesting/ca.crt",
                        "key_file": "test/systemtesting/ca.key"
                    }
                })
            ebus.connect()

            def handler(message):
                self.assertEqual(message['body']['hello'], 'world')
                ebus.close()
                print("Passed!")
                latch.count_down()

            ebus.register_handler("echo-back", handler)
            ebus.send("echo",
                      reply_address="echo-back",
                      body={'hello': 'world'})
            latch.awaits(10)
        finally:
            starter.stop()
예제 #6
0
    def test_reconnect_server_restart(self):
        """
        Tests that server paused for 5 seconds, and restarts after that.
        All local handlers should be registered again after server restarted.
        """
        latch = CountDownLatch(2)
        ebus = EventBus(options={
            "auto_connect": "True",
            "max_reconnect": "5",
            "debug": "True"
        })
        starter = EventBusBridgeStarter(debug=True)

        def handler(message):
            self.assertEqual(message['body']['hello'], 'world')
            latch.count_down()

        try:
            starter.start()
            starter.wait_started()
            ebus.connect()
            ebus.register_handler("echo-back", handler)
            ebus.send("echo",
                      reply_address="echo-back",
                      body={'hello': 'world'})
            latch.awaits(5, to_count=1)
        finally:
            print("Now stop the server")
            starter.stop()

        print("Now wait for 5 seconds")
        time.sleep(5)
        try:
            print("Now start the server again.")
            starter.start()
            starter.wait_started()
            print(
                "ebus should get connected automatically and the handler gets registered again."
            )
            ebus.send("echo",
                      reply_address="echo-back",
                      body={'hello': 'world'})
            latch.awaits(10)
        finally:
            print("close the client now...")
            ebus.close()
            starter.stop()
예제 #7
0
    def test_reconnect_before_server_start(self):
        """
        Tests that server starts 5 seconds after client tries to connect to it.
        """
        latch = CountDownLatch()
        ebus = EventBus(options={"auto_connect": "True", "max_reconnect": "5"})
        starter = EventBusBridgeStarter(debug=False)
        # server will start after 5 seconds in background thread
        starter.start_async(delay=5)
        # this will block for 5 seconds to connect until server gets started
        ebus.connect()

        def handler(message):
            self.assertEqual(message['body']['hello'], 'world')
            ebus.close()
            print("Passed!")
            latch.count_down()

        ebus.register_handler("echo-back", handler)
        ebus.send("echo", reply_address="echo-back", body={'hello': 'world'})
        latch.awaits(10)
        starter.stop()