コード例 #1
0
    def test_unset_instance_serializer(self):
        """
        Verify that calling unset serializers does not remove an instance level
        serializer
        """

        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {
            'hosts': hostlist,
            'serialization': (instance_serializer, instance_deserializer)}
        client = TestBaseClass.get_new_connection(method_config)

        aerospike.unset_serializers()
        response = client.put(
            self.test_key, self.mixed_record,
            serializer=aerospike.SERIALIZER_USER)

        _, _, bins = client.get(self.test_key)

        # tuples JSON-encode to a list, and we use this fact to check which
        # serializer ran:
        assert bins == {'normal': 1234,
                        'tuple': (
                            'instance serialized', 'instance deserialized'
                        )
                        }
        client.close()
コード例 #2
0
 def setup_class(cls):
     """
         Setup class
     """
     aerospike.unset_serializers()
     cls.mixed_record = {'normal': 1234, 'tuple': (1, 2, 3)}
     cls.test_key = ('test', 'demo', 'TestPythonSerializer')
コード例 #3
0
    def test_with_unset_serializer_python_serializer(self):
        """
        Invoke put() for mixed data record with python serializer and
        calling unset_serializers
        """
        aerospike.set_serializer((lambda v: json.dumps(v)))
        aerospike.set_deserializer((lambda v: json.loads(v)))
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {"hosts": hostlist}
        if user is None and password is None:
            client = aerospike.client(method_config).connect()
        else:
            client = aerospike.client(method_config).connect(user, password)
        key = ("test", "demo", 16)
        try:
            client.remove(key)
        except:
            pass

        rec = {"normal": 1234, "tuple": (1, 2, 3)}

        aerospike.unset_serializers()
        res = client.put(key, rec, serializer=aerospike.SERIALIZER_PYTHON)

        assert res == 0

        _, _, bins = client.get(key)

        # tuples JSON-encode to a list, and we use this fact to check which
        # serializer ran:
        assert bins == {"normal": 1234, "tuple": (1, 2, 3)}
        client.remove(key)
コード例 #4
0
    def test_with_class_serializer_and_instance_serializer_with_unset_serializer(self):
        """
        Invoke put() for mixed data record with python serializer.
        """
        aerospike.set_serializer((lambda v: json.dumps(v)))
        aerospike.set_deserializer((lambda v: json.loads(v)))
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {"hosts": hostlist}
        if user is None and password is None:
            client = aerospike.client(method_config).connect()
        else:
            client = aerospike.client(method_config).connect(user, password)
        key = ("test", "demo", 16)
        try:
            TestPythonSerializer.client.remove(key)
        except:
            pass

        rec = {"normal": 1234, "tuple": (1, 2, 3)}

        aerospike.unset_serializers()
        try:
            client.put(key, rec, serializer=aerospike.SERIALIZER_USER)
        except e.ClientError as exception:
            assert exception.code == -1
            assert exception.msg == "No serializer callback registered"
コード例 #5
0
    def test_with_unset_serializer_python_serializer(self):
        """
        Invoke put() for mixed data record with python serializer and
        calling unset_serializers
        """
        aerospike.set_serializer((lambda v: json.dumps(v)))
        aerospike.set_deserializer((lambda v: json.loads(v)))
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {'hosts': hostlist}
        if user is None and password is None:
            client = aerospike.client(method_config).connect()
        else:
            client = aerospike.client(method_config).connect(user, password)
        key = ('test', 'demo', 16)
        try:
            client.remove(key)
        except:
            pass

        rec = {'normal': 1234, 'tuple': (1, 2, 3)}

        aerospike.unset_serializers()
        res = client.put(key, rec, serializer=aerospike.SERIALIZER_PYTHON)

        assert res == 0

        _, _, bins = client.get(key)

        # tuples JSON-encode to a list, and we use this fact to check which
        # serializer ran:
        assert bins == {'normal': 1234, 'tuple': (1, 2, 3)}
        client.remove(key)
