當前位置: 首頁>>代碼示例>>Python>>正文


Python Nsqd.close_stream方法代碼示例

本文整理匯總了Python中gnsq.Nsqd.close_stream方法的典型用法代碼示例。如果您正苦於以下問題:Python Nsqd.close_stream方法的具體用法?Python Nsqd.close_stream怎麽用?Python Nsqd.close_stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gnsq.Nsqd的用法示例。


在下文中一共展示了Nsqd.close_stream方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_read

# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import close_stream [as 別名]
def test_read(body):
    @mock_server
    def handle(socket, address):
        socket.send(struct.pack('>l', len(body)))
        socket.send(body)

    with handle as server:
        conn = Nsqd(address='127.0.0.1', tcp_port=server.server_port)
        conn.connect()

        assert conn._read_response() == body
        conn.close_stream()
開發者ID:christhompson,項目名稱:gnsq,代碼行數:14,代碼來源:test_nsqd.py

示例2: test_disconnected

# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import close_stream [as 別名]
def test_disconnected():
    @mock_server
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(1) == ''

    with handle as server:
        conn = Nsqd(address='127.0.0.1', tcp_port=server.server_port)
        conn.connect()
        conn.close_stream()
        assert conn.state == states.DISCONNECTED

        with pytest.raises(errors.NSQSocketError):
            conn.nop()

        with pytest.raises(errors.NSQSocketError):
            conn.read_response()
開發者ID:christhompson,項目名稱:gnsq,代碼行數:19,代碼來源:test_nsqd.py

示例3: test_connection

# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import close_stream [as 別名]
def test_connection():
    @mock_server
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(1) == ''

    with handle as server:
        conn = Nsqd(address='127.0.0.1', tcp_port=server.server_port)
        assert conn.state == states.INIT

        conn.connect()
        assert conn.state == states.CONNECTED

        conn.connect()
        assert conn.state == states.CONNECTED

        conn.close_stream()
        assert conn.state == states.DISCONNECTED
開發者ID:christhompson,項目名稱:gnsq,代碼行數:20,代碼來源:test_nsqd.py

示例4: test_socket_upgrades

# 需要導入模塊: from gnsq import Nsqd [as 別名]
# 或者: from gnsq.Nsqd import close_stream [as 別名]
def test_socket_upgrades(tls, deflate, snappy):
    with NsqdIntegrationServer() as server:
        options = {
            'address': server.address,
            'tcp_port': server.tcp_port,
            'deflate': deflate,
            'snappy': snappy,
        }

        if tls:
            options.update({
                'tls_v1': True,
                'tls_options': {
                    'keyfile': server.tls_key,
                    'certfile': server.tls_cert,
                }
            })

        conn = Nsqd(**options)
        conn.connect()
        assert conn.state == states.CONNECTED

        if deflate and snappy:
            with pytest.raises(errors.NSQErrorCode):
                conn.identify()
            return

        if tls and BAD_GEVENT:
            with pytest.raises(AttributeError):
                conn.identify()
            return

        if tls and server.version < (0, 2, 28):
            with pytest.raises(ssl.SSLError):
                conn.identify()
            return

        resp = conn.identify()
        assert isinstance(resp, dict)

        assert resp['tls_v1'] is tls
        assert resp['deflate'] is deflate
        assert resp['snappy'] is snappy

        if tls and (deflate or snappy):
            assert isinstance(conn.stream.socket._socket, SSLSocket)
        elif tls:
            assert isinstance(conn.stream.socket, SSLSocket)

        if deflate:
            assert isinstance(conn.stream.socket, DefalteSocket)

        if snappy:
            assert isinstance(conn.stream.socket, SnappySocket)

        conn.publish('topic', 'sup')
        frame, data = conn.read_response()
        assert frame == nsq.FRAME_TYPE_RESPONSE
        assert data == 'OK'

        conn.subscribe('topic', 'channel')
        frame, data = conn.read_response()
        assert frame == nsq.FRAME_TYPE_RESPONSE
        assert data == 'OK'

        conn.ready(1)
        frame, data = conn.read_response()
        assert frame == nsq.FRAME_TYPE_MESSAGE
        assert data.body == 'sup'

        conn.close_stream()
開發者ID:christhompson,項目名稱:gnsq,代碼行數:73,代碼來源:test_nsqd.py


注:本文中的gnsq.Nsqd.close_stream方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。