Skip to content

Commit

Permalink
Add persist index option in map policy
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannguyen4 committed Oct 18, 2023
1 parent af2abfe commit dad3b56
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/main/policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 17 additions & 1 deletion test/new_tests/test_map_operation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dad3b56

Please sign in to comment.