From 023e6574d02bb9b7bc6deeaa611dddf962b960b2 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:16:18 -0700 Subject: [PATCH 1/7] Add support for persisting index --- .../operations/map_operations.py | 30 +++++++++++++++++++ doc/client.rst | 5 ++++ src/include/policy.h | 1 + src/main/client/operate.c | 18 ++++++++++- src/main/policy.c | 1 + test/new_tests/test_map_operation_helpers.py | 11 +++++++ 6 files changed, 65 insertions(+), 1 deletion(-) diff --git a/aerospike_helpers/operations/map_operations.py b/aerospike_helpers/operations/map_operations.py index 97af1c64d..ae8d9575b 100755 --- a/aerospike_helpers/operations/map_operations.py +++ b/aerospike_helpers/operations/map_operations.py @@ -41,6 +41,8 @@ COUNT_KEY = "count" RANK_KEY = "rank" CTX_KEY = "ctx" +MAP_ORDER_KEY = "map_order" +PERSIST_INDEX_KEY = "persist_index" def map_set_policy(bin_name: str, policy, ctx: Optional[list] = None): @@ -65,6 +67,34 @@ def map_set_policy(bin_name: str, policy, ctx: Optional[list] = None): return op_dict +def map_create(bin_name: str, map_order: int, persist_index: bool, ctx: Optional[list] = None): + """ + Create map create operation. + + Server creates map at given context level. + + Args: + bin_name (str): Bin name. + map_order (int): Map order. + persist_index (bool): If true, persist map index. A map index improves lookup performance, + but requires more storage. A map index can be created for a top-level + ordered map only. Nested and unordered map indexes are not supported. + ctx (Optional[dict]): An optional list of nested CDT :class:`cdt_ctx ` + specifying the path to nested map. If not defined, the top-level map is used. + """ + op_dict = { + OP_KEY: aerospike.OP_MAP_CREATE, + BIN_KEY: bin_name, + MAP_ORDER_KEY: map_order, + PERSIST_INDEX_KEY: persist_index + } + + if ctx is not None: + op_dict[CTX_KEY] = ctx + + return op_dict + + def map_put(bin_name: str, key, value, map_policy: Optional[dict] = None, ctx: Optional[list] = None): """Creates a map_put operation. diff --git a/doc/client.rst b/doc/client.rst index 0060c2604..197c2614a 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -2296,6 +2296,11 @@ Map Policies | | Default: :data:`aerospike.MAP_UNORDERED` + * **persist_index** (:class:`bool`) + | If :py:obj:`True`, persist map index. A map index improves lookup performance, + | but requires more storage. A map index can be created for a top-level + | ordered map only. Nested and unordered map indexes are not supported. + Example: .. code-block:: python diff --git a/src/include/policy.h b/src/include/policy.h index 9980b3965..f48fefc11 100644 --- a/src/include/policy.h +++ b/src/include/policy.h @@ -95,6 +95,7 @@ enum Aerospike_list_operations { enum Aerospike_map_operations { OP_MAP_SET_POLICY = 1101, + OP_MAP_CREATE, OP_MAP_PUT, OP_MAP_PUT_ITEMS, OP_MAP_INCREMENT, diff --git a/src/main/client/operate.c b/src/main/client/operate.c index a1ce5f7c6..79d776e6d 100644 --- a/src/main/client/operate.c +++ b/src/main/client/operate.c @@ -283,7 +283,8 @@ bool opRequiresValue(int op) op != OP_MAP_REMOVE_BY_KEY && op != OP_MAP_REMOVE_BY_INDEX && op != OP_MAP_REMOVE_BY_RANK && op != OP_MAP_GET_BY_KEY && op != OP_MAP_GET_BY_INDEX && op != OP_MAP_GET_BY_KEY_RANGE && - op != OP_MAP_GET_BY_RANK && op != AS_OPERATOR_DELETE); + op != OP_MAP_GET_BY_RANK && op != AS_OPERATOR_DELETE && + op != OP_MAP_CREATE); } bool opRequiresRange(int op) @@ -347,6 +348,10 @@ as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val, PyObject *py_range = NULL; PyObject *py_map_policy = NULL; PyObject *py_return_type = NULL; + // For map_create operation + PyObject *py_map_order = NULL; + PyObject *py_persist_index = NULL; + Py_ssize_t pos = 0; if (get_operation(err, py_val, &operation) != AEROSPIKE_OK) { @@ -419,6 +424,12 @@ as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val, CONVERT_PY_CTX_TO_AS_CTX(); ctx_ref = (ctx_in_use ? &ctx : NULL); } + else if (strcmp(name, "map_order") == 0) { + py_map_order = value; + } + else if (strcmp(name, "persist_index") == 0) { + py_persist_index = value; + } else { as_error_update( err, AEROSPIKE_ERR_PARAM, @@ -653,6 +664,11 @@ as_status add_op(AerospikeClient *self, as_error *err, PyObject *py_val, case OP_MAP_SET_POLICY: as_operations_map_set_policy(ops, bin, ctx_ref, &map_policy); break; + case OP_MAP_CREATE:; + as_map_order order = (as_map_order)PyLong_AsLong(py_map_order); + bool persist_index = PyObject_IsTrue(py_persist_index); + as_operations_map_create_all(ops, bin, ctx_ref, order, persist_index); + break; case OP_MAP_PUT: CONVERT_VAL_TO_AS_VAL(); CONVERT_KEY_TO_AS_VAL(); diff --git a/src/main/policy.c b/src/main/policy.c index e89e9e77f..e0fd08259 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -187,6 +187,7 @@ static AerospikeConstants aerospike_constants[] = { {OP_LIST_INCREMENT, "OP_LIST_INCREMENT"}, {OP_MAP_SET_POLICY, "OP_MAP_SET_POLICY"}, + {OP_MAP_CREATE, "OP_MAP_CREATE"}, {OP_MAP_PUT, "OP_MAP_PUT"}, {OP_MAP_PUT_ITEMS, "OP_MAP_PUT_ITEMS"}, {OP_MAP_INCREMENT, "OP_MAP_INCREMENT"}, diff --git a/test/new_tests/test_map_operation_helpers.py b/test/new_tests/test_map_operation_helpers.py index 0b88b4fcc..044d9e040 100644 --- a/test/new_tests/test_map_operation_helpers.py +++ b/test/new_tests/test_map_operation_helpers.py @@ -394,3 +394,14 @@ def test_map_get_exists_by_rank_range(self): operations = [map_ops.map_get_by_rank_range(self.test_bin, 1, 2, return_type=aerospike.MAP_RETURN_EXISTS)] ret_vals = get_map_result_from_operation(self.as_connection, self.test_key, operations, self.test_bin) assert ret_vals is True + + def test_map_create(self): + # This should create an empty dictionary + # map_create only works if a map does not already exist at the given bin and context path + operations = [ + map_ops.map_create(bin_name="new_map", map_order=aerospike.MAP_KEY_ORDERED, persist_index=False, ctx=None) + ] + get_map_result_from_operation(self.as_connection, self.test_key, operations, "new_map") + + res_map = self.as_connection.get(self.test_key)[2]["new_map"] + assert res_map == {} From 67819ad055dff3bc985f61d6fb2a41a18be7e21a Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:26:32 -0700 Subject: [PATCH 2/7] Move new map op to end of enum to avoid breaking type stubs --- aerospike-stubs/aerospike.pyi | 1 + src/include/policy.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/aerospike-stubs/aerospike.pyi b/aerospike-stubs/aerospike.pyi index c661d0538..b5f066213 100644 --- a/aerospike-stubs/aerospike.pyi +++ b/aerospike-stubs/aerospike.pyi @@ -238,6 +238,7 @@ OP_MAP_REMOVE_BY_VALUE_RANK_RANGE_REL: Literal[1128] OP_MAP_REMOVE_BY_VALUE_REL_INDEX_RANGE: Literal[1138] OP_MAP_REMOVE_BY_VALUE_REL_RANK_RANGE: Literal[1139] OP_MAP_REMOVE_BY_VALUE_REL_RANK_RANGE_TO_END: Literal[1133] +OP_MAP_CREATE: Literal[1144] OP_MAP_SET_POLICY: Literal[1101] OP_MAP_SIZE: Literal[1106] POLICY_COMMIT_LEVEL_ALL: Literal[0] diff --git a/src/include/policy.h b/src/include/policy.h index f48fefc11..25548c02d 100644 --- a/src/include/policy.h +++ b/src/include/policy.h @@ -95,7 +95,6 @@ enum Aerospike_list_operations { enum Aerospike_map_operations { OP_MAP_SET_POLICY = 1101, - OP_MAP_CREATE, OP_MAP_PUT, OP_MAP_PUT_ITEMS, OP_MAP_INCREMENT, @@ -137,7 +136,8 @@ enum Aerospike_map_operations { OP_MAP_GET_BY_KEY_REL_INDEX_RANGE, OP_MAP_GET_BY_VALUE_RANK_RANGE_REL_TO_END, OP_MAP_GET_BY_INDEX_RANGE_TO_END, - OP_MAP_GET_BY_RANK_RANGE_TO_END + OP_MAP_GET_BY_RANK_RANGE_TO_END, + OP_MAP_CREATE }; enum aerospike_bitwise_operations { From 0f55dc62d4397b51075bf2e458be917b80970750 Mon Sep 17 00:00:00 2001 From: juliannguyen4 <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:48:51 -0700 Subject: [PATCH 3/7] Update map_operations.py docs --- aerospike_helpers/operations/map_operations.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aerospike_helpers/operations/map_operations.py b/aerospike_helpers/operations/map_operations.py index ae8d9575b..00577a8d7 100755 --- a/aerospike_helpers/operations/map_operations.py +++ b/aerospike_helpers/operations/map_operations.py @@ -75,8 +75,8 @@ def map_create(bin_name: str, map_order: int, persist_index: bool, ctx: Optional Args: bin_name (str): Bin name. - map_order (int): Map order. - persist_index (bool): If true, persist map index. A map index improves lookup performance, + map_order (int): See :ref:`aerospike_map_order` for possible values. + persist_index (bool): If :py:obj:`True`, persist map index. A map index improves lookup performance, but requires more storage. A map index can be created for a top-level ordered map only. Nested and unordered map indexes are not supported. ctx (Optional[dict]): An optional list of nested CDT :class:`cdt_ctx ` From 39b71228947757f9e9dcb5dd3182685de8b98fa0 Mon Sep 17 00:00:00 2001 From: juliannguyen4 <109386615+juliannguyen4@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:11:23 -0700 Subject: [PATCH 4/7] Remove unimplemented persist_index --- doc/client.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/client.rst b/doc/client.rst index 197c2614a..0060c2604 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -2296,11 +2296,6 @@ Map Policies | | Default: :data:`aerospike.MAP_UNORDERED` - * **persist_index** (:class:`bool`) - | If :py:obj:`True`, persist map index. A map index improves lookup performance, - | but requires more storage. A map index can be created for a top-level - | ordered map only. Nested and unordered map indexes are not supported. - Example: .. code-block:: python From af2abfe7d4780a805fce8f170c5121c88d20cbec Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:10:16 -0700 Subject: [PATCH 5/7] Revert "Remove unimplemented persist_index" This reverts commit 39b71228947757f9e9dcb5dd3182685de8b98fa0. --- doc/client.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/client.rst b/doc/client.rst index 0060c2604..197c2614a 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -2296,6 +2296,11 @@ Map Policies | | Default: :data:`aerospike.MAP_UNORDERED` + * **persist_index** (:class:`bool`) + | If :py:obj:`True`, persist map index. A map index improves lookup performance, + | but requires more storage. A map index can be created for a top-level + | ordered map only. Nested and unordered map indexes are not supported. + Example: .. code-block:: python From dad3b560636ff0e928e0fb62bc11e14f8e96d2b5 Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 18 Oct 2023 09:37:05 -0700 Subject: [PATCH 6/7] Add persist index option in map policy --- src/main/policy.c | 17 ++++++++++++++++- test/new_tests/test_map_operation_helpers.py | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/policy.c b/src/main/policy.c index e0fd08259..745eaa35b 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -1148,7 +1148,22 @@ as_status pyobject_to_map_policy(as_error *err, PyObject *py_policy, } MAP_POLICY_SET_FIELD(map_write_mode); - as_map_policy_set(policy, map_order, map_write_mode); + + PyObject *py_persist_index = + PyDict_GetItemString(py_policy, "persist_index"); + bool persist_index; + if (!py_persist_index) { + // Default value if persist_index isn't set in policy + persist_index = false; + } + else if (!PyBool_Check(py_persist_index)) { + // persist_index value must be valid if it is set + return as_error_update(err, AEROSPIKE_ERR_PARAM, + "persist_index is not a boolean"); + } + + persist_index = (bool)PyObject_IsTrue(py_persist_index); + as_map_policy_set_all(policy, map_order, map_write_mode, persist_index); return err->code; } diff --git a/test/new_tests/test_map_operation_helpers.py b/test/new_tests/test_map_operation_helpers.py index 044d9e040..d7a3dd3f8 100644 --- a/test/new_tests/test_map_operation_helpers.py +++ b/test/new_tests/test_map_operation_helpers.py @@ -79,11 +79,27 @@ def test_map_set_policy(self): """ Test setting map policy with an operation """ - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_VALUE_ORDERED} + map_policy = { + "map_write_mode": aerospike.MAP_CREATE_ONLY, + "map_order": aerospike.MAP_KEY_VALUE_ORDERED, + "persist_index": True + } operations = [map_ops.map_set_policy(self.test_bin, map_policy)] self.as_connection.operate(self.test_key, operations) + def test_map_policy_invalid_persist_index(self): + map_policy = { + "persist_index": 1 + } + operations = [map_ops.map_set_policy(self.test_bin, map_policy)] + + with pytest.raises(e.ParamError): + self.as_connection.operate(self.test_key, operations) + + # Default persist index value should be tested automatically + # from other tests that don't set the persist index option + def test_map_put(self): operations = [map_ops.map_put(self.test_bin, "new", "map_put")] self.as_connection.operate(self.test_key, operations) From d37c0bf4d4024be54afe6c0eb6c4430705fc1e7b Mon Sep 17 00:00:00 2001 From: Julian Nguyen <109386615+juliannguyen4@users.noreply.github.com> Date: Wed, 18 Oct 2023 13:54:33 -0700 Subject: [PATCH 7/7] Remove map_write_mode since it is mutually exclusive with persist_index --- aerospike-stubs/aerospike.pyi | 3 - .../operations/bitwise_operations.py | 2 +- doc/aerospike.rst | 21 ---- doc/client.rst | 18 +-- src/main/policy.c | 50 +++----- test/new_tests/test_batch_get_ops.py | 2 +- .../new_tests/test_inverted_map_operations.py | 2 +- test/new_tests/test_map_operation_helpers.py | 4 +- test/new_tests/test_map_write_flags.py | 2 +- test/new_tests/test_map_write_mode.py | 107 ------------------ .../new_tests/test_relative_cdt_operations.py | 2 +- 11 files changed, 21 insertions(+), 192 deletions(-) delete mode 100644 test/new_tests/test_map_write_mode.py diff --git a/aerospike-stubs/aerospike.pyi b/aerospike-stubs/aerospike.pyi index b5f066213..dbc562c6f 100644 --- a/aerospike-stubs/aerospike.pyi +++ b/aerospike-stubs/aerospike.pyi @@ -93,7 +93,6 @@ LOG_LEVEL_INFO: Literal[2] LOG_LEVEL_OFF: Literal[-1] LOG_LEVEL_TRACE: Literal[4] LOG_LEVEL_WARN: Literal[1] -MAP_CREATE_ONLY: Literal[2] MAP_KEY_ORDERED: Literal[1] MAP_KEY_VALUE_ORDERED: Literal[3] MAP_RETURN_COUNT: Literal[5] @@ -109,8 +108,6 @@ MAP_RETURN_VALUE: Literal[7] MAP_RETURN_ORDERED_MAP: Literal[17] MAP_RETURN_UNORDERED_MAP: Literal[16] MAP_UNORDERED: Literal[0] -MAP_UPDATE: Literal[0] -MAP_UPDATE_ONLY: Literal[1] MAP_WRITE_FLAGS_CREATE_ONLY: Literal[1] MAP_WRITE_FLAGS_DEFAULT: Literal[0] MAP_WRITE_FLAGS_NO_FAIL: Literal[4] diff --git a/aerospike_helpers/operations/bitwise_operations.py b/aerospike_helpers/operations/bitwise_operations.py index f8d018378..320a8547b 100644 --- a/aerospike_helpers/operations/bitwise_operations.py +++ b/aerospike_helpers/operations/bitwise_operations.py @@ -96,7 +96,7 @@ client.remove(key) bit_policy = { - 'map_write_mode': aerospike.BIT_WRITE_DEFAULT, + 'bit_write_flags': aerospike.BIT_WRITE_DEFAULT, } client.put(key, {five_one_bin: five_one_blob}) diff --git a/doc/aerospike.rst b/doc/aerospike.rst index 4cf6a242b..37fb9b4b9 100644 --- a/doc/aerospike.rst +++ b/doc/aerospike.rst @@ -1085,27 +1085,6 @@ Flags used by map write flag. Allow other valid map items to be committed if a map item is denied due to write flag constraints. -.. _aerospike_map_write_mode: - -Map Write Mode -^^^^^^^^^^^^^^ - -Flags used by map *write mode*. - -.. note:: This should only be used for Server version < 4.3.0 - -.. data:: MAP_UPDATE - - Default. Allow create or update. - -.. data:: MAP_CREATE_ONLY - - If the key already exists, the item will be denied. If the key does not exist, a new item will be created. - -.. data:: MAP_UPDATE_ONLY - - If the key already exists, the item will be overwritten. If the key does not exist, the item will be denied. - .. _aerospike_map_order: Map Order diff --git a/doc/client.rst b/doc/client.rst index 197c2614a..4a15e6102 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -2264,21 +2264,11 @@ Map Policies .. object:: policy - A :class:`dict` of optional map policies, which are applicable to map operations. Only one of ``map_write_mode`` or ``map_write_flags`` should - be provided. ``map_write_mode`` should be used for Aerospike Server versions < `4.3.0` and ``map_write_flags`` should be used for Aerospike server versions - greater than or equal to `4.3.0` . + A :class:`dict` of optional map policies, which are applicable to map operations. .. hlist:: :columns: 1 - * **map_write_mode** - | Write mode for the map operation. - | One of the :ref:`aerospike_map_write_mode` values such as :data:`aerospike.MAP_UPDATE` - | - | Default: :data:`aerospike.MAP_UPDATE` - - .. note:: This should only be used for Server version < 4.3.0. - * **map_write_flags** | Write flags for the map operation. | One of the :ref:`aerospike_map_write_flag` values such as :data:`aerospike.MAP_WRITE_FLAGS_DEFAULT` @@ -2311,12 +2301,6 @@ Map Policies 'map_write_flags': aerospike.MAP_WRITE_FLAGS_CREATE_ONLY } - # Server < 4.3.0 - map_policy = { - 'map_order': aerospike.MAP_UNORDERED, - 'map_write_mode': aerospike.MAP_CREATE_ONLY - } - .. _aerospike_bit_policies: Bit Policies diff --git a/src/main/policy.c b/src/main/policy.c index 745eaa35b..07ff2b638 100644 --- a/src/main/policy.c +++ b/src/main/policy.c @@ -219,10 +219,6 @@ static AerospikeConstants aerospike_constants[] = { {AS_MAP_KEY_ORDERED, "MAP_KEY_ORDERED"}, {AS_MAP_KEY_VALUE_ORDERED, "MAP_KEY_VALUE_ORDERED"}, - {AS_MAP_UPDATE, "MAP_UPDATE"}, - {AS_MAP_UPDATE_ONLY, "MAP_UPDATE_ONLY"}, - {AS_MAP_CREATE_ONLY, "MAP_CREATE_ONLY"}, - {AS_MAP_RETURN_NONE, "MAP_RETURN_NONE"}, {AS_MAP_RETURN_INDEX, "MAP_RETURN_INDEX"}, {AS_MAP_RETURN_REVERSE_INDEX, "MAP_RETURN_REVERSE_INDEX"}, @@ -1122,48 +1118,28 @@ as_status pyobject_to_map_policy(as_error *err, PyObject *py_policy, // Initialize Policy POLICY_INIT(as_map_policy); + // Defaults long map_order = AS_MAP_UNORDERED; - long map_write_mode = AS_MAP_UPDATE; uint32_t map_write_flags = AS_MAP_WRITE_DEFAULT; + bool persist_index = false; MAP_POLICY_SET_FIELD(map_order); - PyObject *mode_or_flags = - PyDict_GetItemString(py_policy, MAP_WRITE_FLAGS_KEY); - - /* - This only works for client >= 3.5.0 and server >= 4.3.0 - If py_policy["map_write_flags"] is set, we use it - otherwise we use py_policy["map_write_mode"] - */ - if (mode_or_flags) { - if (PyLong_Check(mode_or_flags)) { - map_write_flags = (uint32_t)PyLong_AsLong(mode_or_flags); - as_map_policy_set_flags(policy, map_order, map_write_flags); - } - else { - as_error_update(err, AEROSPIKE_ERR_PARAM, - "map write flags must be an integer"); - } - return err->code; - } - - MAP_POLICY_SET_FIELD(map_write_mode); + MAP_POLICY_SET_FIELD(map_write_flags); PyObject *py_persist_index = PyDict_GetItemString(py_policy, "persist_index"); - bool persist_index; - if (!py_persist_index) { - // Default value if persist_index isn't set in policy - persist_index = false; - } - else if (!PyBool_Check(py_persist_index)) { - // persist_index value must be valid if it is set - return as_error_update(err, AEROSPIKE_ERR_PARAM, - "persist_index is not a boolean"); + if (py_persist_index) { + if (PyBool_Check(py_persist_index)) { + persist_index = (bool)PyObject_IsTrue(py_persist_index); + } + else { + // persist_index value must be valid if it is set + return as_error_update(err, AEROSPIKE_ERR_PARAM, + "persist_index is not a boolean"); + } } - persist_index = (bool)PyObject_IsTrue(py_persist_index); - as_map_policy_set_all(policy, map_order, map_write_mode, persist_index); + as_map_policy_set_all(policy, map_order, map_write_flags, persist_index); return err->code; } diff --git a/test/new_tests/test_batch_get_ops.py b/test/new_tests/test_batch_get_ops.py index 898103116..a8df01661 100644 --- a/test/new_tests/test_batch_get_ops.py +++ b/test/new_tests/test_batch_get_ops.py @@ -122,7 +122,7 @@ def test_batch_result_output_format(self): # pp = pprint.PrettyPrinter(2, 80) policy = {"key": aerospike.POLICY_KEY_SEND} map_policy = { - "map_write_mode": aerospike.MAP_UPDATE, + "map_write_flags": aerospike.MAP_WRITE_FLAGS_UPDATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED, } diff --git a/test/new_tests/test_inverted_map_operations.py b/test/new_tests/test_inverted_map_operations.py index 93aa95109..d6f6e189b 100644 --- a/test/new_tests/test_inverted_map_operations.py +++ b/test/new_tests/test_inverted_map_operations.py @@ -39,7 +39,7 @@ def maps_have_same_values(map1, map2): def sort_map(client, test_key, test_bin): - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(test_bin, map_policy)] client.operate(test_key, operations) diff --git a/test/new_tests/test_map_operation_helpers.py b/test/new_tests/test_map_operation_helpers.py index d7a3dd3f8..15bc02ddc 100644 --- a/test/new_tests/test_map_operation_helpers.py +++ b/test/new_tests/test_map_operation_helpers.py @@ -39,7 +39,7 @@ def maps_have_same_values(map1, map2): def sort_map(client, test_key, test_bin): - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(test_bin, map_policy)] client.operate(test_key, operations) @@ -80,7 +80,7 @@ def test_map_set_policy(self): Test setting map policy with an operation """ map_policy = { - "map_write_mode": aerospike.MAP_CREATE_ONLY, + "map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_VALUE_ORDERED, "persist_index": True } diff --git a/test/new_tests/test_map_write_flags.py b/test/new_tests/test_map_write_flags.py index 3a50793e7..08572197b 100644 --- a/test/new_tests/test_map_write_flags.py +++ b/test/new_tests/test_map_write_flags.py @@ -90,7 +90,7 @@ def test_update_only_does_not_allow_create(self): map_ops.map_put("map", "new", "new", map_policy=map_policy), ] - with pytest.raises(e.AerospikeError): + with pytest.raises(e.ElementNotFoundError): self.as_connection.operate(key, ops) _, _, bins = self.as_connection.get(key) diff --git a/test/new_tests/test_map_write_mode.py b/test/new_tests/test_map_write_mode.py deleted file mode 100644 index e501b7a86..000000000 --- a/test/new_tests/test_map_write_mode.py +++ /dev/null @@ -1,107 +0,0 @@ -# These fail if we don't have a new server -# -*- coding: utf-8 -*- -import pytest -import aerospike -from aerospike import exception as e -from aerospike_helpers.operations import map_operations as map_ops - - -class TestMapWriteMode(object): - @pytest.fixture(autouse=True) - def setup(self, request, as_connection): - """ - Setup Method - """ - self.keys = [] - - yield - - for key in self.keys: - self.as_connection.remove(key) - - def test_default_allows_update_and_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "new" - assert map_bin["new"] == "new" - - def test_create_only_does_not_allow_update(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - ] - with pytest.raises(e.ElementExistsError): - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - - def test_create_only_allows_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY} - ops = [ - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - self.as_connection.operate(key, ops) - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - assert map_bin["new"] == "new" - - def test_update_only_does_not_allow_create(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE_ONLY} - ops = [ - map_ops.map_put("map", "new", "new", map_policy=map_policy), - ] - - with pytest.raises(e.ElementNotFoundError): - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "old" - assert "new" not in map_bin - - def test_update_only_allows_update(self): - key = "test", "write_mode", 1 - self.keys.append(key) - self.as_connection.put(key, {"map": {"existing": "old"}}) - - map_policy = {"map_write_mode": aerospike.MAP_UPDATE_ONLY} - ops = [ - map_ops.map_put("map", "existing", "new", map_policy=map_policy), - ] - - self.as_connection.operate(key, ops) - - _, _, bins = self.as_connection.get(key) - - map_bin = bins["map"] - assert map_bin["existing"] == "new" diff --git a/test/new_tests/test_relative_cdt_operations.py b/test/new_tests/test_relative_cdt_operations.py index 5f9a2cad4..7a242f5ca 100644 --- a/test/new_tests/test_relative_cdt_operations.py +++ b/test/new_tests/test_relative_cdt_operations.py @@ -261,7 +261,7 @@ def setup(self, request, as_connection): self.test_bin = "map" self.as_connection.put(self.test_key, {self.test_bin: self.test_map}) - map_policy = {"map_write_mode": aerospike.MAP_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} + map_policy = {"map_write_flags": aerospike.MAP_WRITE_FLAGS_CREATE_ONLY, "map_order": aerospike.MAP_KEY_ORDERED} operations = [map_ops.map_set_policy(self.test_bin, map_policy)] self.as_connection.operate(self.test_key, operations) self.keys.append(self.test_key)