diff --git a/.github/workflows/smoke-tests.yml b/.github/workflows/smoke-tests.yml index 244bf4a8f3..70d63d7099 100644 --- a/.github/workflows/smoke-tests.yml +++ b/.github/workflows/smoke-tests.yml @@ -136,7 +136,7 @@ jobs: registry-username: ${{ env.REGISTRY_NAME == 'docker.io' && secrets.DOCKER_HUB_BOT_USERNAME || secrets.QE_DOCKER_REGISTRY_USERNAME }} registry-password: ${{ env.REGISTRY_NAME == 'docker.io' && secrets.DOCKER_HUB_BOT_PW || secrets.QE_DOCKER_REGISTRY_PASSWORD }} - - run: python3 -m pytest --cov=aerospike_helpers --cov-report xml:coverage.xml ./new_tests + - run: python3 -m pytest -Werror --cov=aerospike_helpers --cov-report xml:coverage.xml ./new_tests working-directory: test - name: Copy over source files to build dir @@ -306,7 +306,7 @@ jobs: - name: Run tests # We need to disable capturing output or else we cannot see memory errors reported by # libasan during the test run - run: python -m pytest ./new_tests -vvs + run: python -m pytest ./new_tests -vvs -W error::DeprecationWarning working-directory: test test-ce: diff --git a/aerospike_helpers/batch/records.py b/aerospike_helpers/batch/records.py index 99e9f5816e..9682338525 100644 --- a/aerospike_helpers/batch/records.py +++ b/aerospike_helpers/batch/records.py @@ -60,6 +60,8 @@ def __init__(self, key: tuple) -> None: class Write(BatchRecord): """ Write is used for executing Batch write commands with batch_write and retrieving batch write results. + .. include:: ./deprecate_meta_ttl.rst + Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. @@ -111,6 +113,9 @@ def __init__( class Read(BatchRecord): """ Read is used for executing Batch read commands with batch_write and retrieving results. + .. deprecated:: 19.1.0 Deprecated the ``"ttl"`` option in the ``meta`` parameter. Use the policy parameter in a + :py:obj:`~aerospike_helpers.batch.records.Write` BatchRecord to set the ``"ttl"`` instead. + Attributes: key (:obj:`tuple`): The aerospike key to send the command to. record (:obj:`tuple`): The record corresponding to the requested key. diff --git a/aerospike_helpers/operations/operations.py b/aerospike_helpers/operations/operations.py index 95aff57a6b..d147a27ecd 100644 --- a/aerospike_helpers/operations/operations.py +++ b/aerospike_helpers/operations/operations.py @@ -119,18 +119,18 @@ def increment(bin_name, amount): def touch(ttl: Optional[int] = None): """Create a touch operation dictionary. - Using ttl here is deprecated. It should be set in the record metadata for the operate method. + Using ttl here is deprecated. It should be set in the policy parameter for the operate method. Args: ttl (int): Deprecated. The ttl that should be set for the record. - This should be set in the metadata passed to the operate or + This should be set in the policy parameter passed to the operate or operate_ordered methods. Returns: A dictionary to be passed to operate or operate_ordered. """ op_dict = {"op": aerospike.OPERATOR_TOUCH} if ttl: - warnings.warn("TTL should be specified in the meta dictionary for operate", DeprecationWarning) + warnings.warn("TTL should be specified in the policy parameter for operate", DeprecationWarning) op_dict["val"] = ttl return op_dict diff --git a/doc/client.rst b/doc/client.rst index 36e789dfa2..4cb8a79302 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -100,6 +100,8 @@ Record Commands Create a new record, or remove / add bins to a record. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param dict bins: contains bin name-value pairs of the record. :param dict meta: record metadata to be set. see :ref:`metadata_dict`. @@ -181,6 +183,8 @@ Record Commands (In Aerospike server versions prior to 3.6.0, non-existent bins being read will have a \ :py:obj:`None` value. ) + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: See :ref:`aerospike_operation_helpers.operations`. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -207,6 +211,8 @@ Record Commands Write operations or read operations that fail will not return a ``(bin-name, result)`` tuple. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: See :ref:`aerospike_operation_helpers.operations`. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -224,6 +230,10 @@ Record Commands Touch the given record, setting its time-to-live and incrementing its generation. + .. versionchanged:: 19.1.0 + + Deprecated the ``meta["ttl"]`` parameter. Use the ``val`` parameter instead. + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param int val: ttl in seconds, with ``0`` resolving to the default value in the server config. :param dict meta: record metadata to be set. see :ref:`metadata_dict` @@ -238,6 +248,10 @@ Record Commands Remove a record matching the *key* from the cluster. + .. versionchanged:: 19.1.0 + + Deprecated the ``meta`` parameter. Use the policy parameter to set ``gen`` instead. + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param dict meta: contains the expected generation of the record in a key called ``"gen"``. :param dict policy: see :ref:`aerospike_remove_policies`. May be passed as a keyword argument. @@ -252,6 +266,8 @@ Record Commands Remove a list of bins from a record with a given *key*. Equivalent to \ setting those bins to :meth:`aerospike.null` with a :meth:`~aerospike.put`. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` associated with the record. :param list list: the bins names to be removed from the record. :param dict meta: record metadata to be set. See :ref:`metadata_dict`. @@ -408,6 +424,8 @@ String Operations Append a string to the string value in bin. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param str val: the string to append to the bin value. @@ -427,6 +445,8 @@ String Operations Prepend the string value in *bin* with the string *val*. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param str val: the string to prepend to the bin value. @@ -456,6 +476,8 @@ Numeric Operations Increment the integer value in *bin* by the integer *val*. + .. include:: ./deprecate_meta_ttl.rst + :param tuple key: a :ref:`aerospike_key_tuple` tuple associated with the record. :param str bin: the name of the bin. :param int offset: the value by which to increment the value in *bin*. @@ -946,7 +968,7 @@ Index Operations .. method:: index_string_create(ns, set, bin, name[, policy: dict]) - .. deprecated:: 20.0.0 :meth:`index_single_value_create` should be used instead. + .. deprecated:: 19.1.0 :meth:`index_single_value_create` should be used instead. Create a string index with *index_name* on the *bin* in the specified \ *ns*, *set*. @@ -960,7 +982,7 @@ Index Operations .. method:: index_integer_create(ns, set, bin, name[, policy]) - .. deprecated:: 20.0.0 :meth:`index_single_value_create` should be used instead. + .. deprecated:: 19.1.0 :meth:`index_single_value_create` should be used instead. Create an integer index with *name* on the *bin* in the specified \ *ns*, *set*. @@ -974,7 +996,7 @@ Index Operations .. method:: index_blob_create(ns, set, bin, name[, policy]) - .. deprecated:: 20.0.0 :meth:`index_single_value_create` should be used instead. + .. deprecated:: 19.1.0 :meth:`index_single_value_create` should be used instead. Create a blob index with *name* on the *bin* in the specified \ *ns*, *set*. @@ -988,7 +1010,7 @@ Index Operations .. method:: index_geo2dsphere_create(ns, set, bin, name[, policy: dict]) - .. deprecated:: 20.0.0 :meth:`index_single_value_create` should be used instead. + .. deprecated:: 19.1.0 :meth:`index_single_value_create` should be used instead. Create a geospatial 2D spherical index with *name* on the *bin* \ in the specified *ns*, *set*. @@ -1012,23 +1034,23 @@ Index Operations client.index_geo2dsphere_create('test', 'pads', 'loc', 'pads_loc_geo') client.close() -.. method:: index_cdt_create(ns: str, set: str, bin: str, index_type, index_datatype, index_name: str, ctx: list[, policy: dict]) + .. method:: index_cdt_create(ns: str, set: str, bin: str, index_type, index_datatype, index_name: str, ctx: list[, policy: dict]) - .. deprecated:: 20.0.0 Use the other non-deprecated index methods to create an index with a list of contexts. + .. deprecated:: 19.1.0 Use the other non-deprecated index methods to create an index with a list of contexts. - Create an collection data type (CDT) index named *index_name* for a scalar, list values, map keys, or map values (as defined by *index_type*) and for - numeric, string, or GeoJSON values (as defined by *index_datatype*) - on records of the specified *ns*, *set* whose bin is a list or map. + Create an collection data type (CDT) index named *index_name* for a scalar, list values, map keys, or map values (as defined by *index_type*) and for + numeric, string, or GeoJSON values (as defined by *index_datatype*) + on records of the specified *ns*, *set* whose bin is a list or map. - :param str ns: the namespace in the aerospike cluster. - :param str set: the set name. - :param str bin: the name of bin the secondary index is built on. - :param index_type: whether we are querying a single scalar value or specific values of a CDT type. See :ref:`aerospike_index_types`. - :param index_datatype: the type of value being queried on. See :ref:`aerospike_index_datatypes`. - :param str index_name: the name of the index. - :param dict ctx: a :class:`list` of contexts produced by :mod:`aerospike_helpers.cdt_ctx` methods. - :param dict policy: optional :ref:`aerospike_info_policies`. - :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. + :param str ns: the namespace in the aerospike cluster. + :param str set: the set name. + :param str bin: the name of bin the secondary index is built on. + :param index_type: whether we are querying a single scalar value or specific values of a CDT type. See :ref:`aerospike_index_types`. + :param index_datatype: the type of value being queried on. See :ref:`aerospike_index_datatypes`. + :param str index_name: the name of the index. + :param dict ctx: a :class:`list` of contexts produced by :mod:`aerospike_helpers.cdt_ctx` methods. + :param dict policy: optional :ref:`aerospike_info_policies`. + :raises: a subclass of :exc:`~aerospike.exception.AerospikeError`. .. index:: single: Admin Operations diff --git a/doc/deprecate_meta_ttl.rst b/doc/deprecate_meta_ttl.rst new file mode 100644 index 0000000000..907f1cb50c --- /dev/null +++ b/doc/deprecate_meta_ttl.rst @@ -0,0 +1,3 @@ +.. versionchanged:: 19.1.0 + + Deprecated the ``meta["ttl"]`` parameter. Use the policy parameter to set ``ttl`` instead. diff --git a/src/include/client.h b/src/include/client.h index e41ddcc5fd..cd168c57c5 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -25,6 +25,9 @@ #define CLUSTER_NPARTITIONS (4096) +// This allows people to see the function calling the Python client API that issues a warning +#define STACK_LEVEL 2 + /******************************************************************************* * Macros for UDF operations. ******************************************************************************/ diff --git a/src/main/aerospike.c b/src/main/aerospike.c index a094cc3aa4..1e7ac45cd6 100644 --- a/src/main/aerospike.c +++ b/src/main/aerospike.c @@ -661,7 +661,9 @@ DEFINE_SET_OF_VALID_KEYS(client_config_policies, "read", "write", "apply", "batch_parent_write", "info", "admin", "txn_verify", "txn_roll", "total_timeout", "auth_mode", "login_timeout_ms", "key", "exists", "max_retries", - "replica", "commit_level", "metrics", NULL) + "replica", "commit_level", "metrics", "read_mode_ap", + "max_threads", "thread_pool_size", "socket_timeout", + NULL) DEFINE_SET_OF_VALID_KEYS(client_config_tls, "enable", "cafile", "capath", "protocols", "cipher_suite", "keyfile", "keyfile_pw", diff --git a/src/main/client/remove.c b/src/main/client/remove.c index 78162c6001..345d3702a3 100644 --- a/src/main/client/remove.c +++ b/src/main/client/remove.c @@ -169,6 +169,17 @@ PyObject *AerospikeClient_Remove(AerospikeClient *self, PyObject *args, return NULL; } + if (py_meta) { + int retval = PyErr_WarnEx( + PyExc_DeprecationWarning, + "meta parameter is deprecated and will be removed in the " + "next client major release", + STACK_LEVEL); + if (retval == -1) { + return NULL; + } + } + // Invoke Operation return AerospikeClient_Remove_Invoke(self, py_key, py_meta, py_policy); } diff --git a/src/main/client/sec_index.c b/src/main/client/sec_index.c index a0296474d0..e2d96d74a8 100644 --- a/src/main/client/sec_index.c +++ b/src/main/client/sec_index.c @@ -241,9 +241,6 @@ PyObject *AerospikeClient_Index_Expr_Create(AerospikeClient *self, NULL, py_expr); } -// This allows people to see the function calling the Python client API that issues a warning -#define STACK_LEVEL 2 - // TODO: way to get method name dynamically for error message? static inline PyObject * AerospikeClient_Index_Create_Helper(AerospikeClient *self, PyObject *args, @@ -469,10 +466,14 @@ PyObject *AerospikeClient_Index_2dsphere_Create(AerospikeClient *self, PyObject *AerospikeClient_Index_Cdt_Create(AerospikeClient *self, PyObject *args, PyObject *kwds) { - PyErr_WarnEx(PyExc_DeprecationWarning, - "index_cdt_create() is deprecated. Please use one of the " - "other non-deprecated index_*_create() methods instead", - STACK_LEVEL); + int retval = + PyErr_WarnEx(PyExc_DeprecationWarning, + "index_cdt_create() is deprecated. Please use one of the " + "other non-deprecated index_*_create() methods instead", + STACK_LEVEL); + if (retval == -1) { + return NULL; + } // Initialize error as_error err; diff --git a/src/main/conversions.c b/src/main/conversions.c index e869275af0..98a49c277b 100644 --- a/src/main/conversions.c +++ b/src/main/conversions.c @@ -2289,6 +2289,10 @@ void initialize_bin_for_strictypes(AerospikeClient *self, as_error *err, strcpy(binop_bin->name, bin); } +#define META_TTL_DEPRECATION_MESSAGE \ + "meta[\"ttl\"] is deprecated and will be removed in " \ + "the next client major release." + /** ******************************************************************************************************* * This function checks for metadata and if present set it into the @@ -2327,6 +2331,16 @@ as_status check_and_set_meta(PyObject *py_meta, uint32_t *ttl_ref, uint32_t ttl = 0; uint16_t gen = 0; if (py_ttl) { + int retval = + PyErr_WarnEx(PyExc_DeprecationWarning, + META_TTL_DEPRECATION_MESSAGE, STACK_LEVEL); + if (retval == -1) { + // This handles the codepath where warnings are converted into errors from pytest/python cli + // TODO: this does NOT handle the codepath where the warning mechanism itself fails + return as_error_update(err, AEROSPIKE_ERR, + META_TTL_DEPRECATION_MESSAGE); + } + if (PyLong_Check(py_ttl)) { ttl = (uint32_t)PyLong_AsLong(py_ttl); } diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index bf0a4cbbef..6e41bee6bf 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -113,9 +113,10 @@ def test_pos_append_with_policy_key_gen_EQ_ignore(self): key = ("test", "demo", 1) policy = { "gen": aerospike.POLICY_GEN_IGNORE, + "ttl": 1200 } - meta = {"gen": 10, "ttl": 1200} + meta = {"gen": 10} self.as_connection.append(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -135,12 +136,13 @@ def test_pos_append_with_policy_key_gen_EQ_positive(self): key = ("test", "demo", 1) policy = { "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} self.as_connection.append(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -160,11 +162,12 @@ def test_pos_append_with_policy_key_gen_GT_positive(self): key = ("test", "demo", 1) policy = { "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 2, "ttl": 1200} + meta = {"gen": gen + 2} self.as_connection.append(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -294,12 +297,13 @@ def test_neg_append_with_policy_key_gen_GT_lesser(self): key = ("test", "demo", 1) policy = { "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} try: self.as_connection.append(key, "name", "str", meta, policy) except e.RecordGenerationError as exception: @@ -321,11 +325,12 @@ def test_neg_append_with_policy_key_gen_EQ_not_equal(self): key = ("test", "demo", 1) policy = { "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} try: self.as_connection.append(key, "name", "str", meta, policy) diff --git a/test/new_tests/test_batch_write.py b/test/new_tests/test_batch_write.py index ea4c17e7d9..20181d629f 100644 --- a/test/new_tests/test_batch_write.py +++ b/test/new_tests/test_batch_write.py @@ -123,12 +123,13 @@ def teardown(): br.Write( ("test", "demo", 1), [op.write("new", 10), op.read("new")], - meta={"gen": 1, "ttl": aerospike.TTL_NEVER_EXPIRE}, + meta={"gen": 1}, policy={ "key": aerospike.POLICY_KEY_SEND, "commit_level": aerospike.POLICY_COMMIT_LEVEL_MASTER, "gen": aerospike.POLICY_GEN_IGNORE, "exists": aerospike.POLICY_EXISTS_UPDATE, + "ttl": aerospike.TTL_NEVER_EXPIRE, "durable_delete": False, "expressions": exp.Eq(exp.IntBin("count"), 1).compile(), }, @@ -186,9 +187,10 @@ def teardown(): br.Write( ("test", "demo", 1), [op.write("new", 10), op.read("new")], - meta={"gen": 1, "ttl": aerospike.TTL_NEVER_EXPIRE}, + meta={"gen": 1}, policy={ "expressions": exp.Eq(exp.IntBin("count"), 1).compile(), + "ttl": aerospike.TTL_NEVER_EXPIRE }, ) ] diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index b894b3d647..5e851222fe 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -7,6 +7,7 @@ from .index_helpers import ensure_dropped_index from aerospike_helpers import cdt_ctx + list_index = "list_index" list_rank = "list_rank" list_value = "list_value" @@ -53,6 +54,7 @@ def add_ctx_op(ctx_type, value): ctx_map_value.append(add_ctx_op(map_value, 3)) +@pytest.mark.filterwarnings("ignore::DeprecationWarning") class TestCDTIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): diff --git a/test/new_tests/test_client_config_level_options.py b/test/new_tests/test_client_config_level_options.py index f7b7c027e6..138c0d4487 100644 --- a/test/new_tests/test_client_config_level_options.py +++ b/test/new_tests/test_client_config_level_options.py @@ -14,6 +14,7 @@ import re import os from .conftest import verify_record_ttl, wait_for_job_completion +import warnings gconfig = {} gconfig = TestBaseClass.get_connection_config() @@ -293,7 +294,6 @@ def test_query_invalid_expected_duration(): # Some of these options may not be documented, but they are allowed in the code and customers may be using them def test_config_level_misc_options(): config = copy.deepcopy(gconfig) - config["policies"]["socket_timeout"] = 1 config["policies"]["total_timeout"] = 1 config["policies"]["max_retries"] = 1 config["policies"]["exists"] = aerospike.POLICY_EXISTS_CREATE @@ -302,6 +302,7 @@ def test_config_level_misc_options(): config["policies"]["commit_level"] = aerospike.POLICY_COMMIT_LEVEL_ALL config["policies"]["max_threads"] = 16 config["policies"]["thread_pool_size"] = 16 + config["policies"]["socket_timeout"] = 0 config["thread_pool_size"] = 16 config["max_threads"] = 16 config["max_conns_per_node"] = 16 @@ -335,6 +336,8 @@ def test_config_level_misc_options(): # We just make sure that the above options are allowed as dict keys try: aerospike.client(config) + except e.ParamError as exc: + raise exc except: pass @@ -350,7 +353,7 @@ def config_ttl_setup(self, policy_name: str): "ttl": self.NEW_TTL } self.client = aerospike.client(config) - self.client.put(KEY, {"a": "a", "b": "b"}) + self.client.put(KEY, {"a": "a", "b": "b", "c": 1}) if "apply" in policy_name: self.client.udf_put("test_record_udf.lua") @@ -373,90 +376,128 @@ def config_ttl_setup(self, policy_name: str): self.client.close() - @pytest.mark.parametrize("policy_name", ["write"]) - @pytest.mark.parametrize( - "meta", - [None, {"ttl": aerospike.TTL_CLIENT_DEFAULT}, {"gen": 10}], - ids=["no metadata", "metadata with special ttl value", "metadata without ttl"] - ) - @pytest.mark.parametrize("api_method, kwargs", [ - (aerospike.Client.put, {"key": KEY, "bins": {"a": 1}}), - (aerospike.Client.remove_bin, {"key": KEY, "list": ["a"]}), - ]) - def test_setting_write_ttl(self, config_ttl_setup, meta, api_method, kwargs): - api_method(self.client, **kwargs, meta=meta) - verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - - @pytest.mark.parametrize("policy_name", ["operate"]) - @pytest.mark.parametrize( - "meta", - [None, {"ttl": aerospike.TTL_CLIENT_DEFAULT}, {"gen": 10}], - ids=["no metadata", "metadata with special ttl value", "metadata without ttl"] - ) - def test_setting_operate_ttl(self, config_ttl_setup, meta): - ops = [ - operations.write("a", 1) + ttl_param = pytest.mark.parametrize( + "kwargs_with_ttl", + [ + {"meta": None}, + {"meta": {"gen": 10}}, + {"meta": {"ttl": aerospike.TTL_CLIENT_DEFAULT, "gen": 10}}, + {"policy": None}, + # {"policy": {}}, ] - self.client.operate(KEY, ops, meta=meta) - verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) + ) - @pytest.mark.parametrize("policy_name", ["apply"]) - def test_setting_apply_ttl(self, config_ttl_setup): - # Setup - self.client.put(KEY, {"bin": "a"}) + # Don't bother testing for DeprecationWarnings here since running Python with -W error flag can + # cause ClientError to be raised. It's too complicated to check both cases + @pytest.mark.filterwarnings("ignore::DeprecationWarning") + @ttl_param + @pytest.mark.parametrize("api_method, kwargs, policy_name", [ + ( + aerospike.Client.put, + {"key": KEY, "bins": {"a": 1}}, + "write" + ), + ( + aerospike.Client.remove_bin, + {"key": KEY, "list": ["a"]}, + "write" + ), + ( + aerospike.Client.operate, + {"key": KEY, "list": [operations.write("a", 1)]}, "operate" + ), + ( + aerospike.Client.operate_ordered, + {"key": KEY, "list": [operations.write("a", 1)]}, "operate" + ), + ( + aerospike.Client.increment, + {"key": KEY, "bin": "c", "offset": 1}, + "operate" + ), + ( + aerospike.Client.prepend, + {"key": KEY, "bin": "a", "val": "a"}, + "operate" + ), + ( + aerospike.Client.append, + {"key": KEY, "bin": "a", "val": "a"}, + "operate" + ), + ]) + def test_apis_with_meta_parameter(self, config_ttl_setup, api_method, kwargs: dict, kwargs_with_ttl: dict): + kwargs |= kwargs_with_ttl + try: + api_method(self.client, **kwargs) + except e.ClientError as exc: + # ClientError can be raised if the user runs Python with warnings treated as errors. + assert exc.msg == "meta[\"ttl\"] is deprecated and will be removed in the next client major release" - # Call without setting the ttl in the command's apply policy - # Args: bin name, str - self.client.apply(KEY, module="test_record_udf", function="bin_udf_operation_string", args=["bin", "a"]) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) + # Don't bother testing for DeprecationWarnings here since running Python with -W error flag can + # cause ClientError to be raised. It's too complicated to check both cases + @pytest.mark.filterwarnings("ignore::DeprecationWarning") + @ttl_param @pytest.mark.parametrize("policy_name", ["batch_write"]) - @pytest.mark.parametrize( - "meta", - [None, {"ttl": aerospike.TTL_CLIENT_DEFAULT}], - ids=["no metadata", "metadata with special ttl value"] - ) - def test_setting_batch_write_ttl_with_batch_write(self, config_ttl_setup, meta): + def test_batch_write(self, config_ttl_setup, kwargs_with_ttl): ops = [ operations.write("bin", 1) ] batch_records = BatchRecords([ - Write(KEY, ops=ops, meta=meta) + Write(KEY, ops=ops, **kwargs_with_ttl) ]) - brs = self.client.batch_write(batch_records) + try: + brs = self.client.batch_write(batch_records) + except e.ClientError as exc: + assert exc.msg == "meta[\"ttl\"] is deprecated and will be removed in the next client major release" + # assert brs.result == 0 for br in brs.batch_records: assert br.result == 0 verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - @pytest.mark.parametrize("policy_name", ["batch_write"]) @pytest.mark.parametrize( - "ttl", - [None, aerospike.TTL_CLIENT_DEFAULT], + "kwargs", + [ + {}, + {"ttl": None}, + {"ttl": aerospike.TTL_CLIENT_DEFAULT} + ], ) - def test_setting_batch_write_ttl_with_batch_operate(self, config_ttl_setup, ttl): + @pytest.mark.parametrize("policy_name", ["batch_write"]) + def test_apis_with_ttl_parameter(self, config_ttl_setup, kwargs): ops = [ operations.write("bin", 1) ] keys = [KEY] - brs = self.client.batch_operate(keys, ops, ttl=ttl) + brs = self.client.batch_operate(keys, ops, **kwargs) # assert brs.result == 0 for br in brs.batch_records: assert br.result == 0 verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - @pytest.mark.parametrize("policy_name", ["batch_apply"]) - def test_setting_batch_apply_ttl(self, config_ttl_setup): + @pytest.mark.parametrize("api_method, kwargs, policy_name", [ + ( + aerospike.Client.apply, + {"key": KEY}, + "apply", + ), + ( + aerospike.Client.batch_apply, + {"keys": [KEY]}, + "batch_apply", + ), + ]) + def test_apis_with_policy_parameter(self, config_ttl_setup, api_method, kwargs): # Setup self.client.put(KEY, {"bin": "a"}) - # Call without setting the ttl in batch_apply()'s batch apply policy - keys = [ - KEY - ] - self.client.batch_apply(keys, module="test_record_udf", function="bin_udf_operation_string", args=["bin", "a"]) + kwargs |= {"module": "test_record_udf", "function": "bin_udf_operation_string", "args": ["bin", "a"]} + api_method(self.client, **kwargs) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) @pytest.mark.parametrize("policy_name", ["scan"]) @@ -480,7 +521,7 @@ def test_setting_scan_ttl(self, config_ttl_setup): @pytest.mark.parametrize("policy_name", ["write"]) def test_query_client_default_ttl(self, config_ttl_setup): # Setup - self.client.put(KEY, {"bin": "a"}, meta={"ttl": 90}) + self.client.put(KEY, {"bin": "a"}, policy={"ttl": 90}) # Tell scan to use client config's write policy ttl query = self.client.query("test", "demo") diff --git a/test/new_tests/test_command_level_policies.py b/test/new_tests/test_command_level_policies.py index 00e94592a2..a8f2cd213b 100644 --- a/test/new_tests/test_command_level_policies.py +++ b/test/new_tests/test_command_level_policies.py @@ -17,15 +17,25 @@ class CommandLevelTTL: NEW_TTL = 3000 POLICY = {"ttl": NEW_TTL} - def test_write_policy(self): - self.as_connection.put(KEY, bins={"a": 1}, policy=self.POLICY) + meta_and_policy_params = pytest.mark.parametrize( + "kwargs_with_ttl", + [ + {"meta": POLICY}, + {"policy": POLICY}, + ] + ) + + @meta_and_policy_params + def test_write_policy(self, kwargs_with_ttl): + self.as_connection.put(KEY, bins={"a": 1}, **kwargs_with_ttl) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) - def test_operate_policy(self): + @meta_and_policy_params + def test_operate_policy(self, kwargs_with_ttl): ops = [ operations.write(bin_name="a", write_item=1) ] - self.as_connection.operate(KEY, list=ops, policy=self.POLICY) + self.as_connection.operate(KEY, list=ops, **kwargs_with_ttl) verify_record_ttl(self.client, KEY, expected_ttl=self.NEW_TTL) def test_batch_write_policy(self): @@ -51,7 +61,7 @@ class TestReadTouchTTLPercent: @pytest.fixture(autouse=True) def setup(self, as_connection): ttl = 2 - self.as_connection.put(KEY, bins={"a": 1}, meta={"ttl": ttl}) + self.as_connection.put(KEY, bins={"a": 1}, policy={"ttl": ttl}) self.policy = { "read_touch_ttl_percent": 50 } diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index c27038c531..51d06b5ff1 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -68,8 +68,8 @@ def test_pos_exists_with_key_and_policy1(self, key, record, policy, put_data): def test_neg_exists_with_record_expiry(self, put_data): key = ("test", "demo", 30) rec = {"name": "John"} - meta = {"gen": 3, "ttl": 1} - put_data(self.as_connection, key, rec, meta) + meta = {"gen": 3} + put_data(self.as_connection, key, rec, meta, {"ttl": 1}) time.sleep(2) key, meta = self.as_connection.exists(key) diff --git a/test/new_tests/test_expressions_everywhere.py b/test/new_tests/test_expressions_everywhere.py index 2541054d0a..ca36aa7a87 100644 --- a/test/new_tests/test_expressions_everywhere.py +++ b/test/new_tests/test_expressions_everywhere.py @@ -417,7 +417,7 @@ def test_expressions_key_operate_record_void_time(self): for i in range(5): key = "test", "pred_ttl", i - self.as_connection.put(key, {"time": "earlier"}, meta={"ttl": 100}) + self.as_connection.put(key, {"time": "earlier"}, policy={"ttl": 100}) # 150 second range for record TTLs should be enough, we are storing with # Current time + 100s and current time +5000s, so only one of the group should be found @@ -426,7 +426,7 @@ def test_expressions_key_operate_record_void_time(self): for i in range(5, 10): key = "test", "pred_ttl", i - self.as_connection.put(key, {"time": "later"}, meta={"ttl": 1000}) + self.as_connection.put(key, {"time": "later"}, policy={"ttl": 1000}) results = [] @@ -578,7 +578,7 @@ def test_pos_remove_with_expressions(self): Call remove with expressions in policy. """ expr = exp.Eq(exp.IntBin("account_id"), 1) - self.as_connection.remove(self.keys[0], {"expressions": expr.compile()}) + self.as_connection.remove(self.keys[0], policy={"expressions": expr.compile()}) rec = self.as_connection.exists(self.keys[0]) assert rec[1] is None diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 628078a5bd..b601be6d3c 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -14,6 +14,7 @@ import aerospike from aerospike import exception as e +import warnings @contextmanager @@ -256,24 +257,27 @@ def test_pos_put_with_policy_exists_create_or_replace(self): key = ("test", "demo", 1) rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_CREATE_OR_REPLACE, "gen": aerospike.POLICY_GEN_IGNORE, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } + assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) assert rec == bins rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_CREATE_OR_REPLACE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -288,12 +292,13 @@ def test_pos_put_with_policy_exists_ignore_create(self): key = ("test", "demo", 1) rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_IGNORE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -309,12 +314,13 @@ def test_pos_put_with_policy_exists_ignore_update(self): key = ("test", "demo", 1) rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_IGNORE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -324,12 +330,13 @@ def test_pos_put_with_policy_exists_ignore_update(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_IGNORE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -344,11 +351,12 @@ def test_pos_put_with_policy_replace(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -357,8 +365,8 @@ def test_pos_put_with_policy_replace(self): assert rec == bins rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} - policy = {"exists": aerospike.POLICY_EXISTS_REPLACE} + meta = {"gen": 2} + policy = {"exists": aerospike.POLICY_EXISTS_REPLACE, "ttl": 25000} assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -373,11 +381,12 @@ def test_pos_put_with_policy_exists_update_positive(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -386,8 +395,8 @@ def test_pos_put_with_policy_exists_update_positive(self): assert rec == bins rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} - policy = {"exists": aerospike.POLICY_EXISTS_UPDATE} + meta = {"gen": 2} + policy = {"exists": aerospike.POLICY_EXISTS_UPDATE, "ttl": 25000} assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -401,8 +410,8 @@ def test_pos_put_with_policy_gen_GT(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} - policy = {} + meta = {"gen": 2} + policy = {"ttl": 25000} assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -427,8 +436,8 @@ def test_pos_put_with_policy_gen_ignore(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} - policy = {} + meta = {"gen": 2} + policy = {"ttl": 25000} assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -447,28 +456,28 @@ def test_pos_put_with_policy_gen_ignore(self): self.as_connection.remove(key) @pytest.mark.parametrize( - "key, record, meta", + "key, record, meta, policy", [ - (("test", "demo", 1), {"name": "john"}, {"gen": True, "ttl": 25000}), - (("test", "demo", 1), {"name": "john"}, {"gen": 3, "ttl": True}), - (("test", "demo", 1), {"name": "john"}, {"gen": True, "ttl": True}), + (("test", "demo", 1), {"name": "john"}, {"gen": True}, {"ttl": 25000}), + (("test", "demo", 1), {"name": "john"}, {"gen": 3}, {"ttl": True}), + (("test", "demo", 1), {"name": "john"}, {"gen": True}, {"ttl": True}), ( ("test", "demo", 1), {"name": "john"}, - {"gen": True, "ttl": aerospike.TTL_NAMESPACE_DEFAULT}, + {"gen": True}, {"ttl": aerospike.TTL_NAMESPACE_DEFAULT} ), ( ("test", "demo", 1), {"name": "john"}, - {"gen": True, "ttl": aerospike.TTL_NEVER_EXPIRE}, + {"gen": True}, {"ttl": aerospike.TTL_NEVER_EXPIRE} ), ], ) - def test_pos_put_with_metadata_bool(self, key, record, meta, put_data): + def test_pos_put_with_metadata_bool(self, key, record, meta, policy, put_data): """ Invoke put() for a record with generation as boolean. """ - put_data(self.as_connection, key, record, meta) + put_data(self.as_connection, key, record, meta, policy) (key, meta, bins) = self.as_connection.get(key) assert bins == record @@ -569,8 +578,8 @@ def test_neg_put_with_policy_gen_EQ_less(self): key = ("test", "demo", "policy_gen_EQ_key") rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} - policy = {} + meta = {"gen": 2} + policy = {"ttl": 25000} assert 0 == self.as_connection.put(key, rec, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -595,8 +604,8 @@ def test_neg_put_with_policy_gen_EQ_more(self): key = ("test", "demo", "policy_gen_EQ_more_key") rec = {"name": "John"} - meta = {"gen": 10, "ttl": 25000} - assert 0 == self.as_connection.put(key, rec, meta) + meta = {"gen": 10} + assert 0 == self.as_connection.put(key, rec, meta, policy={"ttl": 25000}) (key, meta, bins) = self.as_connection.get(key) @@ -620,11 +629,12 @@ def test_neg_put_with_policy_exists_create(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -651,12 +661,13 @@ def test_neg_put_with_policy_exists_replace_negative(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_REPLACE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } with pytest.raises(e.RecordNotFound): assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -668,8 +679,8 @@ def test_neg_put_with_policy_replace(self): key = ("test", "demo", 1) rec = {"name": "Smith"} - meta = {"gen": 2, "ttl": 25000} - policy = {"exists": aerospike.POLICY_EXISTS_REPLACE} + meta = {"gen": 2} + policy = {"exists": aerospike.POLICY_EXISTS_REPLACE, "ttl": 25000} with pytest.raises(e.RecordNotFound): self.as_connection.put(key, rec, meta, policy) @@ -681,12 +692,13 @@ def test_neg_put_with_policy_exists_update_negative(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} + meta = {"gen": 2} policy = { "exists": aerospike.POLICY_EXISTS_UPDATE, "gen": aerospike.POLICY_GEN_IGNORE, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, + "ttl": 25000 } try: assert 0 == self.as_connection.put(key, rec, meta, policy) @@ -702,8 +714,8 @@ def test_neg_put_with_policy_gen_GT_lesser(self): key = ("test", "demo", 1) rec = {"name": "John"} - meta = {"gen": 2, "ttl": 25000} - assert 0 == self.as_connection.put(key, rec, meta) + meta = {"gen": 2} + assert 0 == self.as_connection.put(key, rec, meta, policy={"ttl": 25000}) (key, meta, bins) = self.as_connection.get(key) @@ -747,7 +759,7 @@ def test_neg_put_with_string_record_without_connection(self): ( ("test", "demo", 1), {"name": "john"}, - {"gen": "wrong", "ttl": 25000}, + {"gen": "wrong"}, None, -2, "Generation should be an int or long", @@ -755,23 +767,23 @@ def test_neg_put_with_string_record_without_connection(self): ( ("test", "demo", 1), {"name": "john"}, - {"gen": 3, "ttl": "25000"}, - None, + {"gen": 3}, + {"ttl": "25000"}, -2, "TTL should be an int or long", ), ( ("test", "demo", 1), {"name": "john"}, - {"gen": 3, "ttl": 25000}, - {"total_timeout": 0.5}, + {"gen": 3}, + {"total_timeout": 0.5, "ttl": 25000}, -2, "timeout is invalid", ), ( ("test", "demo", 1), {"name": "john"}, # Policy as string - {"gen": 3, "ttl": 25000}, + {"gen": 3}, "Policy", -2, "policy must be a dict", diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 1f6e71acae..7fb75c26b4 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -124,9 +124,10 @@ def test_increment_with_policy_key_gen_EQ_ignore(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_IGNORE, + "ttl": 1200 } - meta = {"gen": 10, "ttl": 1200} + meta = {"gen": 10} self.as_connection.increment(key, "age", 5, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -148,11 +149,12 @@ def test_increment_with_policy_key_gen_EQ_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} self.as_connection.increment(key, "age", 5, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -174,11 +176,12 @@ def test_increment_with_policy_key_gen_EQ_not_equal(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} # Since the generations are not equal, this should raise an error # And not increment. @@ -202,11 +205,12 @@ def test_increment_with_policy_key_gen_GT_lesser(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} # since gen is equal to the server version, this should raise an error with pytest.raises(e.RecordGenerationError) as err_info: self.as_connection.increment(key, "age", 5, meta, policy) @@ -228,11 +232,12 @@ def test_increment_with_policy_key_gen_GT_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} self.as_connection.increment(key, "age", 5, meta, policy) (key, meta, bins) = self.as_connection.get(key) diff --git a/test/new_tests/test_index_deprecated.py b/test/new_tests/test_index_deprecated.py index a5de8d5aac..46a5a7d906 100644 --- a/test/new_tests/test_index_deprecated.py +++ b/test/new_tests/test_index_deprecated.py @@ -16,8 +16,6 @@ class TestDeprecatedIndexCreationMethods: ] ) def test_deprecated_index_creation_methods(self, index_create_method): - with warnings.catch_warnings(record=True) as w: - warnings.simplefilter(action="always", category=DeprecationWarning) + with pytest.warns(DeprecationWarning): with pytest.raises(e.ParamError): index_create_method(self.as_connection, 1, "demo", "bin_name", "deprecated_index") - assert len(w) == 1 diff --git a/test/new_tests/test_log.py b/test/new_tests/test_log.py index 0a222eef80..554cefcc79 100644 --- a/test/new_tests/test_log.py +++ b/test/new_tests/test_log.py @@ -13,7 +13,7 @@ def custom_log_callback(level, func, path, line, msg): callback_called = True class TestLog(object): - @pytest.mark.fixture(autouse=True) + @pytest.fixture(autouse=True) def setup(self): global callback_called callback_called = False diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index 3c5a9550b8..491ac091aa 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -282,8 +282,9 @@ def test_pos_operate_with_policy_key_digest(self): "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, "commit_level": aerospike.POLICY_COMMIT_LEVEL_ALL, + "ttl": 1200 }, - {"gen": 10, "ttl": 1200}, + {"gen": 10}, [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, @@ -312,10 +313,10 @@ def test_pos_operate_with_policy_gen_EQ(self): Invoke operate() with gen EQ positive. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, @@ -358,11 +359,11 @@ def test_pos_operate_with_policy_gen_EQ_not_equal(self): Invoke operate() with gen not equal. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, @@ -388,10 +389,10 @@ def test_pos_operate_with_policy_gen_GT_lesser(self): Invoke operate() with gen GT lesser. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, @@ -416,16 +417,16 @@ def test_pos_operate_with_policy_gen_GT_lesser(self): def test_pos_operate_touch_with_meta(self): """ - Invoke operate() OPERATE_TOUCH using meta to pass in ttl. + Invoke operate() OPERATE_TOUCH using policy to pass in ttl. """ key = ("test", "demo", 1) (key, _) = self.as_connection.exists(key) - meta = {"ttl": 1200} + policy = {"ttl": 1200} llist = [{"op": aerospike.OPERATOR_TOUCH}] try: - (key, meta, _) = self.as_connection.operate(key, llist, meta) + (key, meta, _) = self.as_connection.operate(key, llist, policy=policy) except e.RecordGenerationError as exception: assert exception.code == 3 @@ -440,10 +441,10 @@ def test_pos_operate_with_policy_gen_GT(self): Invoke operate() with gen GT positive. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index d61a2e2a28..e8b524008c 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -5,6 +5,7 @@ import aerospike from aerospike import exception as e +import warnings # OPERATIONS # aerospike.OPERATOR_WRITE @@ -279,8 +280,9 @@ def test_pos_operate_with_correct_policy(self): "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, "commit_level": aerospike.POLICY_COMMIT_LEVEL_ALL, + "ttl": 1200 }, - {"gen": 10, "ttl": 1200}, + {"gen": 10}, [operations.append("name", "aa"), operations.increment("age", 3), operations.read("name")], ), ], @@ -310,14 +312,20 @@ def test_pos_operate_with_policy_gen_EQ(self): assert bins == {"name": "name1aa"} @pytest.mark.parametrize( - "key, llist", [(("test", "demo", 1), [operations.touch(4000)]), (("test", "demo", 1), [operations.touch(4000)])] + "key", [ + ("test", "demo", 1) + ] ) - def test_pos_operate_touch_operation_with_bin_and_value_combination(self, key, llist): + def test_pos_operate_touch_operation_with_bin_and_value_combination(self, key): """ Invoke operate() with touch value with bin and value combination. """ - self.as_connection.operate(key, llist) + with pytest.warns(DeprecationWarning): + ops = [ + operations.touch(4000) + ] + self.as_connection.operate(key, ops) (key, meta) = self.as_connection.exists(key) @@ -371,11 +379,11 @@ def test_pos_operate_touch_with_meta(self): Invoke operate() OPERATE_TOUCH using meta to pass in ttl. """ key = ("test", "demo", 1) - meta = {"ttl": 1200} + policy = {"ttl": 1200} llist = [operations.touch()] - self.as_connection.operate(key, llist, meta) + self.as_connection.operate(key, llist, policy=policy) _, meta = self.as_connection.exists(key) diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index 67a10299b0..33582d6080 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -5,6 +5,7 @@ import aerospike from aerospike import exception as e from aerospike_helpers.operations import operations +import warnings class TestOperateOrdered(object): @@ -208,8 +209,9 @@ def test_pos_operate_ordered_with_policy_key_digest(self): "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, "commit_level": aerospike.POLICY_COMMIT_LEVEL_ALL, + "ttl": 1200 }, - {"gen": 10, "ttl": 1200}, + {"gen": 10}, [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, @@ -231,10 +233,10 @@ def test_pos_operate_ordered_with_policy_gen_GT(self): Invoke operate_ordered() with gen GT positive. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, @@ -594,11 +596,11 @@ def test_neg_operate_ordered_with_policy_gen_EQ_not_equal(self): Invoke operate_ordered() with gen not equal. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, @@ -624,10 +626,10 @@ def test_neg_operate_ordered_with_policy_gen_GT_lesser(self): Invoke operate_ordered() with gen GT lesser. """ key = ("test", "demo", 1) - policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT} + policy = {"key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, "ttl": 1200} (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} llist = [ {"op": aerospike.OPERATOR_APPEND, "bin": "name", "val": "aa"}, diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index e6bfb08e9a..5fa4fdae2c 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -98,9 +98,10 @@ def test_pos_prepend_with_policy_key_gen_EQ_ignore(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_IGNORE, + "ttl": 1200 } - meta = {"gen": 10, "ttl": 1200} + meta = {"gen": 10} self.as_connection.prepend(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -122,11 +123,12 @@ def test_pos_prepend_with_policy_key_gen_EQ_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} self.as_connection.prepend(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -148,11 +150,12 @@ def test_pos_prepend_with_policy_key_gen_GT_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 2, "ttl": 1200} + meta = {"gen": gen + 2} self.as_connection.prepend(key, "name", "str", meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -297,11 +300,12 @@ def test_neg_prepend_with_policy_key_gen_EQ_not_equal(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} try: self.as_connection.prepend(key, "name", "str", meta, policy) @@ -328,11 +332,12 @@ def test_neg_prepend_with_policy_key_gen_GT_lesser(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} try: self.as_connection.prepend(key, "name", "str", meta, policy) diff --git a/test/new_tests/test_query_expressions.py b/test/new_tests/test_query_expressions.py index 98698afee6..6ac96c4ae6 100644 --- a/test/new_tests/test_query_expressions.py +++ b/test/new_tests/test_query_expressions.py @@ -328,7 +328,7 @@ def test_rec_void_time(self): """ for i in range(7): key = "test", "ttl", i - self.as_connection.put(key, {"time": "earlier"}, meta={"ttl": 100}) + self.as_connection.put(key, {"time": "earlier"}, policy={"ttl": 100}) # 150 second range for record TTLs should be enough, we are storing with # Current time + 100s and current time +5000s, so only one of the group should be found @@ -338,7 +338,7 @@ def test_rec_void_time(self): # Store 5 records after the cutoff for i in range(7, 12): key = "test", "ttl", i - self.as_connection.put(key, {"time": "later"}, meta={"ttl": 1000}) + self.as_connection.put(key, {"time": "later"}, policy={"ttl": 1000}) query = self.as_connection.query("test", "ttl") diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index c0ed09126e..876dcf2d09 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -6,12 +6,21 @@ from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e +from contextlib import nullcontext +import warnings @pytest.mark.usefixtures("as_connection") class TestRemove: - @pytest.mark.xfail(reason="open bug #client-533") - def test_pos_remove_with_existing_record(self): + @pytest.fixture + def setup_for_pos_tests(self): + key = ("test", "demo", 1) + bins = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} + self.as_connection.put(key, bins=bins) + + yield + + def test_pos_remove_with_existing_record(self, setup_for_pos_tests): """ Invoke remove() when records are present """ @@ -23,116 +32,105 @@ def test_pos_remove_with_existing_record(self): with pytest.raises(e.RecordNotFound) as exception: (key, _, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - @pytest.mark.xfail(reason="open bug #client-533") - def test_pos_remove_with_policy(self): + @pytest.mark.parametrize( + "kwargs", + [ + {"meta": {"gen": 0}}, + {"policy": {"generation": 0, "total_timeout": 180000}}, + ] + ) + def test_pos_remove_with_policy(self, setup_for_pos_tests, kwargs): """ Invoke remove() with policy """ key = ("test", "demo", 1) - meta = {"gen": 0} - policy = {"total_timeout": 180000} - retobj = self.as_connection.remove(key, meta, policy) + if "meta" in kwargs: + cm = pytest.warns(DeprecationWarning) + else: + cm = nullcontext() + + with cm: + retobj = self.as_connection.remove(key, **kwargs) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - key = ("test", "demo", 1) - rec = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} - self.as_connection.put(key, rec) - - @pytest.mark.xfail(reason="open bug #client-533") - def test_pos_remove_with_policy_all(self): + def test_pos_remove_with_policy_all(self, setup_for_pos_tests): """ Invoke remove() with policy """ key = ("test", "demo", 1) - meta = {"gen": 0} policy = { "total_timeout": 180000, "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, + "generation": 0 } - retobj = self.as_connection.remove(key, meta, policy) + retobj = self.as_connection.remove(key, policy=policy) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - key = ("test", "demo", 1) - rec = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} - self.as_connection.put(key, rec) - - @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_policy_key_digest(self): """ Invoke remove() with policy_key_digest """ key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) - meta = {"gen": 0} policy = {"max_retries": 1, "key": aerospike.POLICY_KEY_DIGEST} retobj = self.as_connection.put(key, policy) assert retobj == 0 - retobj = self.as_connection.remove(key, meta, policy) + policy["generation"] = 0 + retobj = self.as_connection.remove(key, policy=policy) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - @pytest.mark.xfail(reason="open bug #client-533") - def test_pos_remove_with_policy_gen_ignore(self): + def test_pos_remove_with_policy_gen_ignore(self, setup_for_pos_tests): """ Invoke remove() with policy gen ignore """ key = ("test", "demo", 1) - meta = {"gen": 0} policy = { "max_retries": 1, + "generation": 0, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, } - retobj = self.as_connection.remove(key, meta, policy) + retobj = self.as_connection.remove(key, policy=policy) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - key = ("test", "demo", 1) - rec = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} - self.as_connection.put(key, rec) - - @pytest.mark.xfail(reason="Issue1 : open bug #client-533") - def test_pos_remove_with_policy_gen_eq_positive(self): + def test_pos_remove_with_policy_gen_eq_positive(self, setup_for_pos_tests): """ Invoke remove() with policy gen positive """ @@ -144,24 +142,17 @@ def test_pos_remove_with_policy_gen_eq_positive(self): } (key, meta) = self.as_connection.exists(key) - gen = meta["gen"] - meta = {"gen": gen} - retobj = self.as_connection.remove(key, meta, policy) + policy["generation"] = meta["gen"] + retobj = self.as_connection.remove(key, policy=policy) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - key = ("test", "demo", 1) - rec = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} - self.as_connection.put(key, rec) - - @pytest.mark.xfail(reason="open bug #client-533") - def test_pos_remove_with_policy_gen_GT_positive(self): + def test_pos_remove_with_policy_gen_GT_positive(self, setup_for_pos_tests): """ Invoke remove() with policy gen GT positive """ @@ -174,22 +165,17 @@ def test_pos_remove_with_policy_gen_GT_positive(self): (key, meta) = self.as_connection.exists(key) gen = meta["gen"] + 5 - metadata = {"gen": gen} + policy["generation"] = gen - retobj = self.as_connection.remove(key, metadata, policy) + retobj = self.as_connection.remove(key, policy=policy) assert retobj == 0 with pytest.raises(e.RecordNotFound) as exception: (key, meta, _) = self.as_connection.get(key) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_NOT_FOUND" + (code, msg, _, _, _) = exception.value.args assert code == 2 - key = ("test", "demo", 1) - rec = {"name": "name%s" % (str(1)), "addr": "name%s" % (str(1)), "age": 1, "no": 1} - self.as_connection.put(key, rec) - # Negative Tests def test_neg_remove_with_policy_gen_eq_not_equal(self, put_data): """ @@ -208,12 +194,11 @@ def test_neg_remove_with_policy_gen_eq_not_equal(self, put_data): } (key, meta) = self.as_connection.exists(key) - gen = meta["gen"] + 5 # Increment Generation by 5 + policy["generation"] = meta["gen"] + 5 # Increment Generation by 5 with pytest.raises(e.RecordGenerationError) as exception: - self.as_connection.remove(key, {"gen": gen}, policy) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" + self.as_connection.remove(key, policy=policy) + (code, msg, _, _, _) = exception.value.args assert code == 3 def test_neg_remove_with_policy_gen_GT_lesser(self, put_data): @@ -230,12 +215,11 @@ def test_neg_remove_with_policy_gen_GT_lesser(self, put_data): } (key, meta) = self.as_connection.exists(key) - lesserGen = meta["gen"] - 1 + policy["generation"] = meta["gen"] - 1 with pytest.raises(e.RecordGenerationError) as exception: - self.as_connection.remove(key, ("gen", lesserGen), policy) - (code, msg, _, _) = exception.value - assert msg == "AEROSPIKE_ERR_RECORD_GENERATION" + self.as_connection.remove(key, policy=policy) + (code, msg, _, _, _) = exception.value.args assert code == 3 (key, meta, bins) = self.as_connection.get(key) @@ -249,11 +233,9 @@ def test_neg_remove_with_policy_as_string(self): Invoke remove() with policy as string """ key = ("test", "demo", 1) - meta = {"gen": 0} with pytest.raises(e.ParamError) as exception: - self.as_connection.remove(key, meta, "String_policy") - (code, msg, _, _) = exception.value - assert msg == "policy must be a dict" + self.as_connection.remove(key, policy="String_policy") + (code, msg, _, _, _) = exception.value.args assert code == -2 def test_neg_remove_with_extra_parameter(self): @@ -275,8 +257,7 @@ def test_neg_remove_with_incorrect_data(self, key, ex_code, ex_msg): with pytest.raises(e.ParamError) as exception: self.as_connection.remove(key) - (code, msg, _, _) = exception.value - assert msg == ex_msg + (code, msg, _, _, _) = exception.value.args assert code == ex_code @pytest.mark.parametrize( @@ -293,7 +274,7 @@ def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): """ with pytest.raises(ex_name) as exception: self.as_connection.remove(key) - (code, _, _, _) = exception.value + (code, _, _, _) = exception.value.args assert code == ex_code def test_neg_remove_with_correct_parameters_without_connection(self): @@ -307,7 +288,7 @@ def test_neg_remove_with_correct_parameters_without_connection(self): with pytest.raises(e.ClusterError) as exception: client1.remove(key) - (code, _, _, _) = exception.value + (code, _, _, _) = exception.value.args assert code == 11 def test_neg_remove_with_no_parameters(self): diff --git a/test/new_tests/test_remove_bin.py b/test/new_tests/test_remove_bin.py index 6714f053f7..21f44fe582 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -53,8 +53,9 @@ def test_pos_remove_bin_with_policy_send_gen_ignore(self, put_data): "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_IGNORE, + "ttl": 1000 } - meta = {"gen": 2, "ttl": 1000} + meta = {"gen": 2} self.as_connection.remove_bin(key, ["age"], meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -73,11 +74,12 @@ def test_pos_remove_bin_with_policy_send_gen_eq_positive(self, put_data): "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1000 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1000} + meta = {"gen": gen} self.as_connection.remove_bin(key, ["years"], meta, policy) @@ -176,6 +178,7 @@ def test_pos_remove_bin_with_unicode_all(self, key, record, bins_for_removal, pu "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "commit_level": aerospike.POLICY_COMMIT_LEVEL_ALL, + "ttl": 1000 }, "age", ), @@ -186,6 +189,7 @@ def test_pos_remove_bin_with_unicode_all(self, key, record, bins_for_removal, pu "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "commit_level": aerospike.POLICY_COMMIT_LEVEL_MASTER, + "ttl": 1000 }, "age", ), @@ -196,6 +200,7 @@ def test_pos_remove_bin_with_unicode_all(self, key, record, bins_for_removal, pu "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1000 }, "age", ), @@ -210,7 +215,7 @@ def test_pos_remove_bin_with_policy(self, key, record, policy, bin_for_removal, put_data(self.as_connection, key, record) (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1000} + meta = {"gen": gen + 5} self.as_connection.remove_bin(key, [bin_for_removal], meta, policy) @@ -304,10 +309,11 @@ def test_neg_remove_bin_with_policy_send_gen_eq_not_equal(self, put_data): "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1000 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1000} + meta = {"gen": gen + 5} try: self.as_connection.remove_bin(key, ["age"], meta, policy) @@ -336,11 +342,12 @@ def test_neg_remove_bin_with_policy_send_gen_GT_lesser(self, put_data): "max_retries": 1, "key": aerospike.POLICY_KEY_SEND, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1000 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1000} + meta = {"gen": gen} try: self.as_connection.remove_bin(key, ["age"], meta, policy) diff --git a/test/new_tests/test_scan_execute_background.py b/test/new_tests/test_scan_execute_background.py index ef3158195e..3918254bcd 100644 --- a/test/new_tests/test_scan_execute_background.py +++ b/test/new_tests/test_scan_execute_background.py @@ -54,10 +54,10 @@ def teardown(): drop_test_udf(self.as_connection) keys = [(TEST_NS, TEST_SET, i) for i in range(50)] for i, key in enumerate(keys): - self.as_connection.remove(key, {"number": i}) + self.as_connection.remove(key) keys = [(TEST_NS, TEST_SET2, i) for i in range(10)] for i, key in enumerate(keys): - self.as_connection.remove(key, {"number": i}) + self.as_connection.remove(key) request.addfinalizer(teardown) diff --git a/test/new_tests/test_touch.py b/test/new_tests/test_touch.py index b000351c50..d76b182617 100644 --- a/test/new_tests/test_touch.py +++ b/test/new_tests/test_touch.py @@ -101,10 +101,10 @@ def test_touch_with_policy_key_gen_EQ_ignore(self): policy = { "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, - "gen": aerospike.POLICY_GEN_IGNORE, + "gen": aerospike.POLICY_GEN_IGNORE } - meta = {"gen": 10, "ttl": 1200} + meta = {"gen": 10} self.as_connection.touch(key, 120, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -121,11 +121,12 @@ def test_touch_with_policy_key_gen_EQ_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} self.as_connection.touch(key, 120, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -142,8 +143,9 @@ def test_touch_with_policy_key_gen_EQ_not_equal(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_EQ, + "ttl": 1200 } - meta = {"gen": 10, "ttl": 1200} + meta = {"gen": 10} with pytest.raises(e.RecordGenerationError) as err_info: self.as_connection.touch(key, 120, meta, policy) @@ -165,11 +167,12 @@ def test_touch_with_policy_key_gen_GT_lesser(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen, "ttl": 1200} + meta = {"gen": gen} with pytest.raises(e.RecordGenerationError) as err_info: self.as_connection.touch(key, 120, meta, policy) @@ -190,11 +193,12 @@ def test_touch_with_policy_key_gen_GT_positive(self): "key": aerospike.POLICY_KEY_SEND, "max_retries": 1, "gen": aerospike.POLICY_GEN_GT, + "ttl": 1200 } (key, meta) = self.as_connection.exists(key) gen = meta["gen"] - meta = {"gen": gen + 5, "ttl": 1200} + meta = {"gen": gen + 5} self.as_connection.touch(key, 120, meta, policy) (key, meta, bins) = self.as_connection.get(key) @@ -278,9 +282,9 @@ def test_touch_withttlvalue_greaterthan_maxsize(self): Invoke touch() with ttl value greater than (2^63-1) """ key = ("test", "demo", 1) - meta = {"gen": 10, "ttl": 2**64} - with pytest.raises(e.ParamError) as err_info: - self.as_connection.touch(key, 120, meta, None) + meta = {"gen": 10} + with pytest.raises(e.ClientError) as err_info: + self.as_connection.touch(key, 120, meta, {"ttl": 2**64}) err_code = err_info.value.code - assert err_code == AerospikeStatus.AEROSPIKE_ERR_PARAM + assert err_code == AerospikeStatus.AEROSPIKE_ERR_CLIENT diff --git a/test/new_tests/test_validate_keys.py b/test/new_tests/test_validate_keys.py index 9c9959f04a..c7b56e10fc 100644 --- a/test/new_tests/test_validate_keys.py +++ b/test/new_tests/test_validate_keys.py @@ -120,7 +120,7 @@ def test_invalid_metadata_dictionary_key(self): else: context = nullcontext() - meta = {"ttl": 30, INVALID_METADATA_KEY: 1} + meta = {INVALID_METADATA_KEY: 1} with context as excinfo: self.as_connection.put(key=KEY, bins={"a": 1}, meta=meta)