Пример #1
0
 def test_conn_socket_upgrade(self):
     c = AsyncConn('127.0.0.1', 4150, **self.identify_options)
     c.on('ready', self.stop)
     c.connect()
     self.wait()
     assert isinstance(c.socket, SnappySocket)
     assert isinstance(c.socket._socket, ssl.SSLSocket)
Пример #2
0
 def test_conn_identify(self):
     c = AsyncConn('127.0.0.1', 4150)
     c.on('identify_response', self.stop)
     c.connect()
     response = self.wait()
     print(response)
     assert response['conn'] is c
     assert isinstance(response['data'], dict)
Пример #3
0
    def _send_messages(self, topic, count, body):
        c = AsyncConn('127.0.0.1', 4150)
        c.connect()

        def _on_ready(*args, **kwargs):
            for i in range(count):
                c.send(protocol.pub(topic, body))

        c.on('ready', _on_ready)
Пример #4
0
def _get_test_conn():
    conn = AsyncConn('test', 4150)
    # now set the stream attribute, which is ordinarily set in conn.connect()
    conn.stream = create_autospec(IOStream)
    fut = Future()
    fut.set_result(conn.stream)
    conn.stream.connect.return_value = fut
    conn.stream.read_bytes.return_value = Future()
    return conn
Пример #5
0
 def test_conn_identify_options(self):
     c = AsyncConn('127.0.0.1', 4150, **self.identify_options)
     c.on('identify_response', self.stop)
     c.connect()
     response = self.wait()
     print(response)
     assert response['conn'] is c
     assert isinstance(response['data'], dict)
     assert response['data']['snappy'] is True
     assert response['data']['tls_v1'] is True
Пример #6
0
    def test_conn_subscribe(self):
        topic = 'test_conn_suscribe_%s' % time.time()
        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_ready(*args, **kwargs):
            c.on('response', self.stop)
            c.send(protocol.subscribe(topic, 'ch'))

        c.on('ready', _on_ready)
        c.connect()
        response = self.wait()
        print(response)
        assert response['conn'] is c
        assert response['data'] == b'OK'
Пример #7
0
    def test_conn_identify(self):
        auth_app = tornado.web.Application([("/auth", AuthHandler)])
        auth_srv = tornado.httpserver.HTTPServer(auth_app)
        auth_srv.add_socket(self.auth_sock)

        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_ready(*args, **kwargs):
            c.on('response', self.stop)
            c.send(protocol.subscribe('authtopic', 'ch'))

        c.on('ready', _on_ready)
        c.connect()
        response = self.wait()
        auth_srv.stop()
        print(response)
        assert response['conn'] is c
        assert response['data'] == b'OK'
Пример #8
0
 def test_conn_socket_upgrade(self):
     c = AsyncConn('127.0.0.1', 4150, **self.identify_options)
     c.on('ready', self.stop)
     c.connect()
     self.wait()
     assert isinstance(c.socket, SnappySocket)
     assert isinstance(c.socket._socket, ssl.SSLSocket)
Пример #9
0
 def test_conn_identify(self):
     c = AsyncConn('127.0.0.1', 4150)
     c.on('identify_response', self.stop)
     c.connect()
     response = self.wait()
     print(response)
     assert response['conn'] is c
     assert isinstance(response['data'], dict)
Пример #10
0
    def test_conn_messages(self):
        self.msg_count = 0

        topic = 'test_conn_suscribe_%s' % time.time()
        self._send_messages(topic, 5, b'sup')

        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_message(*args, **kwargs):
            self.msg_count += 1
            if c.in_flight == 5:
                self.stop()

        def _on_ready(*args, **kwargs):
            c.on('message', _on_message)
            c.send(protocol.subscribe(topic, 'ch'))
            c.send_rdy(5)

        c.on('ready', _on_ready)
        c.connect()

        self.wait()
        assert self.msg_count == 5
Пример #11
0
    def _send_messages(self, topic, count, body):
        c = AsyncConn('127.0.0.1', 4150)
        c.connect()

        def _on_ready(*args, **kwargs):
            for i in range(count):
                c.send(protocol.pub(topic, body))

        c.on('ready', _on_ready)
Пример #12
0
 def test_conn_identify_options(self):
     c = AsyncConn('127.0.0.1', 4150, **self.identify_options)
     c.on('identify_response', self.stop)
     c.connect()
     response = self.wait()
     print(response)
     assert response['conn'] is c
     assert isinstance(response['data'], dict)
     assert response['data']['snappy'] is True
     assert response['data']['tls_v1'] is True
Пример #13
0
    def test_conn_subscribe(self):
        topic = 'test_conn_suscribe_%s' % time.time()
        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_ready(*args, **kwargs):
            c.on('response', self.stop)
            c.send(protocol.subscribe(topic, 'ch'))

        c.on('ready', _on_ready)
        c.connect()
        response = self.wait()
        print(response)
        assert response['conn'] is c
        assert response['data'] == b'OK'
Пример #14
0
    def test_conn_identify(self):
        auth_app = tornado.web.Application([("/auth", AuthHandler)])
        auth_srv = tornado.httpserver.HTTPServer(auth_app)
        auth_srv.add_socket(self.auth_sock)

        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_ready(*args, **kwargs):
            c.on('response', self.stop)
            c.send(protocol.subscribe('authtopic', 'ch'))

        c.on('ready', _on_ready)
        c.connect()
        response = self.wait()
        auth_srv.stop()
        print(response)
        assert response['conn'] is c
        assert response['data'] == b'OK'
Пример #15
0
    def test_conn_messages(self):
        self.msg_count = 0

        topic = 'test_conn_suscribe_%s' % time.time()
        self._send_messages(topic, 5, b'sup')

        c = AsyncConn('127.0.0.1', 4150, **self.identify_options)

        def _on_message(*args, **kwargs):
            self.msg_count += 1
            if c.in_flight == 5:
                self.stop()

        def _on_ready(*args, **kwargs):
            c.on('message', _on_message)
            c.send(protocol.subscribe(topic, 'ch'))
            c.send_rdy(5)

        c.on('ready', _on_ready)
        c.connect()

        self.wait()
        assert self.msg_count == 5
Пример #16
0
def _get_test_conn():
    conn = AsyncConn('test', 4150)
    # now set the stream attribute, which is ordinarily set in conn.connect()
    conn.stream = create_autospec(IOStream)
    return conn
Пример #17
0
def _get_test_conn():
    conn = AsyncConn('test', 4150)
    # now set the stream attribute, which is ordinarily set in conn.connect()
    conn.stream = create_autospec(IOStream)
    return conn