コード例 #6
0
    def test_with_class_serializer_and_instance_serializer_with_unset_serializer(
            self):
        """
        Invoke put() for mixed data record with python serializer.
        """
        aerospike.set_serializer((lambda v: json.dumps(v)))
        aerospike.set_deserializer((lambda v: json.loads(v)))
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {'hosts': hostlist}
        if user is None and password is None:
            client = aerospike.client(method_config).connect()
        else:
            client = aerospike.client(method_config).connect(user, password)
        key = ('test', 'demo', 16)
        try:
            TestPythonSerializer.client.remove(key)
        except:
            pass

        rec = {'normal': 1234, 'tuple': (1, 2, 3)}

        aerospike.unset_serializers()
        try:
            client.put(key, rec, serializer=aerospike.SERIALIZER_USER)
        except e.ClientError as exception:
            assert exception.code == -1
            assert exception.msg == "No serializer callback registered"
コード例 #7
0
    def setup_class(cls):
        """
            Setup class
        """
        hostlist, user, password = TestBaseClass.get_hosts()
        config = {"hosts": hostlist}
        if user is None and password is None:
            TestPythonSerializer.client = aerospike.client(config).connect()
        else:
            TestPythonSerializer.client = aerospike.client(config).connect(user, password)

        # Unset previously set class serializers if set
        aerospike.unset_serializers()
コード例 #8
0
    def setup_class(cls):
        """
            Setup class
        """
        hostlist, user, password = TestBaseClass.get_hosts()
        config = {'hosts': hostlist}
        if user is None and password is None:
            TestPythonSerializer.client = aerospike.client(config).connect()
        else:
            TestPythonSerializer.client = aerospike.client(config).connect(
                user, password)

        # Unset previously set class serializers if set
        aerospike.unset_serializers()
コード例 #9
0
    def setup(self, request, as_connection):
        '''
        Remove the test key if it exists each time through.
        Unset any set serializers
        '''
        aerospike.unset_serializers()
        # Try to remove the key if it exists

        def teardown():
            try:
                as_connection.remove(self.test_key)
            except:
                pass
            aerospike.unset_serializers()
        request.addfinalizer(teardown)
コード例 #10
0
    def test_unsetting_serializers_after_a_record_put(self):
        aerospike.set_serializer(class_serializer)
        aerospike.set_deserializer(class_deserializer)

        self.as_connection.put(
            self.test_key, self.mixed_record,
            serializer=aerospike.SERIALIZER_USER)

        aerospike.unset_serializers()

        _, _, record = self.as_connection.get(self.test_key)
        # this should not have been deserialized with the class serializer
        # it will have been deserialized by the class deserializer,
        # so this should be a deserialization of 'class serialized'
        assert record['tuple'] != ('class serialized', 'class deserialized')
コード例 #11
0
    def test_class_serializer_unset(self):
        """
        Verify that calling unset_serializers actually removes
        the class serializer
        """
        aerospike.set_serializer(json.dumps)
        aerospike.set_deserializer(json.loads)
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {
            'hosts': hostlist
        }
        client = TestBaseClass.get_new_connection(method_config)

        aerospike.unset_serializers()
        with pytest.raises(e.ClientError) as err_info:
            client.put(
                self.test_key, self.mixed_record,
                serializer=aerospike.SERIALIZER_USER)

        assert err_info.value.code == AerospikeStatus.AEROSPIKE_ERR_CLIENT
コード例 #12
0
    def test_with_unset_serializer_python_serializer(self):
        """
        Invoke put() for mixed data record with python serializer and
        calling unset_serializers
        """
        aerospike.set_serializer(json.dumps)
        aerospike.set_deserializer(json.loads)
        hostlist, user, password = TestBaseClass.get_hosts()
        method_config = {
            'hosts': hostlist
        }
        client = TestBaseClass.get_new_connection(method_config)

        aerospike.unset_serializers()
        response = client.put(
            self.test_key, self.mixed_record,
            serializer=aerospike.SERIALIZER_PYTHON)

        _, _, bins = client.get(self.test_key)

        assert bins == {'normal': 1234, 'tuple': (1, 2, 3)}
        client.close()
コード例 #13
0
 def teardown_class(cls):
     TestUserSerializer.client.close()
     aerospike.unset_serializers()
コード例 #14
0
 def teardown():
     try:
         as_connection.remove(self.test_key)
     except:
         pass
     aerospike.unset_serializers()