Ejemplo n.º 1
0
    def test_neg_calc_digest_with_only_ns(self):
        """
            Invoke calc_digest() with a ns and no other parameters
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest("test")

        assert "argument 'set' (pos 2)" in str(typeError.value)
    def test_neg_calc_digest_with_invalid_parameters(self, ns, set, key, err_msg):
        """
            Invoke calc_digest() with invalid parameters
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest(ns, set, key)

        assert err_msg in str(typeError.value)
    def test_neg_calc_digest_with_only_ns(self):
        """
            Invoke calc_digest() with a ns and no other parameters
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest("test")

        assert "Required argument 'set' (pos 2) not found" in str(typeError.value)
    def test_neg_calc_digest_with_no_parameter(self):
        """
            Invoke calc_digest() without any mandatory parameters.
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest()

        assert "Required argument 'ns' (pos 1) not found" in str(typeError.value)
Ejemplo n.º 5
0
    def test_neg_calc_digest_with_no_parameter(self):
        """
            Invoke calc_digest() without any mandatory parameters.
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest()

        assert "argument 'ns' (pos 1)" in str(typeError.value)
    def test_neg_calc_digest_with_invalid_parameters(self, ns, set, key,
                                                     err_msg):
        """
            Invoke calc_digest() with invalid parameters
        """
        with pytest.raises(TypeError) as typeError:
            aerospike.calc_digest(ns, set, key)

        assert err_msg in str(typeError.value)
    def test_pos_calc_digest_with_key(self, ns, set, key):
        """
            Invoke calc_digest() with key
        """
        digest = aerospike.calc_digest(ns, set, key)

        assert type(digest) == bytearray
    def test_predexp_key_operate_record_digest_modulo(self):
        """
        Invoke the C client aerospike_key_operate with a rec_digest_modulo predexp.
        """

        less_than_128 = 0
        for i in range(100):
            key = 'test', 'demo', i
            if aerospike.calc_digest(*key)[-1] < 128:
                less_than_128 += 1
            self.as_connection.put(key, {'dig_id': i})

        results = []

        predexp = [
            as_predexp.rec_digest_modulo(256),
            as_predexp.integer_value(128),
            as_predexp.integer_less()
        ]

        ops = [operations.read('dig_id')]

        for i in range(100):
            try:
                key = 'test', 'demo', i
                _, _, res = self.as_connection.operate(
                    key, ops, policy={'predexp': predexp})
                results.append(res)
            except:
                pass
            self.as_connection.remove(key)

        assert len(results) == less_than_128
    def test_expressions_key_operate_record_digest_modulo(self):
        """
        Invoke the C client aerospike_key_operate with a rec_digest_modulo expressions.
        """

        less_than_128 = 0
        for i in range(100):
            key = 'test', 'demo', i
            if aerospike.calc_digest(*key)[-1] < 128:
                less_than_128 += 1
            self.as_connection.put(key, {'dig_id': i})

        results = []

        expr = exp.LT(exp.DigestMod(256), 128).compile()

        ops = [operations.read('dig_id')]

        for i in range(100):
            try:
                key = 'test', 'demo', i
                _, _, res = self.as_connection.operate(
                    key, ops, policy={'expressions': expr})
                results.append(res)
            except:
                pass
            self.as_connection.remove(key)

        assert len(results) == less_than_128
    def test_pos_calc_digest_with_key(self, ns, set, key):
        """
            Invoke calc_digest() with key
        """
        digest = aerospike.calc_digest(ns, set, key)

        assert isinstance(digest, bytearray)
    def test_pos_calc_digest_with_key(self, ns, set, key):
        """
            Invoke calc_digest() with key
        """
        digest = aerospike.calc_digest(ns, set, key)

        assert isinstance(digest, bytearray)
Ejemplo n.º 12
0
    def test_select_with_key_and_multiple_bins_to_select_policy_key_send(self):

        bins_to_select = ['c', 'd']
        policy = {'timeout': 1000, 'key': aerospike.POLICY_KEY_SEND}
        key, meta, bins = self.as_connection.select(self.test_key,
                                                    bins_to_select, policy)

        # Calculate the key's digest
        key_digest = aerospike.calc_digest(*self.test_key)

        assert bins == {'c': 1234, 'd': '!@#@#$QSDAsd;as'}
        assert key == ('test', 'demo', 1, key_digest)
        assert meta is not None
Ejemplo n.º 13
0
    def test_select_many_with_all_non_existent_key(self):
        """
        Test call to select_many with only non existent keys
        """
        keys = [('test', 'demo', 'key')]
        #  Precalculate the digest of this key
        desired_digest = aerospike.calc_digest(*keys[0])
        filter_bins = ['title', 'name', 'country']
        records = self.as_connection.select_many(keys, filter_bins)

        assert len(records) == 1
        assert records == [(('test', 'demo', 'key', desired_digest), None,
                            None)]
    def test_select_with_key_and_multiple_bins_to_select_policy_key_send(self):

        bins_to_select = ['c', 'd']
        policy = {'timeout': 1000, 'key': aerospike.POLICY_KEY_SEND}
        key, meta, bins = self.as_connection.select(
            self.test_key, bins_to_select, policy)

        # Calculate the key's digest
        key_digest = aerospike.calc_digest(*self.test_key)

        assert bins == {'c': 1234, 'd': '!@#@#$QSDAsd;as'}
        assert key == ('test', 'demo', 1, key_digest)
        assert meta is not None
Ejemplo n.º 15
0
    def test_digest_modulo(self):
        # Count of digests whose last byte is < 128
        less_than_128 = 0
        expected_ids = set([])
        for i in range(100):
            key = 'test', 'demo', i
            if aerospike.calc_digest(*key)[-1] < 128:
                expected_ids.add(i)
                less_than_128 += 1

        expr = exp.LT(exp.DigestMod(256), 128)

        results = self.query.results(policy={'expressions': expr.compile()})
        assert len(results) == less_than_128
Ejemplo n.º 16
0
    def test_pos_calc_digest_on_inserted_key(self):
        """
            Invoke calc_digest() on inserted key
        """
        client = TestBaseClass.get_new_connection()

        key = ('test', 'demo', 'get_digest_key')
        client.put(key, {"bin1": 1})
        key, meta, bins = client.get(key)

        assert key[3] == aerospike.calc_digest("test", "demo",
                                               "get_digest_key")

        client.remove(key)
        client.close()
    def test_pos_calc_digest_on_inserted_key(self):
        """
            Invoke calc_digest() on inserted key
        """
        client = TestBaseClass.get_new_connection()

        key = ('test', 'demo', 'get_digest_key')
        client.put(key, {"bin1": 1})
        key, meta, bins = client.get(key)

        assert key[3] == aerospike.calc_digest(
            "test", "demo", "get_digest_key")

        client.remove(key)
        client.close()
    def setup(self, request, as_connection):
        self.test_demo_1_digest = aerospike.calc_digest('test', 'demo', 1)
        self.added_keys = []

        for i in range(5):
            key = ('test', 'demo', i)
            rec = {'name': 'name%s' % (str(i)), 'age': i}
            as_connection.put(key, rec)
            self.added_keys.append(key)

        def teardown():
            for key in self.added_keys:
                as_connection.remove(key)
            self.added_keys = []

        request.addfinalizer(teardown)
Ejemplo n.º 19
0
    def setup(self, request, as_connection):
        self.test_demo_1_digest = aerospike.calc_digest(
            'test', 'demo', 1)
        self.added_keys = []

        for i in range(5):
            key = ('test', 'demo', i)
            rec = {'name': 'name%s' % (str(i)), 'age': i}
            as_connection.put(key, rec)
            self.added_keys.append(key)

        def teardown():
            for key in self.added_keys:
                as_connection.remove(key)
            self.added_keys = []

        request.addfinalizer(teardown)
    def test_select_many_with_all_non_existent_key(self):
        """
        Test call to select_many with only non existent keys
        """
        keys = [('test', 'demo', 'key')]
        #  Precalculate the digest of this key
        desired_digest = aerospike.calc_digest(*keys[0])
        filter_bins = ['title', 'name', 'country']
        records = self.as_connection.select_many(keys, filter_bins)

        assert len(records) == 1
        assert records == [
            (
                ('test', 'demo', 'key', desired_digest),
                None,
                None
            )
        ]
Ejemplo n.º 21
0
    def test_digest_modulo(self):
        # Count of digests whose last byte is < 128
        less_than_128 = 0
        expected_ids = set([])
        for i in range(100):
            key = 'test', 'demo', i
            if aerospike.calc_digest(*key)[-1] < 128:
                expected_ids.add(i)
                less_than_128 += 1

        predexps = [
            predexp.rec_digest_modulo(256),
            predexp.integer_value(128),
            predexp.integer_less()
        ]

        self.query.predexp(predexps)
        results = self.query.results()
        assert len(results) == less_than_128
    def test_pos_calc_digest_on_inserted_key(self):
        """
            Invoke calc_digest() on inserted key
        """
        hostlist, user, password = TestBaseClass.get_hosts()
        config = {'hosts': hostlist}
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        key = ('test', 'demo', 'get_digest_key')
        client.put(key, {"bin1": 1})
        key, meta, bins = client.get(key)

        assert key[3] == aerospike.calc_digest("test", "demo", "get_digest_key")

        client.remove(key)
        client.close()
    def test_pos_calc_digest_on_inserted_key(self):
        """
            Invoke calc_digest() on inserted key
        """
        hostlist, user, password = TestBaseClass.get_hosts()
        config = {'hosts': hostlist}
        if user is None and password is None:
            client = aerospike.client(config).connect()
        else:
            client = aerospike.client(config).connect(user, password)

        key = ('test', 'demo', 'get_digest_key')
        client.put(key, {"bin1": 1})
        key, meta, bins = client.get(key)

        assert key[3] == aerospike.calc_digest("test", "demo",
                                               "get_digest_key")

        client.remove(key)
        client.close()
def test_validate_digest_bytes(pk, expected):
    # encode the primary key as bytes
    byte_key = bytearray(pk, 'utf-8')
    digest = aerospike.calc_digest(NAMESPACE, SET, byte_key)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected
def test_calculating_a_digest_with_no_set():
    expected = 'a443f05d05d962202b59abb402afae1737dbf66a'
    digest = aerospike.calc_digest(NAMESPACE, '', 1)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected
def test_validate_digest_str(pk, expected):
    digest = aerospike.calc_digest(NAMESPACE, SET, pk)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected
def test_validate_digest_str(pk, expected):
    digest = aerospike.calc_digest(NAMESPACE, SET, pk)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected
def test_calculating_a_digest_with_no_set():
    expected = 'a443f05d05d962202b59abb402afae1737dbf66a'
    digest = aerospike.calc_digest(NAMESPACE, '', 1)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected
def test_validate_digest_bytes(pk, expected):
    # encode the primary key as bytes
    byte_key = bytearray(pk, 'utf-8')
    digest = aerospike.calc_digest(NAMESPACE, SET, byte_key)
    hex_digest = b2a_hex(digest)
    assert convert_bytestr_to_str(hex_digest) == expected