Пример #1
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(9) == 'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size))
        assert 'gnsq' in data['user_agent']

        resp = json.dumps({'auth_required': True})
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))

        assert socket.recv(5) == 'AUTH\n'
        assert nsq.unpack_size(socket.recv(4)) == 6
        assert socket.recv(6) == 'secret'

        resp = json.dumps({'identity': 'awesome'})
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #2
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(9) == b'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size).decode('utf-8'))
        assert 'gnsq' in data['user_agent']

        resp = six.b(json.dumps({'auth_required': True}))
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))

        assert socket.recv(5) == b'AUTH\n'
        assert nsq.unpack_size(socket.recv(4)) == 6
        assert socket.recv(6) == b'secret'

        resp = six.b(json.dumps({'identity': 'awesome'}))
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #3
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(5) == b'AUTH\n'

        assert nsq.unpack_size(socket.recv(4)) == 6
        assert socket.recv(6) == b'secret'

        resp = six.b(json.dumps({'identity': 'awesome'}))
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #4
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(11) == b'MPUB topic\n'

        size = nsq.unpack_size(socket.recv(4))
        data = socket.recv(size)

        head, data = data[:4], data[4:]
        assert nsq.unpack_size(head) == 2

        for _ in range(2):
            head, data = data[:4], data[4:]
            assert nsq.unpack_size(head) == 3

            head, data = data[:3], data[3:]
            assert head == b'sup'

        assert data == b''
Пример #5
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(9) == b'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size).decode('utf-8'))

        assert 'gnsq' in data['user_agent']
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, b'OK'))
Пример #6
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(5) == 'AUTH\n'

        assert nsq.unpack_size(socket.recv(4)) == 6
        assert socket.recv(6) == 'secret'

        resp = json.dumps({'identity': 'awesome'})
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #7
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(11) == 'MPUB topic\n'

        size = nsq.unpack_size(socket.recv(4))
        data = socket.recv(size)

        head, data = data[:4], data[4:]
        assert nsq.unpack_size(head) == 2

        for _ in xrange(2):
            head, data = data[:4], data[4:]
            assert nsq.unpack_size(head) == 3

            head, data = data[:3], data[3:]
            assert head == 'sup'

        assert data == ''
Пример #8
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(9) == 'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size))

        assert 'gnsq' in data['user_agent']
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, 'OK'))
Пример #9
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(9) == 'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size))

        assert 'gnsq' in data['user_agent']
        resp = json.dumps({'test': 42})
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #10
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(9) == b'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size).decode('utf-8'))

        assert 'gnsq' in data['user_agent']
        resp = six.b(json.dumps({'test': 42}))
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, resp))
Пример #11
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(9) == b'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size).decode('utf-8'))

        assert isinstance(data, dict)
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, b'OK'))

        msg = b'SUB topic channel\n'
        assert socket.recv(len(msg)) == msg
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, b'OK'))

        for i in range(10):
            assert socket.recv(6) == b'RDY 1\n'

            body = six.b(json.dumps({'data': {'test_key': i}}))
            ts = i * 1000 * 1000
            socket.send(mock_response_message(ts, i, i, body))
Пример #12
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(9) == 'IDENTIFY\n'

        size = nsq.unpack_size(socket.recv(4))
        data = json.loads(socket.recv(size))

        assert isinstance(data, dict)
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, 'OK'))

        msg = 'SUB topic channel\n'
        assert socket.recv(len(msg)) == msg
        socket.send(mock_response(nsq.FRAME_TYPE_RESPONSE, 'OK'))

        for i in xrange(10):
            assert socket.recv(6) == 'RDY 1\n'

            body = json.dumps({'data': {'test_key': i}})
            ts = i * 1000 * 1000
            socket.send(mock_response_message(ts, i, i, body))
Пример #13
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(10) == b'PUB topic\n'

        assert nsq.unpack_size(socket.recv(4)) == 3
        assert socket.recv(3) == b'sup'
Пример #14
0
    def handle(socket, address):
        assert socket.recv(4) == '  V2'
        assert socket.recv(10) == 'PUB topic\n'

        assert nsq.unpack_size(socket.recv(4)) == 3
        assert socket.recv(3) == 'sup'
Пример #15
0
    def handle(socket, address):
        assert socket.recv(4) == b'  V2'
        assert socket.recv(14) == b'DPUB topic 42\n'

        assert nsq.unpack_size(socket.recv(4)) == 3
        assert socket.recv(3) == b'sup'