コード例 #1
0
    def test_unsupported_cql_version(self, *args):
        c = self.make_connection()
        c._requests = {
            0: (c._handle_options_response, ProtocolHandler.decode_message, [])
        }
        c.defunct = Mock()
        c.cql_version = "3.0.3"

        # read in a SupportedMessage response
        header = self.make_header_prefix(SupportedMessage)

        options_buf = BytesIO()
        write_stringmultimap(options_buf, {
            'CQL_VERSION': ['7.8.9'],
            'COMPRESSION': []
        })
        options = options_buf.getvalue()

        c.process_msg(
            _Frame(version=4,
                   flags=0,
                   stream=0,
                   opcode=SupportedMessage.opcode,
                   body_offset=9,
                   end_pos=9 + len(options)), options)

        # make sure it errored correctly
        c.defunct.assert_called_once_with(ANY)
        args, kwargs = c.defunct.call_args
        self.assertIsInstance(args[0], ProtocolError)
コード例 #2
0
    def test_prefer_lz4_compression(self, *args):
        c = self.make_connection()
        c._requests = {
            0: (c._handle_options_response, ProtocolHandler.decode_message, [])
        }
        c.defunct = Mock()
        c.cql_version = "3.0.3"

        locally_supported_compressions.pop('lz4', None)
        locally_supported_compressions.pop('snappy', None)
        locally_supported_compressions['lz4'] = ('lz4compress',
                                                 'lz4decompress')
        locally_supported_compressions['snappy'] = ('snappycompress',
                                                    'snappydecompress')

        # read in a SupportedMessage response
        options_buf = BytesIO()
        write_stringmultimap(options_buf, {
            'CQL_VERSION': ['3.0.3'],
            'COMPRESSION': ['snappy', 'lz4']
        })
        options = options_buf.getvalue()

        c.process_msg(
            _Frame(version=4,
                   flags=0,
                   stream=0,
                   opcode=SupportedMessage.opcode,
                   body_offset=9,
                   end_pos=9 + len(options)), options)

        self.assertEqual(c.decompressor,
                         locally_supported_compressions['lz4'][1])
コード例 #3
0
    def test_requested_compression_not_available(self, *args):
        c = self.make_connection()
        c._requests = {0: (c._handle_options_response, ProtocolHandler.decode_message, [])}
        c.defunct = Mock()
        # request lz4 compression
        c.compression = "lz4"

        locally_supported_compressions.pop('lz4', None)
        locally_supported_compressions.pop('snappy', None)
        locally_supported_compressions['lz4'] = ('lz4compress', 'lz4decompress')
        locally_supported_compressions['snappy'] = ('snappycompress', 'snappydecompress')

        # read in a SupportedMessage response
        header = self.make_header_prefix(SupportedMessage)

        # the server only supports snappy
        options_buf = BytesIO()
        write_stringmultimap(options_buf, {
            'CQL_VERSION': ['3.0.3'],
            'COMPRESSION': ['snappy']
        })
        options = options_buf.getvalue()

        c.process_msg(_Frame(version=4, flags=0, stream=0, opcode=SupportedMessage.opcode, body_offset=9, end_pos=9 + len(options)), options)

        # make sure it errored correctly
        c.defunct.assert_called_once_with(ANY)
        args, kwargs = c.defunct.call_args
        self.assertIsInstance(args[0], ProtocolError)
コード例 #4
0
    def test_handle_read__fullmessage(self):
        """
        Verify that handle_read() processes complete messages properly.
        """
        self.obj_ut.process_msg = Mock()
        self.assertEqual(self.obj_ut._iobuf.getvalue(),
                         b'')  # buf starts empty

        # write a complete message, plus 'NEXT' (to simulate next message)
        body = b'this is the drum roll'
        extra = b'NEXT'
        self.obj_ut._iobuf.write(b'\x84\x01\x00\x02\x03\x00\x00\x00\x15' +
                                 body + extra)
        self.obj_ut.handle_read()
        self.assertEqual(self.obj_ut._iobuf.getvalue(), extra)
        self.obj_ut.process_msg.assert_called_with(
            _Frame(version=4,
                   flags=1,
                   stream=2,
                   opcode=3,
                   body_offset=9,
                   end_pos=9 + len(body)), body)