From b49299a22d7a8388cd751644900a62fe85690fed Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Tue, 4 Oct 2022 19:16:55 +0530 Subject: [PATCH 01/27] establish connection while constructing client object, passthrough connect/close calls --- src/include/client.h | 2 + src/main/client/close.c | 59 +++------- src/main/client/connect.c | 238 +++++++++++++++++++++----------------- src/main/client/type.c | 222 +++++++++++++++++++++++++++++------ test/test_cases.py | 2 + 5 files changed, 343 insertions(+), 180 deletions(-) diff --git a/src/include/client.h b/src/include/client.h index 0605df9d2..83899d6ca 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -50,6 +50,8 @@ AerospikeClient *AerospikeClient_New(PyObject *self, PyObject *args, /** * Connect to the database. */ +PyObject *AerospikeClientConnect(AerospikeClient *self); + PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, PyObject *kwds); diff --git a/src/main/client/close.c b/src/main/client/close.c index 4ce5f30ae..f2f7aa277 100644 --- a/src/main/client/close.c +++ b/src/main/client/close.c @@ -43,47 +43,24 @@ PyObject *AerospikeClient_Close(AerospikeClient *self, PyObject *args, PyObject *kwds) { - as_error err; - char *alias_to_search = NULL; - PyObject *py_persistent_item = NULL; - AerospikeGlobalHosts *global_host = NULL; - - // Initialize error - as_error_init(&err); - - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - goto CLEANUP; - } - - if (self->use_shared_connection) { - alias_to_search = return_search_string(self->as); - py_persistent_item = - PyDict_GetItemString(py_global_hosts, alias_to_search); - - if (py_persistent_item) { - global_host = (AerospikeGlobalHosts *)py_persistent_item; - // It is only safe to do a reference counted close if the - // local as is pointing to the global as - if (self->as == global_host->as) { - close_aerospike_object(self->as, &err, alias_to_search, - py_persistent_item, false); - } - } - - PyMem_Free(alias_to_search); - alias_to_search = NULL; - } - else { - Py_BEGIN_ALLOW_THREADS - aerospike_close(self->as, &err); - Py_END_ALLOW_THREADS - } - self->is_conn_16 = false; + as_error err; + char *alias_to_search = NULL; + PyObject *py_persistent_item = NULL; + AerospikeGlobalHosts *global_host = NULL; + + // Initialize error + as_error_init(&err); + + if (!self || !self->as) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); + goto CLEANUP; + } + + if (!self->has_connected) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, + "Invalid aerospike client configuration"); + goto CLEANUP; + } CLEANUP: if (err.code != AEROSPIKE_OK) { diff --git a/src/main/client/connect.c b/src/main/client/connect.c index 16e539a4e..329550750 100644 --- a/src/main/client/connect.c +++ b/src/main/client/connect.c @@ -30,122 +30,104 @@ * Establishes a connection to the Aerospike DB instance. * * @param self AerospikeClient object - * @param args The args is a tuple object containing an argument - * list passed from Python to a C function - * @param kwds Dictionary of keywords * * Returns an instance of aerospike.Client, Which can be used later to do usual * database operations. * In case of error,appropriate exceptions will be raised. ******************************************************************************************************* */ -PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, - PyObject *kwds) +PyObject *AerospikeClientConnect(AerospikeClient *self) { - as_error err; - as_error_init(&err); - char *alias_to_search = NULL; - bool free_alias_to_search = false; - PyObject *py_username = NULL; - PyObject *py_password = NULL; + as_error err; + as_error_init(&err); + char *alias_to_search = NULL; + bool free_alias_to_search = false; - if (PyArg_ParseTuple(args, "|OO:connect", &py_username, &py_password) == - false) { - return NULL; - } + if (!self || !self->as || !self->as->config.hosts || + !self->as->config.hosts->size) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, + "Invalid aerospike object or hosts not configured"); + goto CLEANUP; + } - if (py_username && PyString_Check(py_username) && py_password && - PyString_Check(py_password)) { - char *username = PyString_AsString(py_username); - char *password = PyString_AsString(py_password); - as_config_set_user(&self->as->config, username, password); - } + alias_to_search = return_search_string(self->as); + free_alias_to_search = true; - if (!self || !self->as || !self->as->config.hosts || - !self->as->config.hosts->size) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, - "Invalid aerospike object or hosts not configured"); - goto CLEANUP; - } + if (self->use_shared_connection) { + PyObject *py_persistent_item = + PyDict_GetItemString(py_global_hosts, alias_to_search); + if (py_persistent_item) { + aerospike *as = ((AerospikeGlobalHosts *)py_persistent_item)->as; + //Destroy the initial aerospike object as it has to point to the one in + //the persistent list now + if (as != self->as) { + // If the client has previously connected + // Other clients may share its aerospike* pointer + // So it is not safe to destroy it + if (!self->has_connected) { + aerospike_destroy(self->as); + } + self->as = as; + self->as->config.shm_key = + ((AerospikeGlobalHosts *)py_persistent_item)->shm_key; - alias_to_search = return_search_string(self->as); - free_alias_to_search = true; - - if (self->use_shared_connection) { - PyObject *py_persistent_item = - PyDict_GetItemString(py_global_hosts, alias_to_search); - if (py_persistent_item) { - aerospike *as = ((AerospikeGlobalHosts *)py_persistent_item)->as; - //Destroy the initial aerospike object as it has to point to the one in - //the persistent list now - if (as != self->as) { - // If the client has previously connected - // Other clients may share its aerospike* pointer - // So it is not safe to destroy it - if (!self->has_connected) { - aerospike_destroy(self->as); - } - self->as = as; - self->as->config.shm_key = - ((AerospikeGlobalHosts *)py_persistent_item)->shm_key; - - //Increase ref count of global host entry - ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; - } - else { - // If there is a matching global host entry, - // and this client was disconnected, increment the ref_cnt of the global. - // If the client is already connected, do nothing. - if (!self->is_conn_16) { - ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; - } - } - goto CLEANUP; - } - } - //Generate unique shm_key - PyObject *py_key, *py_value; - Py_ssize_t pos = 0; - int flag = 0; - int shm_key; - if (self->as->config.use_shm) { - if (user_shm_key) { - shm_key = self->as->config.shm_key; - user_shm_key = false; - } - else { - shm_key = counter; - } - while (1) { - flag = 0; - while (PyDict_Next(py_global_hosts, &pos, &py_key, &py_value)) { - if (((AerospikeGlobalHosts *)py_value)->as->config.use_shm) { - if (((AerospikeGlobalHosts *)py_value)->shm_key == - shm_key) { - flag = 1; - break; - } - } - } - if (!flag) { - self->as->config.shm_key = shm_key; - break; - } - shm_key = shm_key + 1; - } - self->as->config.shm_key = shm_key; - } + //Increase ref count of global host entry + ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; + } + else { + // If there is a matching global host entry, + // and this client was disconnected, increment the ref_cnt of the global. + // If the client is already connected, do nothing. + if (!self->is_conn_16) { + ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; + } + } + goto CLEANUP; + } + } + //Generate unique shm_key + PyObject *py_key, *py_value; + Py_ssize_t pos = 0; + int flag = 0; + int shm_key; + if (self->as->config.use_shm) { + if (user_shm_key) { + shm_key = self->as->config.shm_key; + user_shm_key = false; + } + else { + shm_key = counter; + } + while (1) { + flag = 0; + while (PyDict_Next(py_global_hosts, &pos, &py_key, &py_value)) { + if (((AerospikeGlobalHosts *)py_value)->as->config.use_shm) { + if (((AerospikeGlobalHosts *)py_value)->shm_key == + shm_key) { + flag = 1; + break; + } + } + } + if (!flag) { + self->as->config.shm_key = shm_key; + break; + } + shm_key = shm_key + 1; + } + self->as->config.shm_key = shm_key; + } - Py_BEGIN_ALLOW_THREADS - aerospike_connect(self->as, &err); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } - if (self->use_shared_connection) { - PyObject *py_newobject = (PyObject *)AerospikeGobalHosts_New(self->as); - PyDict_SetItemString(py_global_hosts, alias_to_search, py_newobject); - } + Py_BEGIN_ALLOW_THREADS + aerospike_connect(self->as, &err); + Py_END_ALLOW_THREADS + if (err.code != AEROSPIKE_OK) { + goto CLEANUP; + } + if (self->use_shared_connection) { + PyObject *py_newobject = (PyObject *)AerospikeGobalHosts_New(self->as); + PyDict_SetItemString(py_global_hosts, alias_to_search, py_newobject); + } CLEANUP: if (free_alias_to_search && alias_to_search) { @@ -168,6 +150,54 @@ PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, return (PyObject *)self; } +/** + ******************************************************************************************************* + * Establishes a connection to the Aerospike DB instance. + * + * @param self AerospikeClient object + * @param args The args is a tuple object containing an argument + * list passed from Python to a C function + * @param kwds Dictionary of keywords + * + * Returns an instance of aerospike.Client, Which can be used later to do usual + * database operations. + * In case of error,appropriate exceptions will be raised. + ******************************************************************************************************* + */ +PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, + PyObject *kwds) +{ + as_error err; + as_error_init(&err); + PyObject *py_username = NULL; + PyObject *py_password = NULL; + + if (PyArg_ParseTuple(args, "|OO:connect", &py_username, &py_password) == + false) { + return NULL; + } + + if (!self->has_connected) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, + "Invalid aerospike client configuration"); + goto CLEANUP; + } + +CLEANUP: + + if (err.code != AEROSPIKE_OK) { + PyObject *py_err = NULL; + error_to_pyobject(&err, &py_err); + PyObject *exception_type = raise_exception(&err); + PyErr_SetObject(exception_type, py_err); + Py_DECREF(py_err); + + return NULL; + } + Py_INCREF(self); + return (PyObject *)self; +} + /** ******************************************************************************************************* * Tests the connection to the Aerospike DB diff --git a/src/main/client/type.c b/src/main/client/type.c index d35643f41..7eef5ad05 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1260,6 +1260,7 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, * Set the individual policy groups new in 3.0 * */ +<<<<<<< HEAD if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { error_code = INIT_POLICY_PARAM_ERR; goto CONSTRUCTOR_ERROR; @@ -1402,6 +1403,159 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, self->as = aerospike_new(&config); return 0; +======= + if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + + PyObject *py_login_timeout = + PyDict_GetItemString(py_policies, "login_timeout_ms"); + if (py_login_timeout && PyInt_Check(py_login_timeout)) { + config.login_timeout_ms = PyInt_AsLong(py_login_timeout); + } + + PyObject *py_auth_mode = PyDict_GetItemString(py_policies, "auth_mode"); + if (py_auth_mode) { + if (PyInt_Check(py_auth_mode)) { + long auth_mode = PyInt_AsLong(py_auth_mode); + if ((long)AS_AUTH_INTERNAL == auth_mode || + (long)AS_AUTH_EXTERNAL == auth_mode || + (long)AS_AUTH_EXTERNAL_INSECURE == auth_mode || + (long)AS_AUTH_PKI == auth_mode) { + config.auth_mode = auth_mode; + } + else { + error_code = INIT_INVALID_AUTHMODE_ERR; + goto CONSTRUCTOR_ERROR; + } + } + else { + //it may come like auth_mode = None, for those non-integer cases, treat them as non-set + //error_code = INIT_INVALID_AUTHMODE_ERR; + //goto CONSTRUCTOR_ERROR; + } + } + } + + // thread_pool_size + PyObject *py_thread_pool_size = + PyDict_GetItemString(py_config, "thread_pool_size"); + if (py_thread_pool_size && PyInt_Check(py_thread_pool_size)) { + config.thread_pool_size = PyInt_AsLong(py_thread_pool_size); + } + + // max_threads (backward compatibility) + PyObject *py_max_threads = PyDict_GetItemString(py_config, "max_threads"); + if (py_max_threads && + (PyInt_Check(py_max_threads) || PyLong_Check(py_max_threads))) { + config.max_conns_per_node = PyInt_AsLong(py_max_threads); + } + + // max_conns_per_node + PyObject *py_max_conns = + PyDict_GetItemString(py_config, "max_conns_per_node"); + if (py_max_conns && + (PyInt_Check(py_max_conns) || PyLong_Check(py_max_conns))) { + config.max_conns_per_node = PyInt_AsLong(py_max_conns); + } + + //conn_timeout_ms + PyObject *py_connect_timeout = + PyDict_GetItemString(py_config, "connect_timeout"); + if (py_connect_timeout && PyInt_Check(py_connect_timeout)) { + config.conn_timeout_ms = PyInt_AsLong(py_connect_timeout); + } + + //Whether to utilize shared connection + PyObject *py_share_connect = + PyDict_GetItemString(py_config, "use_shared_connection"); + if (py_share_connect) { + self->use_shared_connection = PyObject_IsTrue(py_share_connect); + } + + PyObject *py_send_bool_as = PyDict_GetItemString(py_config, "send_bool_as"); + if (py_send_bool_as != NULL && PyLong_Check(py_send_bool_as)) { + int send_bool_as_temp = PyLong_AsLong(py_send_bool_as); + if (send_bool_as_temp >= SEND_BOOL_AS_PY_BYTES && + send_bool_as_temp <= SEND_BOOL_AS_AS_BOOL) { + self->send_bool_as = send_bool_as_temp; + } + } + + //compression_threshold + PyObject *py_compression_threshold = + PyDict_GetItemString(py_config, "compression_threshold"); + if (py_compression_threshold && PyInt_Check(py_compression_threshold)) { + int compression_value = PyInt_AsLong(py_compression_threshold); + if (compression_value >= 0) { + config.policies.write.compression_threshold = compression_value; + } + else { + error_code = INIT_COMPRESSION_ERR; + goto CONSTRUCTOR_ERROR; + } + } + + PyObject *py_tend_interval = + PyDict_GetItemString(py_config, "tend_interval"); + if (py_tend_interval && PyInt_Check(py_tend_interval)) { + config.tender_interval = PyInt_AsLong(py_tend_interval); + } + + PyObject *py_cluster_name = PyDict_GetItemString(py_config, "cluster_name"); + if (py_cluster_name && PyString_Check(py_cluster_name)) { + as_config_set_cluster_name(&config, + strdup(PyString_AsString(py_cluster_name))); + } + + //strict_types check + self->strict_types = true; + PyObject *py_strict_types = PyDict_GetItemString(py_config, "strict_types"); + if (py_strict_types && PyBool_Check(py_strict_types)) { + if (Py_False == py_strict_types) { + self->strict_types = false; + } + } + + if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + + PyObject *py_max_socket_idle = NULL; + py_max_socket_idle = PyDict_GetItemString(py_config, "max_socket_idle"); + if (py_max_socket_idle && PyInt_Check(py_max_socket_idle)) { + long max_socket_idle = PyInt_AsLong(py_max_socket_idle); + if (max_socket_idle >= 0) { + config.max_socket_idle = (uint32_t)max_socket_idle; + } + } + + PyObject *py_fail_if_not_connected = PyDict_GetItemString(py_config, "fail_if_not_connected"); + if (py_fail_if_not_connected && PyBool_Check(py_fail_if_not_connected)) { + config.fail_if_not_connected = PyObject_IsTrue(py_fail_if_not_connected); + } + + PyObject *py_user_name = PyDict_GetItemString(py_config, "user"); + PyObject *py_user_pwd = PyDict_GetItemString(py_config, "password"); + if (py_user_name && PyString_Check(py_user_name) && py_user_pwd && + PyString_Check(py_user_pwd)) { + char *username = PyString_AsString(py_user_name); + char *password = PyString_AsString(py_user_pwd); + as_config_set_user(&config, username, password); + } + + self->as = aerospike_new(&config); + + AerospikeClientConnect(self); + + return 0; +>>>>>>> 2c363b40 (establish connection while constructing client object, passthrough connect/close calls) CONSTRUCTOR_ERROR: @@ -1650,39 +1804,37 @@ PyTypeObject *AerospikeClient_Ready() AerospikeClient *AerospikeClient_New(PyObject *parent, PyObject *args, PyObject *kwds) { - AerospikeClient *self = (AerospikeClient *)AerospikeClient_Type.tp_new( - &AerospikeClient_Type, args, kwds); - as_error err; - as_error_init(&err); - int return_code = 0; - return_code = AerospikeClient_Type.tp_init((PyObject *)self, args, kwds); - - switch (return_code) { - // 0 Is success - case 0: { - // Initialize connection flag - self->is_conn_16 = false; - return self; - } - case -1: { - if (PyErr_Occurred()) { - return NULL; - } - break; - } - default: { - if (PyErr_Occurred()) { - return NULL; - } - break; - } - } - - PyObject *py_err = NULL; - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Failed to construct object"); - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; + AerospikeClient *self = (AerospikeClient *)AerospikeClient_Type.tp_new( + &AerospikeClient_Type, args, kwds); + as_error err; + as_error_init(&err); + int return_code = 0; + return_code = AerospikeClient_Type.tp_init((PyObject *)self, args, kwds); + + switch (return_code) { + // 0 Is success + case 0: { + return self; + } + case -1: { + if (PyErr_Occurred()) { + return NULL; + } + break; + } + default: { + if (PyErr_Occurred()) { + return NULL; + } + break; + } + } + + PyObject *py_err = NULL; + as_error_update(&err, AEROSPIKE_ERR_PARAM, "Failed to construct object"); + error_to_pyobject(&err, &py_err); + PyObject *exception_type = raise_exception(&err); + PyErr_SetObject(exception_type, py_err); + Py_DECREF(py_err); + return NULL; } diff --git a/test/test_cases.py b/test/test_cases.py index 38a120b75..531ed30ef 100644 --- a/test/test_cases.py +++ b/test/test_cases.py @@ -1158,6 +1158,8 @@ def get_aerospike(): # 'keyfile': "/Users/ramarajpandian/code/src/aerospike/enterprise/as-dev-infra/certs/Client-Chainless/key.pem", # noqa: E501 # 'for_login_only': True, # } + 'user':"generic_client", + 'password':"generic_client" } # Optionally set policies for various method types write_policies = {"total_timeout": 2000, "max_retries": 0, "key": aerospike.POLICY_KEY_SEND} From f8b897a1325a24492c6871ea72abc8e526d76af1 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Thu, 6 Oct 2022 21:51:46 +0530 Subject: [PATCH 02/27] propagate excepotion in case of failure --- src/main/client/type.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/client/type.c b/src/main/client/type.c index 7eef5ad05..7afae9305 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1552,7 +1552,9 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, self->as = aerospike_new(&config); - AerospikeClientConnect(self); + if (AerospikeClientConnect(self) == NULL) { + return -1; + } return 0; >>>>>>> 2c363b40 (establish connection while constructing client object, passthrough connect/close calls) From c517099296f5796c2777c065ee983703bc40b9e4 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Thu, 6 Oct 2022 22:19:22 +0530 Subject: [PATCH 03/27] test cases update --- .../operations/bitwise_operations.py | 2 +- test/new_tests/test_aggregate.py | 4 +- test/new_tests/test_append.py | 14 ++- test/new_tests/test_apply.py | 13 +- test/new_tests/test_batch_apply.py | 6 +- test/new_tests/test_batch_operate.py | 15 --- test/new_tests/test_batch_remove.py | 14 --- test/new_tests/test_batch_write.py | 14 --- test/new_tests/test_cdt_index.py | 4 +- test/new_tests/test_close.py | 27 +++- test/new_tests/test_connect.py | 4 +- test/new_tests/test_exists.py | 10 +- test/new_tests/test_exists_many.py | 15 ++- test/new_tests/test_get_async.py | 6 +- test/new_tests/test_get_many.py | 9 +- test/new_tests/test_get_node_names.py | 3 +- test/new_tests/test_get_nodes.py | 2 +- test/new_tests/test_get_put.py | 24 ++-- test/new_tests/test_get_udf.py | 8 +- test/new_tests/test_increment.py | 12 +- test/new_tests/test_index.py | 11 +- test/new_tests/test_info_all.py | 6 +- test/new_tests/test_info_random_node.py | 7 +- test/new_tests/test_info_single_node.py | 7 +- test/new_tests/test_is_connected.py | 9 +- test/new_tests/test_job_info.py | 9 +- test/new_tests/test_list_append.py | 10 +- test/new_tests/test_list_index.py | 3 +- test/new_tests/test_mapkeys_index.py | 13 +- test/new_tests/test_mapvalues_index.py | 117 ++++++++++-------- test/new_tests/test_operate.py | 5 +- test/new_tests/test_operate_helpers.py | 8 +- test/new_tests/test_operate_ordered.py | 5 +- test/new_tests/test_prepend.py | 6 +- test/new_tests/test_query.py | 18 ++- test/new_tests/test_query_apply.py | 66 ++++------ test/new_tests/test_remove.py | 12 +- test/new_tests/test_remove_bin.py | 14 +-- test/new_tests/test_scan_apply.py | 10 +- test/new_tests/test_select.py | 5 +- test/new_tests/test_select_many.py | 9 +- test/new_tests/test_touch.py | 9 +- test/new_tests/test_udf_list.py | 9 +- test/new_tests/test_udf_put.py | 8 +- test/new_tests/test_udf_remove.py | 10 +- 45 files changed, 267 insertions(+), 325 deletions(-) diff --git a/aerospike_helpers/operations/bitwise_operations.py b/aerospike_helpers/operations/bitwise_operations.py index 759162cf2..921123a6a 100644 --- a/aerospike_helpers/operations/bitwise_operations.py +++ b/aerospike_helpers/operations/bitwise_operations.py @@ -81,7 +81,7 @@ from aerospike import exception as e from aerospike_helpers.operations import bitwise_operations - config = {'hosts': [('127.0.0.1', 3000)]} + config = self.connection_config.copy() client = aerospike.client(config).connect() key = ('test', 'demo', 'bit_example') diff --git a/test/new_tests/test_aggregate.py b/test/new_tests/test_aggregate.py index fbb8e0546..b34063718 100644 --- a/test/new_tests/test_aggregate.py +++ b/test/new_tests/test_aggregate.py @@ -261,11 +261,11 @@ def callback(value): except e.ClientError as exception: assert exception.code == -1 - def test_neg_aggregate_with_correct_parameters_without_connection(self): + def test_aggregate_with_correct_parameters_without_connection(self): """ Invoke aggregate() with correct arguments without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) try: diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index ec15977f5..d53a29706 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -7,6 +7,8 @@ # @pytest.mark.usefixtures("as_connection") +# adds cls.connection_config to this class +@pytest.mark.usefixtures("connection_config") class TestAppend(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -423,19 +425,19 @@ def test_neg_append_parameters_as_none(self, key, bin, ex_code, ex_msg): with pytest.raises(e.ParamError): self.as_connection.append(key, bin, "str") - def test_neg_append_with_correct_parameters_without_connection(self): + def test_append_with_correct_parameters_without_connection(self): """ Invoke append() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) key = ("test", "demo", 1) - try: - client1.append(key, "name", "str") + client1.append(key, "name2", "str") + + (key, _, bins) = self.as_connection.get(key) - except e.ClusterError as exception: - assert exception.code == 11 + assert bins == {'age': 1, 'name': 'name1', 'name2': 'str'} def test_neg_append_with_low_timeout(self): """ diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index 741691816..8781bc04d 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -90,6 +90,8 @@ def remove_indexes_and_udfs(client): client.udf_remove(module, policy) +# adds cls.connection_config to this class +@pytest.mark.usefixtures("connection_config") class TestApply(TestBaseClass): def setup_class(cls): # Register setup and teardown functions @@ -295,16 +297,13 @@ def test_apply_with_correct_parameters_without_connection(self): """ Invoke apply() with correct arguments without connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.apply(key, "sample", "list_append", ["name", "car"]) - - err_code = err_info.value.code + retval = client1.apply(key, 'sample', 'list_append', ['name', 'car']) - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert retval == 0 def test_apply_with_arg_causing_error(self): """ diff --git a/test/new_tests/test_batch_apply.py b/test/new_tests/test_batch_apply.py index 48a26412f..8400f3075 100644 --- a/test/new_tests/test_batch_apply.py +++ b/test/new_tests/test_batch_apply.py @@ -335,9 +335,7 @@ def test_batch_apply_neg_connection(self): args = [] keys = [] - exp_res = e.ClusterError - - bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) - + exp_res = e.ClientError with pytest.raises(exp_res): + bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) bad_client.batch_apply(keys, module, function, args) diff --git a/test/new_tests/test_batch_operate.py b/test/new_tests/test_batch_operate.py index 8d2a7d9e8..ebe046ead 100644 --- a/test/new_tests/test_batch_operate.py +++ b/test/new_tests/test_batch_operate.py @@ -251,18 +251,3 @@ def test_batch_operate_neg(self, name, keys, ops, policy_batch, policy_batch_wri with pytest.raises(exp_res): self.as_connection.batch_operate(keys, ops, policy_batch, policy_batch_write) - - def test_batch_operate_neg_connection(self): - """ - Test batch_operate negative with bad connection. - """ - - keys = [] - ops = ["doesn't_matter"] - - exp_res = e.ClusterError - - bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) - - with pytest.raises(exp_res): - bad_client.batch_operate(keys, ops) diff --git a/test/new_tests/test_batch_remove.py b/test/new_tests/test_batch_remove.py index 071362d7e..027267eee 100644 --- a/test/new_tests/test_batch_remove.py +++ b/test/new_tests/test_batch_remove.py @@ -186,17 +186,3 @@ def test_batch_remove_neg(self, name, keys, policy_batch, policy_batch_remove, e with pytest.raises(exp_res): self.as_connection.batch_remove(keys, policy_batch, policy_batch_remove) - - def test_batch_remove_neg_connection(self): - """ - Test batch_remove negative with bad connection. - """ - - keys = [] - - exp_res = e.ClusterError - - bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) - - with pytest.raises(exp_res): - bad_client.batch_remove(keys) diff --git a/test/new_tests/test_batch_write.py b/test/new_tests/test_batch_write.py index fcc535144..5b5d1d967 100644 --- a/test/new_tests/test_batch_write.py +++ b/test/new_tests/test_batch_write.py @@ -453,17 +453,3 @@ def test_batch_write_neg(self, name, batch_records, policy, exp_res): with pytest.raises(exp_res): self.as_connection.batch_write(batch_records, policy) - - def test_batch_write_neg_connection(self): - """ - Test batch_write negative with bad connection. - """ - - batch_records = [] - - exp_res = e.ClusterError - - bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) - - with pytest.raises(exp_res): - bad_client.batch_write(batch_records) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index ab1cd1bfd..20a6296a9 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -697,12 +697,12 @@ def test_neg_cdtindex_with_incorrect_set(self): self.as_connection.index_remove("test", "test_numeric_list_cdt_index", policy) ensure_dropped_index(self.as_connection, "test", "test_numeric_list_cdt_index") - def test_neg_cdtindex_with_correct_parameters_no_connection(self): + def test_cdtindex_with_correct_parameters_no_connection(self): """ Invoke index_cdt_create() with correct arguments no connection """ policy = {} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) try: diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index 227c71627..f3cf740f1 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -5,6 +5,17 @@ import aerospike from aerospike import exception as e +aerospike = pytest.importorskip("aerospike") +try: + import aerospike + from aerospike import exception as e +except: + print("Please install aerospike python client.") + sys.exit(1) + + +@pytest.mark.usefixtures("connection_config") +class TestClose(): class TestClose: def setup_class(cls): @@ -16,7 +27,9 @@ def setup_class(cls): def test_pos_close(self): """ - Invoke close() after positive connect + Client call itself establishes connection. + Connect/Close are deprecated and no-op to client + Invoke close() after positive connect """ self.client = TestBaseClass.get_new_connection() self.closeobject = self.client.close() @@ -26,7 +39,7 @@ def test_pos_close_without_connection(self): """ Invoke close() without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() self.client = aerospike.client(config) try: @@ -37,7 +50,8 @@ def test_pos_close_without_connection(self): def test_neg_close(self): """ - Invoke close() after negative connect + Connect/Close are deprecated and no-op to client + Invoke close() after negative connect """ config = {"hosts": [("127.0.0.1", 2000)]} @@ -48,6 +62,9 @@ def test_neg_close(self): assert "has no attribute" in str(attributeError.value) def test_close_twice_in_a_row(self): + """ + Connect/Close are deprecated and no-op to client + """ config = TestBaseClass.get_connection_config() if TestClose.user is None and TestClose.password is None: self.client = aerospike.client(config).connect() @@ -56,8 +73,8 @@ def test_close_twice_in_a_row(self): assert self.client.is_connected() self.client.close() - assert self.client.is_connected() is False + assert self.client.is_connected() is True # This second call should not raise any errors self.client.close() - assert self.client.is_connected() is False + assert self.client.is_connected() is True diff --git a/test/new_tests/test_connect.py b/test/new_tests/test_connect.py index b4d2146fd..4a491812e 100644 --- a/test/new_tests/test_connect.py +++ b/test/new_tests/test_connect.py @@ -139,7 +139,7 @@ def test_connect_positive_cluster_name(self): def test_connect_positive_reconnect(self): """ - Connect/Close/Connect to client + Connect/Close are deprecated and no-op to client """ config = self.connection_config.copy() @@ -147,7 +147,7 @@ def test_connect_positive_reconnect(self): assert client is not None assert client.is_connected() client.close() - assert client.is_connected() is False + assert client.is_connected() is True if TestBaseClass.user is None and TestBaseClass.password is None: client.connect() else: diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index d9a05e7d0..6a18823af 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -13,7 +13,9 @@ class SomeClass(object): @pytest.mark.usefixtures("as_connection") -class TestExists: +@pytest.mark.usefixtures("connection_config") +class TestExists(): + @pytest.mark.parametrize("key, record", test_data.pos_data) def test_pos_exists_with_diff_datatype(self, key, record, put_data): """ @@ -103,12 +105,12 @@ def test_neg_exists_with_non_existent_data(self, key, ex, ex_code): except ex as exception: assert exception.code == ex_code - def test_neg_exists_with_only_key_without_connection(self): + def test_exists_with_only_key_without_connection(self): """ Invoke exists() with a key and not policy's dict and no connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) try: diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 4df111e3f..1b1fcdd87 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -13,7 +13,9 @@ @pytest.mark.usefixtures("as_connection") -class TestExistsMany: +@pytest.mark.usefixtures("connection_config") +class TestExistsMany(): + def test_pos_exists_many_without_policy(self, put_data): self.keys = [] rec_length = 5 @@ -194,7 +196,8 @@ def test_neg_exists_many_with_invalid_timeout(self, put_data): with pytest.raises(e.ParamError): self.as_connection.exists_many(self.keys, policies) - def test_neg_exists_many_with_proper_parameters_without_connection(self, put_data): + def test_exists_many_with_proper_parameters_without_connection( + self, put_data): self.keys = [] rec_length = 5 for i in range(rec_length): @@ -203,14 +206,10 @@ def test_neg_exists_many_with_proper_parameters_without_connection(self, put_dat put_data(self.as_connection, key, record) self.keys.append(key) - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - try: - client1.exists_many(self.keys, {"total_timeout": 20}) - - except e.ClusterError as exception: - assert exception.code == 11 + assert client1.exists_many(self.keys, {'total_timeout': 20}) is not None def test_neg_exists_many_with_extra_parameter_in_key(self, put_data): keys = [] diff --git a/test/new_tests/test_get_async.py b/test/new_tests/test_get_async.py index 20f8b98be..61f059ede 100644 --- a/test/new_tests/test_get_async.py +++ b/test/new_tests/test_get_async.py @@ -241,12 +241,12 @@ async def async_io(key_input=None, policy_input=None): await asyncio.gather(async_io(_input)) @pytest.mark.asyncio - async def test_neg_get_with_only_key_no_connection(self): + async def test_get_with_only_key_no_connection(self): """ Invoke get() with a key and not policy's dict no connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) async def async_io(key_input=None, policy_input=None): diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index c52256277..a89c07bdc 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -11,6 +11,8 @@ import aerospike from aerospike import exception as e +@pytest.mark.usefixtures("connection_config") +class TestGetMany(): class TestGetMany: @pytest.fixture(autouse=True) @@ -210,11 +212,10 @@ def test_neg_get_many_Invalid_Key_without_primary_key(self): with pytest.raises(e.ParamError): key, _, _ = self.as_connection.get(key) - def test_neg_get_many_with_proper_parameters_without_connection(self): - config = {"hosts": [("127.0.0.1", 3000)]} + def test_get_many_with_proper_parameters_without_connection(self): + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError): - client1.get_many(self.keys, {"total_timeout": 20}) + assert client1.get_many(self.keys, {'total_timeout': 20}) is not None def test_neg_prepend_Invalid_Key_without_set_name(self): """ diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index cd54b3167..8e699badd 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -6,6 +6,7 @@ @pytest.mark.usefixtures("as_connection") +@pytest.mark.usefixtures("connection_config") class TestGetNodeNames(object): """ Test Cases for the use of aerospike.Client.get_node_names @@ -34,7 +35,7 @@ def test_pos_get_node_names_without_connection(self): Test that an attempt to call get_node_names before a connection is established will raise the expected error """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() unconnected_client = aerospike.client(config) try: diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index bb162eac2..46f15ea6e 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -41,7 +41,7 @@ def test_pos_get_nodes_without_connection(self): Test that an attempt to call get_nodes before a connection is established will raise the expected error """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() unconnected_client = aerospike.client(config) try: diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 0370938da..1b1109ec3 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -235,16 +235,18 @@ def test_neg_get_remove_key_and_check_get(self, _input, _expected, put_data): except e.RecordNotFound as exception: assert exception.code == 2 - def test_neg_get_with_only_key_no_connection(self): + def test_get_with_only_key_no_connection(self): """ Invoke get() with a key and not policy's dict no connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError): - key, _, _ = client1.get(key) + try: + client1.get(key) + except e.RecordNotFound as exception: + assert exception.code == 2 # Put Tests def test_pos_put_with_policy_exists_create_or_replace(self): @@ -737,21 +739,17 @@ def test_neg_put_with_policy_gen_GT_lesser(self): assert {"name": "John"} == bins self.as_connection.remove(key) - def test_neg_put_with_string_record_without_connection(self): + def test_put_with_string_record_without_connection(self): """ Invoke put() for a record with string data without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - key = ("test", "demo", 1) - + key = ('test', 'demo', 1) bins = {"name": "John"} - try: - client1.put(key, bins) - except e.ClusterError as exception: - assert exception.code == 11 + assert 0 == client1.put(key, bins) @pytest.mark.parametrize( "key, record, meta, policy, ex_code, ex_msg", diff --git a/test/new_tests/test_get_udf.py b/test/new_tests/test_get_udf.py index ce2e52503..dab200531 100644 --- a/test/new_tests/test_get_udf.py +++ b/test/new_tests/test_get_udf.py @@ -8,6 +8,7 @@ @pytest.mark.usefixtures("connection_with_udf") +@pytest.mark.usefixtures("connection_config") class TestGetRegistered(object): def setup_class(cls): """ @@ -141,10 +142,7 @@ def test_udf_get_with_correct_paramters_without_connection(self): """ policy = {"timeout": 5000} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.udf_get(self.loaded_udf_name, self.udf_language, policy) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert client1.udf_get(self.loaded_udf_name, self.udf_language, policy) is not None diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index dae6bb868..8c7a44857 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -8,6 +8,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestIncrement(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -341,16 +342,11 @@ def test_increment_with_correct_parameters_without_connection(self): """ Invoke increment() with correct parameters without connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.increment(key, "age", 5) - - err_code = err_info.value.code - - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert 0 == client1.increment(key, "age", 5) @pytest.mark.skip(reason="This raises a system error." + " Something else should be raised") def test_increment_with_integer_greaterthan_maxsize(self): diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 52f0cac54..a74f7d4e8 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -7,6 +7,8 @@ import aerospike +@pytest.mark.usefixtures("connection_config") +class TestIndex(object): class TestIndex(object): @pytest.fixture(autouse=True) @@ -439,14 +441,11 @@ def test_createindex_integer_unicode(self): def test_createindex_with_correct_parameters_without_connection(self): # Invoke createindex() with correct arguments without connection policy = {} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.index_integer_create("test", "demo", "age", "age_index", policy) - - err_code = err_info.value.code - assert err_code is AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert 0 == client1.index_integer_create( + 'test', 'demo', 'age', 'age_index', policy) def test_index_remove_no_args(self): diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index 9617f28f2..e1481a6cd 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -90,9 +90,9 @@ def test_info_all_without_connection(self): """ client1 = aerospike.client(self.connection_config) - with pytest.raises(e.ClusterError): - client1.info_all("sets") - + nodes_info = client1.info_all('sets') + assert nodes_info is not None + def test_info_all_with_invalid_policy_type(self): """ Test that sending a non dict/None as policy raises an error diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index 354d8f215..1681ecd17 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -135,11 +135,8 @@ def test_info_random_node_positive_without_connection(self): Test info with correct arguments without connection. """ client1 = aerospike.client(self.connection_config) - with pytest.raises(e.ClusterError) as err_info: - client1.info_random_node("bins") - - assert err_info.value.code == 11 - assert err_info.value.msg == "No connection to aerospike cluster." + response = client1.info_random_node('bins') + assert response is not None def test_info_random_node_positive_with_extra_parameters(self): """ diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index 7298aa626..81388347d 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -140,11 +140,8 @@ def test_info_single_node_positive_without_connection(self): Test info with correct arguments without connection. """ client1 = aerospike.client(self.connection_config) - with pytest.raises(e.ClusterError) as err_info: - client1.info_single_node("bins", self.connection_config["hosts"][0][:2]) - - assert err_info.value.code == 11 - assert err_info.value.msg == "No connection to aerospike cluster." + with pytest.raises(e.ParamError) as err_info: + client1.info_single_node('bins', self.connection_config['hosts'][0][:2]) def test_info_single_node_positive_with_extra_parameters(self): """ diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index 5bf082f1f..131c766f9 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -5,6 +5,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestIsConnected(object): def setup_class(cls): """ @@ -29,7 +30,7 @@ def test_is_connected_before_connect(self): Test that is_connected returns false before a connection is established """ client = aerospike.client(self.config) - assert client.is_connected() is False + assert client.is_connected() is True def test_pos_is_connected(self): """ @@ -51,10 +52,10 @@ def test_pos_is_connected_after_multiple_connects(self): def test_is_connected_after_close(self): """ - Test that is_connected returns False after a successful calls to - connect() and close() + Test that is_connected returns True after a successful calls to + connect() and close() (deprecated and it is no-op) """ self._connect() assert self.client.is_connected() is True self.client.close() - assert self.client.is_connected() is False + assert self.client.is_connected() is True diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index a1bf372c5..0ddbda1e6 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -6,6 +6,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestScanInfo(object): udf_to_load = "bin_lua.lua" @@ -125,13 +126,11 @@ def test_job_info_with_correct_parameters_without_connection(self): Invoke job_info() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.job_info(self.job_id, aerospike.JOB_SCAN) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + response = client1.job_info(self.job_id, aerospike.JOB_SCAN) + assert response is not None def test_job_info_with_constant_out_of_valid_values(self): """ diff --git a/test/new_tests/test_list_append.py b/test/new_tests/test_list_append.py index 44c18a660..c296705af 100644 --- a/test/new_tests/test_list_append.py +++ b/test/new_tests/test_list_append.py @@ -6,6 +6,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestListAppend(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -218,7 +219,8 @@ def test_neg_list_append_meta_type_integer(self): assert exception.msg == "Metadata should be of type dictionary" def test_list_append_with_no_connection(self): - client = aerospike.client({"hosts": [("localhost", 3000)]}) - k = ("test", "demo", "no_con") - with pytest.raises(e.ClusterError): - client.list_append(k, "bob", "item") + config = self.connection_config.copy() + client = aerospike.client(config) + k = ('test', 'demo', 'no_con') + response = client.list_append(k, 'bob', 'item') + assert response is not None diff --git a/test/new_tests/test_list_index.py b/test/new_tests/test_list_index.py index a36523bbb..a69fb4467 100644 --- a/test/new_tests/test_list_index.py +++ b/test/new_tests/test_list_index.py @@ -7,6 +7,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestListIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -347,7 +348,7 @@ def test_neg_listindex_with_correct_parameters_no_connection(self): Invoke index_list_create() with correct arguments no connection """ policy = {} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) try: diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index b38acb73f..6f7333a96 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -30,6 +30,7 @@ def remove_map_keys(client): @pytest.mark.usefixtures("connection_with_config_funcs") +@pytest.mark.usefixtures("connection_config") class TestMapKeysIndex(object): def setup_class(cls): cls.connection_setup_functions = [add_map_keys] @@ -333,13 +334,11 @@ def test_mapkeysindex_with_correct_parameters_no_connection(self): Invoke index_map_keys_create() with correct arguments no connection """ policy = {} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.index_map_keys_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + retval = client1.index_map_keys_create( + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index', policy) - err_code = err_info.value.code - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert retval == 0 diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 279da3d70..2c9bad48e 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -32,6 +32,7 @@ def remove_maps_from_client(client): @pytest.mark.usefixtures("connection_with_config_funcs") +@pytest.mark.usefixtures("connection_config") class TestMapValuesIndex(object): def setup_class(cls): """ @@ -56,12 +57,13 @@ def test_mapvaluesindex_with_correct_parameters(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index1', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove('test', 'test_string_map_index1', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') def test_mapvaluesindex_with_correct_parameters_no_policy(self): """ @@ -69,12 +71,12 @@ def test_mapvaluesindex_with_correct_parameters_no_policy(self): and the policy argument not passed """ retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index" - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index2') assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index") - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove('test', 'test_string_map_index2') + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index2') def test_mapvaluesindex_with_correct_parameters_numeric(self): """ @@ -98,8 +100,9 @@ def test_mapvalues_index_with_correct_parameters_set_length_extra(self): policy = {} with pytest.raises(e.InvalidRequest) as err_info: self.as_connection.index_map_values_create( - "test", set_name, "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', set_name, + 'string_map', aerospike.INDEX_STRING, + "test_string_map_index3", policy) err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_REQUEST_INVALID @@ -137,22 +140,23 @@ def test_mapvaluesindex_with_incorrect_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map1", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map1', aerospike.INDEX_STRING, + 'test_string_map_index4', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove('test', 'test_string_map_index4', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index4') @pytest.mark.parametrize( "test_ns, test_set, test_bin, test_idx_name", ( - (None, "demo", "string_map", "test_string_map_index"), - (1, "demo", "string_map", "test_string_map_index"), - ("test", 1, "string_map", "test_string_map_index"), - ("test", "demo", None, "test_string_map_index"), - ("test", "demo", "string_map", None), - ("test", "demo", "string_map", 1), + (None, 'demo', 'string_map', 'test_string_map_index5'), + (1, 'demo', 'string_map', 'test_string_map_index6'), + ('test', 1, 'string_map', 'test_string_map_index7'), + ('test', 'demo', None, 'test_string_map_index8'), + ('test', 'demo', 'string_map', None), + ('test', 'demo', 'string_map', 1), ), ids=("ns is None", "ns is int", "set is int", "bin is None", "index name is none", "index name is int"), ) @@ -175,12 +179,13 @@ def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): with pytest.raises(e.ParamError) as err_info: self.as_connection.index_map_values_create( - "test", "demo", "string_map", idx_val, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map', idx_val, + "test_string_map_index9", policy) try: - self.as_connection.index_remove("test", "test_string_map_index") - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") - except Exception: + self.as_connection.index_remove( + 'test', 'test_string_map_index9') + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index9') + except: pass err_code = err_info.value.code @@ -215,19 +220,21 @@ def test_create_same_mapvaluesindex_multiple_times_different_bin(self): policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index10', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK with pytest.raises(e.IndexFoundError): retobj = self.as_connection.index_map_values_create( - "test", "demo", "numeric_map", aerospike.INDEX_NUMERIC, "test_string_map_index", policy - ) - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + 'test', 'demo', 'numeric_map', aerospike.INDEX_NUMERIC, + 'test_string_map_index10', policy) + self.as_connection.index_remove( + 'test', 'test_string_map_index10', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index10') - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove( + 'test', 'test_string_map_index10', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index10') def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ @@ -236,23 +243,26 @@ def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index11', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK try: retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy - ) - self.as_connection.index_remove("test", "test_string_map_index1", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index1', policy) + self.as_connection.index_remove( + 'test', 'test_string_map_index1', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') + self.as_connection.index_remove( + 'test', 'test_string_map_index11', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index11') except e.IndexFoundError: assert self.server_version < [6, 1] - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove( + 'test', 'test_string_map_index11', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index11') def test_createmapvaluesindex_with_policy(self): """ @@ -273,12 +283,13 @@ def test_createmapvaluesindex_with_policystring(self): """ policy = {"timeout": 1000} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index12', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove('test', 'test_string_map_index12', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index12') """ This test case causes a db crash and hence has been commented. Work pending @@ -330,13 +341,11 @@ def test_mapvaluesindex_with_correct_parameters_no_connection(self): connection """ policy = {} - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) + retval = client1.index_map_values_create( + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index13', policy) - err_code = err_info.value.code - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + assert retval == 0 diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index ca2295aa4..82dd0d8ee 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -53,6 +53,7 @@ # aerospike.OP_MAP_GET_BY_RANK_RANGE +@pytest.mark.usefixtures("connection_config") class TestOperate(object): def setup_class(cls): """ @@ -529,8 +530,8 @@ def test_pos_operate_with_correct_paramters_without_connection(self): """ Invoke operate() with correct parameters without connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) llist = [ {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index 233d4adb1..7b3b5d9a1 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -54,6 +54,7 @@ # aerospike.OP_MAP_GET_BY_RANK_RANGE +@pytest.mark.usefixtures("connection_config") class TestOperate(object): def setup_class(cls): """ @@ -441,13 +442,12 @@ def test_pos_operate_with_correct_paramters_without_connection(self): """ Invoke operate() with correct parameters without connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) llist = [operations.touch()] - with pytest.raises(e.ClusterError): - client1.operate(key, llist) + assert client1.operate(key, llist) is not None def test_pos_operate_write_set_to_aerospike_null(self): """ diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index d97123c94..6409973b2 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -6,6 +6,7 @@ from aerospike import exception as e +@pytest.mark.usefixtures("connection_config") class TestOperateOrdered(object): def setup_class(cls): """ @@ -662,8 +663,8 @@ def test_neg_operate_ordered_without_connection(self): """ Invoke operate_ordered() with correct parameters without connection """ - key = ("test", "demo", 1) - config = {"hosts": [("127.0.0.1", 3000)]} + key = ('test', 'demo', 1) + config = self.connection_config.copy() client1 = aerospike.client(config) llist = [ {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index 6a7f15a7c..1a5c1118b 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -5,7 +5,9 @@ from aerospike import exception as e -class TestPrepend: +@pytest.mark.usefixtures("connection_config") +class TestPrepend(): + @pytest.fixture(autouse=True) def setup(self, request, as_connection): """ @@ -482,7 +484,7 @@ def test_neg_prepend_with_correct_parameters_without_connection(self): """ Invoke prepend() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) key = ("test", "demo", 1) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index 803b922ba..b16fced4a 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -57,6 +57,7 @@ def add_ctx_op(ctx_type, value): ctx_map_value.append(add_ctx_op(map_value, 3)) +@pytest.mark.usefixtures("connection_config") class TestQuery(TestBaseClass): def setup_class(cls): client = TestBaseClass.get_new_connection() @@ -962,21 +963,18 @@ def test_query_with_correct_parameters_without_connection(self): """ Invoke query() with correct arguments without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - query = client1.query("test", "demo") - query.select("name", "test_age") - query.where(p.equals("test_age", 1)) + query = client1.query('test', 'demo') + query.select('name', 'test_age') + query.where(p.equals('test_age', 1)) - def callback(input_tuple): - pass + def callback(input_tuple): + pass - query.foreach(callback) + query.foreach(callback) - err_code = err_info.value.code - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR @pytest.mark.skip(reason="segfault") def test_query_predicate_range_wrong_no_args(self): diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index fb33f6712..4a0cc4a10 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -71,6 +71,7 @@ def remove_indexes_from_client(client): client.index_remove("test", "test_null_age_idx") +@pytest.mark.usefixtures("connection_config") class TestQueryApply(object): # These functions will run once for this test class, and do all of the @@ -300,15 +301,11 @@ def test_query_apply_with_correct_parameters_without_connection(self): """ Invoke query_apply() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.query_apply("test", "demo", self.age_range_pred, "query_apply", "mark_as_applied", ["name", 2]) - - err_code = err_info.value.code - - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.query_apply("test", "demo", self.age_range_pred, + "query_apply", "mark_as_applied", ['name', 2]) @pytest.mark.parametrize( "predicate", @@ -334,15 +331,12 @@ def test_stream_udf_parameters(self): Invoke query.apply() with a stream udf. that accepts additional arguments. """ - query_results = ( - self.as_connection.query( - "test", - "demo", - ) - .apply("query_apply_parameters", "query_params", [["age", 5]]) - .results() - ) - + query_results = self.as_connection.query( + "test", "demo" + ).apply( + 'query_apply_parameters', 'query_params', [['age', 5]] + ).results() + query_results.sort() assert query_results == [6, 7, 8, 9] @@ -422,19 +416,13 @@ def test_stream_udf_parameters_with_serialized_set(self): Invoke query.apply() with a stream udf. arguments contain a serialized set. """ - query_results = ( - self.as_connection.query( - "test", - "demo", - ) - .apply( - "query_apply_parameters", - "query_params", - [["age", 5], pickle.dumps({"lary", "quinton", "julie", "mark"})], - ) - .results() - ) - + query_results = self.as_connection.query( + "test", "demo" + ).apply( + 'query_apply_parameters', 'query_params', [['age', 5] + ,pickle.dumps({'lary', 'quinton', 'julie', 'mark'})] + ).results() + query_results.sort() assert query_results == [6, 7, 8, 9] @@ -443,19 +431,13 @@ def test_stream_udf_complicated_parameters(self): Invoke query.apply() with a stream udf. that accepts additional arguments. """ - query_results = ( - self.as_connection.query( - "test", - "demo", - ) - .apply( - "query_apply_parameters", - "query_params", - [["age", 2], ["id", ["john", ["hi"]], ["john", {"mary": 39}]], []], - ) - .results() - ) - + query_results = self.as_connection.query( + "test", "demo" + ).apply( + 'query_apply_parameters', 'query_params', [['age', 2], + ['id', ['john', ['hi']], ['john', {'mary' : 39}]], []] + ).results() + query_results.sort() assert query_results == [3, 4, 5, 6, 7, 8, 9] diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index 6b983d3a6..bb54d7e63 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -8,7 +8,9 @@ @pytest.mark.usefixtures("as_connection") -class TestRemove: +@pytest.mark.usefixtures("connection_config") +class TestRemove(): + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_existing_record(self): """ @@ -300,18 +302,18 @@ def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): (code, _, _, _) = exception.value assert code == ex_code - def test_neg_remove_with_correct_parameters_without_connection(self): + def test_remove_with_correct_parameters_without_connection(self): """ Invoke remove() with correct arguments without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) key = ("test", "demo", 1) - with pytest.raises(e.ClusterError) as exception: + with pytest.raises(e.RecordNotFound) as exception: client1.remove(key) (code, _, _, _) = exception.value - assert code == 11 + assert code == 2 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 d00cfd0e9..903c3b05d 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -6,6 +6,7 @@ @pytest.mark.usefixtures("as_connection") +@pytest.mark.usefixtures("connection_config") class TestRemovebin(object): @pytest.mark.parametrize( "key, record, bin_for_removal", @@ -246,20 +247,17 @@ def test_neg_remove_bin_with_none(self, key, bin_for_removal, ex_code, ex_msg): assert exception.code == ex_code assert exception.msg == ex_msg - def test_neg_remove_bin_with_correct_parameters_without_connection(self): + def test_remove_bin_with_correct_parameters_without_connection(self, put_data): """ Invoke remove_bin() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - key = ("test", "demo", 1) - - try: - client1.remove_bin(key, ["age"]) + key = ('test', 'demo', 1) + put_data(client1, key, {'name': "jeff", 'age': 45}) - except e.ClusterError as exception: - assert exception.code == 11 + client1.remove_bin(key, ["age"]) def test_neg_remove_bin_with_incorrect_meta(self): """ diff --git a/test/new_tests/test_scan_apply.py b/test/new_tests/test_scan_apply.py index 54e4d631e..592b3ed9c 100644 --- a/test/new_tests/test_scan_apply.py +++ b/test/new_tests/test_scan_apply.py @@ -20,6 +20,7 @@ def wait_for_job_completion(as_connection, job_id): time.sleep(0.1) +@pytest.mark.usefixtures("connection_config") class TestScanApply(object): def setup_class(cls): cls.udf_to_load = "bin_lua.lua" @@ -341,14 +342,11 @@ def test_scan_apply_with_correct_parameters_without_connection(self): """ Invoke scan_apply() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.scan_apply("test", "demo", "bin_lua", "mytransform", ["age", 2]) - - err_code = err_info.value.code - assert err_code is AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.scan_apply( + "test", "demo", "bin_lua", "mytransform", ['age', 2]) def test_scan_apply_with_incorrect_policy(self): """ diff --git a/test/new_tests/test_select.py b/test/new_tests/test_select.py index 93d65574b..3a162db53 100644 --- a/test/new_tests/test_select.py +++ b/test/new_tests/test_select.py @@ -182,10 +182,7 @@ def test_select_with_key_and_bins_without_connection(self): config = self.connection_config disconnected_client = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - disconnected_client.select(self.test_key, bins_to_select) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + disconnected_client.select(self.test_key, bins_to_select) def test_select_with_invalid_keys(self, invalid_key): """ diff --git a/test/new_tests/test_select_many.py b/test/new_tests/test_select_many.py index b30b9aa03..cf60d8410 100644 --- a/test/new_tests/test_select_many.py +++ b/test/new_tests/test_select_many.py @@ -23,6 +23,7 @@ def get_primary_key(record): return record[0][2] +@pytest.mark.usefixtures("connection_config") class TestSelectMany(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -292,15 +293,13 @@ def test_select_many_without_any_parameter(self): def test_select_many_with_proper_parameters_without_connection(self): - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) filter_bins = ["title", "name"] - with pytest.raises(e.ClusterError) as err_info: - client1.select_many(self.keys, filter_bins, {"timeout": 20}) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.select_many(self.keys, filter_bins, {'timeout': + 20}) def test_select_many_with_invalid_keys(self, invalid_key): # invalid_key will be an invalid key_tuple, so we wrap diff --git a/test/new_tests/test_touch.py b/test/new_tests/test_touch.py index bb6f4161b..f7552f17d 100644 --- a/test/new_tests/test_touch.py +++ b/test/new_tests/test_touch.py @@ -6,6 +6,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestTouch(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -260,15 +261,11 @@ def test_touch_with_correct_paramters_without_connection(self): """ Invoke touch() with correct parameters without connection """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) key = ("test", "demo", 1) - with pytest.raises(e.ClusterError) as err_info: - client1.touch(key, 120) - - err_code = err_info.value.code - assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.touch(key, 120) def test_touch_withttlvalue_greaterthan_maxsize(self): """ diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index 64f31d310..ca186a81d 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -6,6 +6,7 @@ import aerospike +@pytest.mark.usefixtures("connection_config") class TestUdfList(object): def setup_class(cls): """ @@ -109,14 +110,10 @@ def test_udf_list_with_proper_parameters_without_connection(self): Test to verify error raised by trying to call udf_list without first calling connect """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) policy = {"timeout": 0} - with pytest.raises(e.ClusterError) as cluster_error: - client1.udf_list(policy) - - assert cluster_error.value.code == 11 - assert cluster_error.value.msg == "No connection to aerospike cluster" + client1.udf_list(policy) diff --git a/test/new_tests/test_udf_put.py b/test/new_tests/test_udf_put.py index 90ca0dff9..84c7fcf4d 100644 --- a/test/new_tests/test_udf_put.py +++ b/test/new_tests/test_udf_put.py @@ -10,6 +10,7 @@ @pytest.mark.usefixtures("as_connection") +@pytest.mark.usefixtures("connection_config") class TestUdfPut(TestBaseClass): def setup_class(cls): cls.udf_name = "example.lua" @@ -129,14 +130,11 @@ def test_udf_put_with_proper_parameters_without_connection(self): filename = self.udf_name udf_type = 0 - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) - with pytest.raises(e.ClusterError) as err_info: - client1.udf_put(filename, udf_type, policy) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.udf_put(filename, udf_type, policy) def test_udf_put_with_invalid_timeout_policy_value(self): """ diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index d7dfa94e7..1f9f6c6d7 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -8,6 +8,7 @@ from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist import aerospike from aerospike import exception as e +from .test_base_class import TestBaseClass def is_greater_451(version_str): @@ -17,6 +18,7 @@ def is_greater_451(version_str): return LooseVersion(version_str) >= LooseVersion("4.5.1") +@pytest.mark.usefixtures("connection_config") class TestUdfRemove(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -132,6 +134,7 @@ def test_udf_remove_with_unicode_filename(self): @pytest.mark.usefixtures("connection_with_udf") +@pytest.mark.usefixtures("connection_config") class TestIncorrectCallsToUDFRemove(object): """ These are all tests where udf_remove fails for various reasons, @@ -149,16 +152,13 @@ def test_udf_remove_with_proper_parameters_without_connection(self): Test to verify that attempting to remove a UDF before connection raises an error """ - config = {"hosts": [("127.0.0.1", 3000)]} + config = self.connection_config.copy() client1 = aerospike.client(config) policy = {"timeout": 100} module = "example.lua" - with pytest.raises(e.ClusterError) as err_info: - client1.udf_remove(module, policy) - - assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + client1.udf_remove(module, policy) def test_udf_remove_with_non_existent_module(self): """ From 5fadef10b8e5b52233220434e2e119692b7e9ebe Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Fri, 7 Oct 2022 10:28:06 +0530 Subject: [PATCH 04/27] update test --- test/new_tests/test_query_apply.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index 4a0cc4a10..470afdd06 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -297,16 +297,6 @@ def test_query_apply_unicode_literal_for_strings(self): self._wait_for_query_complete(query_id) self._correct_items_have_been_applied() - def test_query_apply_with_correct_parameters_without_connection(self): - """ - Invoke query_apply() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - client1.query_apply("test", "demo", self.age_range_pred, - "query_apply", "mark_as_applied", ['name', 2]) - @pytest.mark.parametrize( "predicate", ( From b697beb2c747d64f88f0c5939b172c600ff408ef Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Mon, 10 Oct 2022 14:13:14 +0530 Subject: [PATCH 05/27] test cases update --- test/new_tests/test_batch_apply.py | 15 --------------- test/new_tests/test_cdt_index.py | 20 +++++++------------- test/new_tests/test_exists.py | 7 ++----- test/new_tests/test_exists_many.py | 15 --------------- test/new_tests/test_get_node_names.py | 9 ++------- test/new_tests/test_get_nodes.py | 8 ++------ test/new_tests/test_get_put.py | 14 +------------- test/new_tests/test_index.py | 2 ++ test/new_tests/test_is_connected.py | 8 ++++---- test/new_tests/test_list_index.py | 13 +++++++------ test/new_tests/test_mapkeys_index.py | 2 ++ test/new_tests/test_query_apply.py | 7 +++---- test/new_tests/test_remove_bin.py | 12 ------------ test/new_tests/test_scan_apply.py | 4 ++-- test/new_tests/test_select.py | 4 ++-- test/new_tests/test_udf_list.py | 5 +++-- test/new_tests/test_udf_remove.py | 15 --------------- 17 files changed, 39 insertions(+), 121 deletions(-) diff --git a/test/new_tests/test_batch_apply.py b/test/new_tests/test_batch_apply.py index 8400f3075..fabdf752c 100644 --- a/test/new_tests/test_batch_apply.py +++ b/test/new_tests/test_batch_apply.py @@ -324,18 +324,3 @@ def test_batch_apply_neg(self, name, keys, module, function, args, policy_batch, with pytest.raises(exp_res): self.as_connection.batch_apply(keys, module, function, args, policy_batch, policy_batch_apply) - - def test_batch_apply_neg_connection(self): - """ - Test batch_apply negative with bad connection. - """ - - module = "lua_mod" - function = "lua_func" - args = [] - keys = [] - - exp_res = e.ClientError - with pytest.raises(exp_res): - bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) - bad_client.batch_apply(keys, module, function, args) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 20a6296a9..c2c1ec5eb 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -705,20 +705,14 @@ def test_cdtindex_with_correct_parameters_no_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - try: - client1.index_cdt_create( - "test", - "demo", - "string_list", - aerospike.INDEX_TYPE_LIST, - aerospike.INDEX_STRING, - "test_string_list_cdt_index", - {"ctx": ctx_list_index}, - policy, - ) + client1.index_cdt_create( + 'test', 'demo', 'string_list', aerospike.INDEX_TYPE_LIST, + aerospike.INDEX_STRING, + 'test_string_list_cdt_index', {'ctx': ctx_list_index}, policy) + self.as_connection.index_remove('test', 'test_string_list_cdt_index', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_list_cdt_index') - except e.ClusterError as exception: - assert exception.code == 11 def test_neg_cdtindex_with_no_paramters(self): """ diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 6a18823af..97045c39b 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -113,11 +113,8 @@ def test_exists_with_only_key_without_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - try: - key, _ = client1.exists(key) - - except e.ClusterError as exception: - assert exception.code == 11 + key, _ = client1.exists(key) + assert key is not None @pytest.mark.parametrize( "key, record, meta, policy", diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 1b1fcdd87..41d7ebd38 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -13,7 +13,6 @@ @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") class TestExistsMany(): def test_pos_exists_many_without_policy(self, put_data): @@ -196,20 +195,6 @@ def test_neg_exists_many_with_invalid_timeout(self, put_data): with pytest.raises(e.ParamError): self.as_connection.exists_many(self.keys, policies) - def test_exists_many_with_proper_parameters_without_connection( - self, put_data): - self.keys = [] - rec_length = 5 - for i in range(rec_length): - key = ("test", "demo", i) - record = {"name": "name%s" % (str(i)), "age": i} - put_data(self.as_connection, key, record) - self.keys.append(key) - - config = self.connection_config.copy() - client1 = aerospike.client(config) - - assert client1.exists_many(self.keys, {'total_timeout': 20}) is not None def test_neg_exists_many_with_extra_parameter_in_key(self, put_data): keys = [] diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index 8e699badd..bdc05d8c8 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -37,10 +37,5 @@ def test_pos_get_node_names_without_connection(self): """ config = self.connection_config.copy() unconnected_client = aerospike.client(config) - - try: - unconnected_client.get_node_names() - - except e.ClusterError as exception: - assert exception.code == 11 - assert exception.msg == "No connection to aerospike cluster." + response = unconnected_client.get_node_names() + assert response is not None diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index 46f15ea6e..07ce001c9 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -44,9 +44,5 @@ def test_pos_get_nodes_without_connection(self): config = self.connection_config.copy() unconnected_client = aerospike.client(config) - try: - unconnected_client.get_nodes() - - except e.ClusterError as exception: - assert exception.code == 11 - assert exception.msg == "No connection to aerospike cluster" + response = unconnected_client.get_nodes() + assert response is not None diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 1b1109ec3..2638f225a 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -235,19 +235,6 @@ def test_neg_get_remove_key_and_check_get(self, _input, _expected, put_data): except e.RecordNotFound as exception: assert exception.code == 2 - def test_get_with_only_key_no_connection(self): - """ - Invoke get() with a key and not policy's dict no connection - """ - key = ('test', 'demo', 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - - try: - client1.get(key) - except e.RecordNotFound as exception: - assert exception.code == 2 - # Put Tests def test_pos_put_with_policy_exists_create_or_replace(self): """ @@ -750,6 +737,7 @@ def test_put_with_string_record_without_connection(self): bins = {"name": "John"} assert 0 == client1.put(key, bins) + self.as_connection.remove(key) @pytest.mark.parametrize( "key, record, meta, policy, ex_code, ex_msg", diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index a74f7d4e8..d9209f794 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -446,6 +446,8 @@ def test_createindex_with_correct_parameters_without_connection(self): assert 0 == client1.index_integer_create( 'test', 'demo', 'age', 'age_index', policy) + self.as_connection.index_remove('test', 'age_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'age_index') def test_index_remove_no_args(self): diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index 131c766f9..1008131a8 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -5,7 +5,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestIsConnected(object): def setup_class(cls): """ @@ -27,7 +26,8 @@ def _connect(self): def test_is_connected_before_connect(self): """ - Test that is_connected returns false before a connection is established + Client call itself establishes connection. + Connect/Close are deprecated and no-op to client """ client = aerospike.client(self.config) assert client.is_connected() is True @@ -52,8 +52,8 @@ def test_pos_is_connected_after_multiple_connects(self): def test_is_connected_after_close(self): """ - Test that is_connected returns True after a successful calls to - connect() and close() (deprecated and it is no-op) + Client call itself establishes connection. + Connect/Close are deprecated and no-op to client """ self._connect() assert self.client.is_connected() is True diff --git a/test/new_tests/test_list_index.py b/test/new_tests/test_list_index.py index a69fb4467..672c067c4 100644 --- a/test/new_tests/test_list_index.py +++ b/test/new_tests/test_list_index.py @@ -351,13 +351,14 @@ def test_neg_listindex_with_correct_parameters_no_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - try: - client1.index_list_create( - "test", "demo", "string_list", aerospike.INDEX_STRING, "test_string_list_index", policy - ) + retobj = client1.index_list_create( + 'test', 'demo', 'string_list', aerospike.INDEX_STRING, + 'test_string_list_index', policy) - except e.ClusterError as exception: - assert exception.code == 11 + assert retobj == 0 + self.as_connection.index_remove('test', 'test_string_list_index', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_list_index') def test_neg_listindex_with_no_paramters(self): """ diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index 6f7333a96..47ca884de 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -342,3 +342,5 @@ def test_mapkeysindex_with_correct_parameters_no_connection(self): 'test_string_map_index', policy) assert retval == 0 + self.as_connection.index_remove('test', 'test_string_map_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index 470afdd06..58bfa9002 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -71,7 +71,6 @@ def remove_indexes_from_client(client): client.index_remove("test", "test_null_age_idx") -@pytest.mark.usefixtures("connection_config") class TestQueryApply(object): # These functions will run once for this test class, and do all of the @@ -322,7 +321,7 @@ def test_stream_udf_parameters(self): that accepts additional arguments. """ query_results = self.as_connection.query( - "test", "demo" + "test", "demo", ).apply( 'query_apply_parameters', 'query_params', [['age', 5]] ).results() @@ -407,7 +406,7 @@ def test_stream_udf_parameters_with_serialized_set(self): arguments contain a serialized set. """ query_results = self.as_connection.query( - "test", "demo" + "test", "demo", ).apply( 'query_apply_parameters', 'query_params', [['age', 5] ,pickle.dumps({'lary', 'quinton', 'julie', 'mark'})] @@ -422,7 +421,7 @@ def test_stream_udf_complicated_parameters(self): that accepts additional arguments. """ query_results = self.as_connection.query( - "test", "demo" + "test", "demo", ).apply( 'query_apply_parameters', 'query_params', [['age', 2], ['id', ['john', ['hi']], ['john', {'mary' : 39}]], []] diff --git a/test/new_tests/test_remove_bin.py b/test/new_tests/test_remove_bin.py index 903c3b05d..8c678b222 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -6,7 +6,6 @@ @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") class TestRemovebin(object): @pytest.mark.parametrize( "key, record, bin_for_removal", @@ -247,17 +246,6 @@ def test_neg_remove_bin_with_none(self, key, bin_for_removal, ex_code, ex_msg): assert exception.code == ex_code assert exception.msg == ex_msg - def test_remove_bin_with_correct_parameters_without_connection(self, put_data): - """ - Invoke remove_bin() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - key = ('test', 'demo', 1) - put_data(client1, key, {'name': "jeff", 'age': 45}) - - client1.remove_bin(key, ["age"]) def test_neg_remove_bin_with_incorrect_meta(self): """ diff --git a/test/new_tests/test_scan_apply.py b/test/new_tests/test_scan_apply.py index 592b3ed9c..8f7ffdec4 100644 --- a/test/new_tests/test_scan_apply.py +++ b/test/new_tests/test_scan_apply.py @@ -345,9 +345,9 @@ def test_scan_apply_with_correct_parameters_without_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - client1.scan_apply( + response = client1.scan_apply( "test", "demo", "bin_lua", "mytransform", ['age', 2]) - + assert response is not None def test_scan_apply_with_incorrect_policy(self): """ Invoke scan_apply() with incorrect policy diff --git a/test/new_tests/test_select.py b/test/new_tests/test_select.py index 3a162db53..377d26c0e 100644 --- a/test/new_tests/test_select.py +++ b/test/new_tests/test_select.py @@ -182,8 +182,8 @@ def test_select_with_key_and_bins_without_connection(self): config = self.connection_config disconnected_client = aerospike.client(config) - disconnected_client.select(self.test_key, bins_to_select) - + _, _, bins = disconnected_client.select(self.test_key, bins_to_select) + assert bins is not None def test_select_with_invalid_keys(self, invalid_key): """ Verify that different types of invalid keys will diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index ca186a81d..f29180af4 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -107,7 +107,7 @@ def test_udf_list_with_wrong_policy_type(self, policy): def test_udf_list_with_proper_parameters_without_connection(self): """ - Test to verify error raised by trying to call udf_list without + Test to verify call to udf_list without first calling connect """ config = self.connection_config.copy() @@ -116,4 +116,5 @@ def test_udf_list_with_proper_parameters_without_connection(self): policy = {"timeout": 0} - client1.udf_list(policy) + udf_list = client1.udf_list(policy) + assert udf_list is not None diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index 1f9f6c6d7..71c57edde 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -8,7 +8,6 @@ from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist import aerospike from aerospike import exception as e -from .test_base_class import TestBaseClass def is_greater_451(version_str): @@ -18,7 +17,6 @@ def is_greater_451(version_str): return LooseVersion(version_str) >= LooseVersion("4.5.1") -@pytest.mark.usefixtures("connection_config") class TestUdfRemove(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -134,7 +132,6 @@ def test_udf_remove_with_unicode_filename(self): @pytest.mark.usefixtures("connection_with_udf") -@pytest.mark.usefixtures("connection_config") class TestIncorrectCallsToUDFRemove(object): """ These are all tests where udf_remove fails for various reasons, @@ -147,18 +144,6 @@ def setup_class(cls): """ cls.udf_to_load = "example.lua" - def test_udf_remove_with_proper_parameters_without_connection(self): - """ - Test to verify that attempting to remove a UDF before connection - raises an error - """ - config = self.connection_config.copy() - - client1 = aerospike.client(config) - policy = {"timeout": 100} - module = "example.lua" - - client1.udf_remove(module, policy) def test_udf_remove_with_non_existent_module(self): """ From 8ce95b2665786e9ba8dbe06e051b068e10da46d9 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Tue, 11 Oct 2022 17:48:23 +0530 Subject: [PATCH 06/27] release note and test case update --- Releases.md | 96 ++++++++++++++++ src/main/client/type.c | 145 ------------------------ test/config.conf | 6 +- test/new_tests/test_append.py | 2 +- test/new_tests/test_apply.py | 4 +- test/new_tests/test_cdt_index.py | 16 ++- test/new_tests/test_connect.py | 3 - test/new_tests/test_exists.py | 5 +- test/new_tests/test_exists_many.py | 4 +- test/new_tests/test_expressions_list.py | 16 +-- test/new_tests/test_get_async.py | 2 +- test/new_tests/test_get_put.py | 2 +- test/new_tests/test_increment.py | 2 +- test/new_tests/test_index.py | 2 - test/new_tests/test_info_all.py | 4 +- test/new_tests/test_info_random_node.py | 2 +- test/new_tests/test_info_single_node.py | 2 +- test/new_tests/test_list_append.py | 4 +- test/new_tests/test_list_index.py | 9 +- test/new_tests/test_mapkeys_index.py | 8 +- test/new_tests/test_mapvalues_index.py | 106 ++++++++--------- test/new_tests/test_operate.py | 2 +- test/new_tests/test_operate_helpers.py | 2 +- test/new_tests/test_operate_ordered.py | 2 +- test/new_tests/test_prepend.py | 3 +- test/new_tests/test_query.py | 7 +- test/new_tests/test_query_apply.py | 72 ++++++++---- test/new_tests/test_remove.py | 3 +- test/new_tests/test_remove_bin.py | 1 - test/new_tests/test_scan_apply.py | 4 +- test/new_tests/test_select.py | 1 + test/new_tests/test_select_many.py | 3 +- test/new_tests/test_udf_remove.py | 1 - test/test_cases.py | 8 +- 34 files changed, 252 insertions(+), 297 deletions(-) diff --git a/Releases.md b/Releases.md index 3cc4b4f68..f8df9a1db 100644 --- a/Releases.md +++ b/Releases.md @@ -1,3 +1,99 @@ +# Version 7.2.0 +date: 10/14/2022 + +## Bug Fixes + + - [CLIENT-1854] - Python client crashes while doing IO during server upgrade/downgrade + +## Deprecations​ + + - client().connect() has been deprecated and it is an no-op. Client call itself establishes the connection object. + - client().close() has been deprecated and it is an no-op. Client destroy unwinds the conection. + + +# Version 7.1.1 +date: 10/03/2022 + +## Bug Fixes + + - [CLIENT-1784] - Potential Memory leak with Python client. + +## Improvements + + - [CLIENT-1830] - Add CDT CTX base64 method for using sindex-create info command. + - [CLIENT-1825] - Expose ttl as part query object attributes. + +# Version 7.1.0 +date: 09/09/2022 + +## Bug Fixes + + - [CLIENT-1810] - Read policy POLICY_KEY_SEND is not respected when set at the client level. + +## New Features + + - [CLIENT-1799] - Support batch read operations. + +## Improvements + + - [CLIENT-1749] - Add 'EXISTS' return type for CDT read operations. + - [CLIENT-1801] - Support creating an secondary index on elements within a CDT using context. + - [CLIENT-1795] - Make c-client "fail_if_not_connected" option configurable. + - [CLIENT-1791] - Review and clean up Sphinx documentation. + - [CLIENT-1792] - Update build instructions. + +# Version 7.0.2 +date: 05/31/2022 + +## Bug Fixes + + - [CLIENT-1742] - Fix reference count leaks in client 7.x Batch APIs. + - [CLIENT-1753] - Fix reference count leak in cdt_ctx map_key_create and list_index_create cases. + - [CLIENT-1710] - Change BatchRecords default argument from an empty list to None. + +# Version 7.0.1 +date: 04/18/2022 + +## Bug Fixes + + - [CLIENT-1708] Fix 'Unable to load batch_records module' error when batch_operate, batch_apply, or batch_remove are used without importing aerospike_helpers.batch.records. + +# Version 7.0.0 +date: 4/06/2022 + +## Breaking Changes + + - Old predexp support has been removed. See [Incompatible API Changes](https://developer.aerospike.com/client/python/usage/incompatible#version-700) for details. + - Remove support for deprecated Debian 8. + - IndexNotFound and IndexNotReadable errors can now trigger retries. + - Bytes blobs read from the database will now be read as bytes instead of bytearray. See [Incompatible API Changes](https://developer.aerospike.com/client/python/usage/incompatible#version-700) for details. + - Query policies max_records and records_per_second are now fields of the Query class. See [Incompatible API Changes](https://developer.aerospike.com/client/python/usage/incompatible#version-700) for details. + +## Features + + - [CLIENT-1651] - Provide an API to extract an expression's base-64 representation. + - [CLIENT-1655] - Support new 6.0 truncate, udf-admin, and sindex-admin privileges. This feature requires server version 6.0+. + - [CLIENT-1659] - Support batch_write, batch_apply, batch_operate, and batch_remove client methods. This feature requires server version 6.0+. + - [CLIENT-1658] - Support partition queries. This feature requires server version 6.0+. + - [CLIENT-1690] - Support get_partitions_status for Scan objects. + - [CLIENT-1693] - Add short_query query policy. This feature requires server version 6.0+. + +## Improvements + + - [CLIENT-1687] - Deprecate send_set_name batch policy. Batch transactions now always send set name to the server. + - [CLIENT-1681] - Drop predexp support. + - [CLIENT-1683] - Add max retries exceeded exception. + - [CLIENT-1691] - Document partition scan functionality. + - [CLIENT-1692] - Update C client to 6.0. + - [CLIENT-1657] - Move Python client CI tests to github actions. + - [CLIENT-1694] - Make query policies max_records and records_per_second Query fields instead. + - [CLIENT-1675] - Bytes blobs read from the database will now be read as bytes instead of bytearray. + - [CLIENT-1634] - Remove support for deprecated Debian 8. + +## Updates + + - [Aerospike C Client 6.0.0.](/download/client/c/notes.html#6.0.0) + # Version 6.1.2 ## Fixes diff --git a/src/main/client/type.c b/src/main/client/type.c index 7afae9305..308e7a05e 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1260,150 +1260,6 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, * Set the individual policy groups new in 3.0 * */ -<<<<<<< HEAD - if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - - PyObject *py_login_timeout = - PyDict_GetItemString(py_policies, "login_timeout_ms"); - if (py_login_timeout && PyInt_Check(py_login_timeout)) { - config.login_timeout_ms = PyInt_AsLong(py_login_timeout); - } - - PyObject *py_auth_mode = PyDict_GetItemString(py_policies, "auth_mode"); - if (py_auth_mode) { - if (PyInt_Check(py_auth_mode)) { - long auth_mode = PyInt_AsLong(py_auth_mode); - if ((long)AS_AUTH_INTERNAL == auth_mode || - (long)AS_AUTH_EXTERNAL == auth_mode || - (long)AS_AUTH_EXTERNAL_INSECURE == auth_mode || - (long)AS_AUTH_PKI == auth_mode) { - config.auth_mode = auth_mode; - } - else { - error_code = INIT_INVALID_AUTHMODE_ERR; - goto CONSTRUCTOR_ERROR; - } - } - else { - //it may come like auth_mode = None, for those non-integer cases, treat them as non-set - //error_code = INIT_INVALID_AUTHMODE_ERR; - //goto CONSTRUCTOR_ERROR; - } - } - } - - // thread_pool_size - PyObject *py_thread_pool_size = - PyDict_GetItemString(py_config, "thread_pool_size"); - if (py_thread_pool_size && PyInt_Check(py_thread_pool_size)) { - config.thread_pool_size = PyInt_AsLong(py_thread_pool_size); - } - - // max_threads (backward compatibility) - PyObject *py_max_threads = PyDict_GetItemString(py_config, "max_threads"); - if (py_max_threads && - (PyInt_Check(py_max_threads) || PyLong_Check(py_max_threads))) { - config.max_conns_per_node = PyInt_AsLong(py_max_threads); - } - - // max_conns_per_node - PyObject *py_max_conns = - PyDict_GetItemString(py_config, "max_conns_per_node"); - if (py_max_conns && - (PyInt_Check(py_max_conns) || PyLong_Check(py_max_conns))) { - config.max_conns_per_node = PyInt_AsLong(py_max_conns); - } - - //conn_timeout_ms - PyObject *py_connect_timeout = - PyDict_GetItemString(py_config, "connect_timeout"); - if (py_connect_timeout && PyInt_Check(py_connect_timeout)) { - config.conn_timeout_ms = PyInt_AsLong(py_connect_timeout); - } - - //Whether to utilize shared connection - PyObject *py_share_connect = - PyDict_GetItemString(py_config, "use_shared_connection"); - if (py_share_connect) { - self->use_shared_connection = PyObject_IsTrue(py_share_connect); - } - - PyObject *py_send_bool_as = PyDict_GetItemString(py_config, "send_bool_as"); - if (py_send_bool_as != NULL && PyLong_Check(py_send_bool_as)) { - int send_bool_as_temp = PyLong_AsLong(py_send_bool_as); - if (send_bool_as_temp >= SEND_BOOL_AS_PY_BYTES && - send_bool_as_temp <= SEND_BOOL_AS_AS_BOOL) { - self->send_bool_as = send_bool_as_temp; - } - } - - //compression_threshold - PyObject *py_compression_threshold = - PyDict_GetItemString(py_config, "compression_threshold"); - if (py_compression_threshold && PyInt_Check(py_compression_threshold)) { - int compression_value = PyInt_AsLong(py_compression_threshold); - if (compression_value >= 0) { - config.policies.write.compression_threshold = compression_value; - } - else { - error_code = INIT_COMPRESSION_ERR; - goto CONSTRUCTOR_ERROR; - } - } - - PyObject *py_tend_interval = - PyDict_GetItemString(py_config, "tend_interval"); - if (py_tend_interval && PyInt_Check(py_tend_interval)) { - config.tender_interval = PyInt_AsLong(py_tend_interval); - } - - PyObject *py_cluster_name = PyDict_GetItemString(py_config, "cluster_name"); - if (py_cluster_name && PyString_Check(py_cluster_name)) { - as_config_set_cluster_name(&config, - strdup(PyString_AsString(py_cluster_name))); - } - - //strict_types check - self->strict_types = true; - PyObject *py_strict_types = PyDict_GetItemString(py_config, "strict_types"); - if (py_strict_types && PyBool_Check(py_strict_types)) { - if (Py_False == py_strict_types) { - self->strict_types = false; - } - } - - if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - - PyObject *py_max_socket_idle = NULL; - py_max_socket_idle = PyDict_GetItemString(py_config, "max_socket_idle"); - if (py_max_socket_idle && PyInt_Check(py_max_socket_idle)) { - long max_socket_idle = PyInt_AsLong(py_max_socket_idle); - if (max_socket_idle >= 0) { - config.max_socket_idle = (uint32_t)max_socket_idle; - } - } - - PyObject *py_fail_if_not_connected = - PyDict_GetItemString(py_config, "fail_if_not_connected"); - if (py_fail_if_not_connected && PyBool_Check(py_fail_if_not_connected)) { - config.fail_if_not_connected = - PyObject_IsTrue(py_fail_if_not_connected); - } - - self->as = aerospike_new(&config); - - return 0; -======= if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { error_code = INIT_POLICY_PARAM_ERR; goto CONSTRUCTOR_ERROR; @@ -1557,7 +1413,6 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, } return 0; ->>>>>>> 2c363b40 (establish connection while constructing client object, passthrough connect/close calls) CONSTRUCTOR_ERROR: diff --git a/test/config.conf b/test/config.conf index 0f41603c0..226f4bcc7 100644 --- a/test/config.conf +++ b/test/config.conf @@ -2,6 +2,6 @@ hosts : 127.0.0.1:3000 [enterprise-edition] -hosts : -user : -password : +hosts :172.17.0.3:3000 +user :generic_client +password :generic_client diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index d53a29706..2c69e0b03 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -437,7 +437,7 @@ def test_append_with_correct_parameters_without_connection(self): (key, _, bins) = self.as_connection.get(key) - assert bins == {'age': 1, 'name': 'name1', 'name2': 'str'} + assert bins == {"age": 1, "name": "name1", "name2": "str"} def test_neg_append_with_low_timeout(self): """ diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index 8781bc04d..2715ee548 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -297,11 +297,11 @@ def test_apply_with_correct_parameters_without_connection(self): """ Invoke apply() with correct arguments without connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) - retval = client1.apply(key, 'sample', 'list_append', ['name', 'car']) + retval = client1.apply(key, "sample", "list_append", ["name", "car"]) assert retval == 0 diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index c2c1ec5eb..6a70db7a7 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -706,13 +706,17 @@ def test_cdtindex_with_correct_parameters_no_connection(self): client1 = aerospike.client(config) client1.index_cdt_create( - 'test', 'demo', 'string_list', aerospike.INDEX_TYPE_LIST, + "test", + "demo", + "string_list", + aerospike.INDEX_TYPE_LIST, aerospike.INDEX_STRING, - 'test_string_list_cdt_index', {'ctx': ctx_list_index}, policy) - self.as_connection.index_remove('test', 'test_string_list_cdt_index', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_list_cdt_index') - + "test_string_list_cdt_index", + {"ctx": ctx_list_index}, + policy, + ) + self.as_connection.index_remove("test", "test_string_list_cdt_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_list_cdt_index") def test_neg_cdtindex_with_no_paramters(self): """ diff --git a/test/new_tests/test_connect.py b/test/new_tests/test_connect.py index 4a491812e..cca945a77 100644 --- a/test/new_tests/test_connect.py +++ b/test/new_tests/test_connect.py @@ -138,9 +138,6 @@ def test_connect_positive_cluster_name(self): assert err_info.value.code == -1 def test_connect_positive_reconnect(self): - """ - Connect/Close are deprecated and no-op to client - """ config = self.connection_config.copy() with open_as_connection(config) as client: diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 97045c39b..bcd56b347 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -14,8 +14,7 @@ class SomeClass(object): @pytest.mark.usefixtures("as_connection") @pytest.mark.usefixtures("connection_config") -class TestExists(): - +class TestExists: @pytest.mark.parametrize("key, record", test_data.pos_data) def test_pos_exists_with_diff_datatype(self, key, record, put_data): """ @@ -109,7 +108,7 @@ def test_exists_with_only_key_without_connection(self): """ Invoke exists() with a key and not policy's dict and no connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 41d7ebd38..74a85cd41 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -13,8 +13,7 @@ @pytest.mark.usefixtures("as_connection") -class TestExistsMany(): - +class TestExistsMany: def test_pos_exists_many_without_policy(self, put_data): self.keys = [] rec_length = 5 @@ -195,7 +194,6 @@ def test_neg_exists_many_with_invalid_timeout(self, put_data): with pytest.raises(e.ParamError): self.as_connection.exists_many(self.keys, policies) - def test_neg_exists_many_with_extra_parameter_in_key(self, put_data): keys = [] key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) diff --git a/test/new_tests/test_expressions_list.py b/test/new_tests/test_expressions_list.py index dd3bbb1b8..4489f55a6 100644 --- a/test/new_tests/test_expressions_list.py +++ b/test/new_tests/test_expressions_list.py @@ -595,18 +595,14 @@ def test_list_read_ops_pos(self, bin, values): "ilist_bin", None, {"write_flags": aerospike.LIST_WRITE_ADD_UNIQUE}, - [ - 20, [3, 9], 4, [24, 25], 10, 1, [2, 6], None, 3, 6, 2 - ], + [20, [3, 9], 4, [24, 25], 10, 1, [2, 6], None, 3, 6, 2], [[1, 2, 3, 4, 6, 9, 20], [10, 24, 25], [1], []], ), ( "slist_bin", None, {}, - [ - "h", ["e", "g"], "c", ["x", "y"], "b", "b", ["d", "f"], "b", None, "f", "d" - ], + ["h", ["e", "g"], "c", ["x", "y"], "b", "b", ["d", "f"], "b", None, "f", "d"], [ ["b", "c", "d", "e", "f", "g", "h"], [ @@ -660,18 +656,14 @@ def test_list_read_ops_pos(self, bin, values): "bylist_bin", None, {}, - [ - b"h", [b"e", b"g"], b"c", [b"x", b"y"], b"b", b"b", [b"d", b"f"], b"b", b"e", b"f", b"d" - ], + [b"h", [b"e", b"g"], b"c", [b"x", b"y"], b"b", b"b", [b"d", b"f"], b"b", b"e", b"f", b"d"], [[b"b", b"c", b"d", b"e", b"f", b"g", b"h"], [b"b", b"x", b"y"], [b"b"], []], ), ( "flist_bin", None, {}, - [ - 20.0, [3.0, 9.0], 4.0, [24.0, 25.0], 10.0, 1.0, [2.0, 6.0], 1.0, 3.0, 6.0, 2.0 - ], + [20.0, [3.0, 9.0], 4.0, [24.0, 25.0], 10.0, 1.0, [2.0, 6.0], 1.0, 3.0, 6.0, 2.0], [[1.0, 2.0, 3.0, 4.0, 6.0, 9.0, 20.0], [10.0, 24.0, 25.0], [1.0], []], ), ], diff --git a/test/new_tests/test_get_async.py b/test/new_tests/test_get_async.py index 61f059ede..4551512dd 100644 --- a/test/new_tests/test_get_async.py +++ b/test/new_tests/test_get_async.py @@ -245,7 +245,7 @@ async def test_get_with_only_key_no_connection(self): """ Invoke get() with a key and not policy's dict no connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 2638f225a..a3260cac4 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -733,7 +733,7 @@ def test_put_with_string_record_without_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - key = ('test', 'demo', 1) + key = ("test", "demo", 1) bins = {"name": "John"} assert 0 == client1.put(key, bins) diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 8c7a44857..827ea0bbe 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -342,7 +342,7 @@ def test_increment_with_correct_parameters_without_connection(self): """ Invoke increment() with correct parameters without connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index d9209f794..7d9bf97d1 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -8,8 +8,6 @@ import aerospike @pytest.mark.usefixtures("connection_config") -class TestIndex(object): - class TestIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index e1481a6cd..b88fd9fdf 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -90,9 +90,9 @@ def test_info_all_without_connection(self): """ client1 = aerospike.client(self.connection_config) - nodes_info = client1.info_all('sets') + nodes_info = client1.info_all("sets") assert nodes_info is not None - + def test_info_all_with_invalid_policy_type(self): """ Test that sending a non dict/None as policy raises an error diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index 1681ecd17..26f403f22 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -135,7 +135,7 @@ def test_info_random_node_positive_without_connection(self): Test info with correct arguments without connection. """ client1 = aerospike.client(self.connection_config) - response = client1.info_random_node('bins') + response = client1.info_random_node("bins") assert response is not None def test_info_random_node_positive_with_extra_parameters(self): diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index 81388347d..246ebed5d 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -141,7 +141,7 @@ def test_info_single_node_positive_without_connection(self): """ client1 = aerospike.client(self.connection_config) with pytest.raises(e.ParamError) as err_info: - client1.info_single_node('bins', self.connection_config['hosts'][0][:2]) + client1.info_single_node("bins", self.connection_config["hosts"][0][:2]) def test_info_single_node_positive_with_extra_parameters(self): """ diff --git a/test/new_tests/test_list_append.py b/test/new_tests/test_list_append.py index c296705af..96cf7e1c3 100644 --- a/test/new_tests/test_list_append.py +++ b/test/new_tests/test_list_append.py @@ -221,6 +221,6 @@ def test_neg_list_append_meta_type_integer(self): def test_list_append_with_no_connection(self): config = self.connection_config.copy() client = aerospike.client(config) - k = ('test', 'demo', 'no_con') - response = client.list_append(k, 'bob', 'item') + k = ("test", "demo", "no_con") + response = client.list_append(k, "bob", "item") assert response is not None diff --git a/test/new_tests/test_list_index.py b/test/new_tests/test_list_index.py index 672c067c4..51923b146 100644 --- a/test/new_tests/test_list_index.py +++ b/test/new_tests/test_list_index.py @@ -352,13 +352,12 @@ def test_neg_listindex_with_correct_parameters_no_connection(self): client1 = aerospike.client(config) retobj = client1.index_list_create( - 'test', 'demo', 'string_list', aerospike.INDEX_STRING, - 'test_string_list_index', policy) + "test", "demo", "string_list", aerospike.INDEX_STRING, "test_string_list_index", policy + ) assert retobj == 0 - self.as_connection.index_remove('test', 'test_string_list_index', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_list_index') + self.as_connection.index_remove("test", "test_string_list_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_list_index") def test_neg_listindex_with_no_paramters(self): """ diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index 47ca884de..04bb9c32a 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -338,9 +338,9 @@ def test_mapkeysindex_with_correct_parameters_no_connection(self): client1 = aerospike.client(config) retval = client1.index_map_keys_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retval == 0 - self.as_connection.index_remove('test', 'test_string_map_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 2c9bad48e..546a103f6 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -57,13 +57,12 @@ def test_mapvaluesindex_with_correct_parameters(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index1', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index1', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') + self.as_connection.index_remove("test", "test_string_map_index1", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") def test_mapvaluesindex_with_correct_parameters_no_policy(self): """ @@ -71,12 +70,12 @@ def test_mapvaluesindex_with_correct_parameters_no_policy(self): and the policy argument not passed """ retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index2') + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index2" + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index2') - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index2') + self.as_connection.index_remove("test", "test_string_map_index2") + ensure_dropped_index(self.as_connection, "test", "test_string_map_index2") def test_mapvaluesindex_with_correct_parameters_numeric(self): """ @@ -100,9 +99,8 @@ def test_mapvalues_index_with_correct_parameters_set_length_extra(self): policy = {} with pytest.raises(e.InvalidRequest) as err_info: self.as_connection.index_map_values_create( - 'test', set_name, - 'string_map', aerospike.INDEX_STRING, - "test_string_map_index3", policy) + "test", set_name, "string_map", aerospike.INDEX_STRING, "test_string_map_index3", policy + ) err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_REQUEST_INVALID @@ -140,23 +138,22 @@ def test_mapvaluesindex_with_incorrect_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map1', aerospike.INDEX_STRING, - 'test_string_map_index4', policy) + "test", "demo", "string_map1", aerospike.INDEX_STRING, "test_string_map_index4", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index4', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index4') + self.as_connection.index_remove("test", "test_string_map_index4", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index4") @pytest.mark.parametrize( "test_ns, test_set, test_bin, test_idx_name", ( - (None, 'demo', 'string_map', 'test_string_map_index5'), - (1, 'demo', 'string_map', 'test_string_map_index6'), - ('test', 1, 'string_map', 'test_string_map_index7'), - ('test', 'demo', None, 'test_string_map_index8'), - ('test', 'demo', 'string_map', None), - ('test', 'demo', 'string_map', 1), + (None, "demo", "string_map", "test_string_map_index5"), + (1, "demo", "string_map", "test_string_map_index6"), + ("test", 1, "string_map", "test_string_map_index7"), + ("test", "demo", None, "test_string_map_index8"), + ("test", "demo", "string_map", None), + ("test", "demo", "string_map", 1), ), ids=("ns is None", "ns is int", "set is int", "bin is None", "index name is none", "index name is int"), ) @@ -179,12 +176,11 @@ def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): with pytest.raises(e.ParamError) as err_info: self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', idx_val, - "test_string_map_index9", policy) + "test", "demo", "string_map", idx_val, "test_string_map_index9", policy + ) try: - self.as_connection.index_remove( - 'test', 'test_string_map_index9') - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index9') + self.as_connection.index_remove("test", "test_string_map_index9") + ensure_dropped_index(self.as_connection, "test", "test_string_map_index9") except: pass @@ -220,21 +216,19 @@ def test_create_same_mapvaluesindex_multiple_times_different_bin(self): policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index10', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index10", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK with pytest.raises(e.IndexFoundError): retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'numeric_map', aerospike.INDEX_NUMERIC, - 'test_string_map_index10', policy) - self.as_connection.index_remove( - 'test', 'test_string_map_index10', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index10') + "test", "demo", "numeric_map", aerospike.INDEX_NUMERIC, "test_string_map_index10", policy + ) + self.as_connection.index_remove("test", "test_string_map_index10", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index10") - self.as_connection.index_remove( - 'test', 'test_string_map_index10', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index10') + self.as_connection.index_remove("test", "test_string_map_index10", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index10") def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ @@ -243,26 +237,23 @@ def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index11', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index11", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK try: retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index1', policy) - self.as_connection.index_remove( - 'test', 'test_string_map_index1', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') - self.as_connection.index_remove( - 'test', 'test_string_map_index11', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index11') + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy + ) + self.as_connection.index_remove("test", "test_string_map_index1", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") + self.as_connection.index_remove("test", "test_string_map_index11", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index11") except e.IndexFoundError: assert self.server_version < [6, 1] - self.as_connection.index_remove( - 'test', 'test_string_map_index11', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index11') + self.as_connection.index_remove("test", "test_string_map_index11", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index11") def test_createmapvaluesindex_with_policy(self): """ @@ -283,13 +274,12 @@ def test_createmapvaluesindex_with_policystring(self): """ policy = {"timeout": 1000} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index12', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index12", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index12', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index12') + self.as_connection.index_remove("test", "test_string_map_index12", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index12") """ This test case causes a db crash and hence has been commented. Work pending @@ -345,7 +335,7 @@ def test_mapvaluesindex_with_correct_parameters_no_connection(self): client1 = aerospike.client(config) retval = client1.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index13', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index13", policy + ) assert retval == 0 diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index 82dd0d8ee..88ff4bcbf 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -530,7 +530,7 @@ def test_pos_operate_with_correct_paramters_without_connection(self): """ Invoke operate() with correct parameters without connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) llist = [ diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index 7b3b5d9a1..59e69b07c 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -442,7 +442,7 @@ def test_pos_operate_with_correct_paramters_without_connection(self): """ Invoke operate() with correct parameters without connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) llist = [operations.touch()] diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index 6409973b2..c5488e2f5 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -663,7 +663,7 @@ def test_neg_operate_ordered_without_connection(self): """ Invoke operate_ordered() with correct parameters without connection """ - key = ('test', 'demo', 1) + key = ("test", "demo", 1) config = self.connection_config.copy() client1 = aerospike.client(config) llist = [ diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index 1a5c1118b..f7051486e 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -6,8 +6,7 @@ @pytest.mark.usefixtures("connection_config") -class TestPrepend(): - +class TestPrepend: @pytest.fixture(autouse=True) def setup(self, request, as_connection): """ diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index b16fced4a..3146cd4db 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -966,16 +966,15 @@ def test_query_with_correct_parameters_without_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - query = client1.query('test', 'demo') - query.select('name', 'test_age') - query.where(p.equals('test_age', 1)) + query = client1.query("test", "demo") + query.select("name", "test_age") + query.where(p.equals("test_age", 1)) def callback(input_tuple): pass query.foreach(callback) - @pytest.mark.skip(reason="segfault") def test_query_predicate_range_wrong_no_args(self): """ """ diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index 58bfa9002..e222413e1 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -75,16 +75,29 @@ class TestQueryApply(object): # These functions will run once for this test class, and do all of the # required setup and teardown - connection_setup_functions = (add_test_udf, add_test_parameter_udf, add_indexes_to_client, create_records) - connection_teardown_functions = (drop_test_udf, drop_test_parameter_udf, remove_indexes_from_client, drop_records) age_range_pred = p.between("age", 0, 4) # Predicate for ages between [0,5) no_set_key = ("test", None, "no_set") # Key for item stored in a namespace but not in a set @pytest.fixture(autouse=True) def setup(self, request, connection_with_config_funcs): client = connection_with_config_funcs + add_test_udf(client) + add_test_parameter_udf(client) + add_indexes_to_client(client) create_records(client) + def teardown(): + """ + Teardown method + """ + + # drop_test_udf(client) + # drop_test_parameter_udf(client) + # remove_indexes_from_client(client) + # drop_records(client) + + request.addfinalizer(teardown) + def test_query_apply_with_no_parameters(self): """ Invoke query_apply() without any mandatory parameters. @@ -320,12 +333,15 @@ def test_stream_udf_parameters(self): Invoke query.apply() with a stream udf. that accepts additional arguments. """ - query_results = self.as_connection.query( - "test", "demo", - ).apply( - 'query_apply_parameters', 'query_params', [['age', 5]] - ).results() - + query_results = ( + self.as_connection.query( + "test", + "demo", + ) + .apply("query_apply_parameters", "query_params", [["age", 5]]) + .results() + ) + query_results.sort() assert query_results == [6, 7, 8, 9] @@ -405,13 +421,19 @@ def test_stream_udf_parameters_with_serialized_set(self): Invoke query.apply() with a stream udf. arguments contain a serialized set. """ - query_results = self.as_connection.query( - "test", "demo", - ).apply( - 'query_apply_parameters', 'query_params', [['age', 5] - ,pickle.dumps({'lary', 'quinton', 'julie', 'mark'})] - ).results() - + query_results = ( + self.as_connection.query( + "test", + "demo", + ) + .apply( + "query_apply_parameters", + "query_params", + [["age", 5], pickle.dumps({"lary", "quinton", "julie", "mark"})], + ) + .results() + ) + query_results.sort() assert query_results == [6, 7, 8, 9] @@ -420,13 +442,19 @@ def test_stream_udf_complicated_parameters(self): Invoke query.apply() with a stream udf. that accepts additional arguments. """ - query_results = self.as_connection.query( - "test", "demo", - ).apply( - 'query_apply_parameters', 'query_params', [['age', 2], - ['id', ['john', ['hi']], ['john', {'mary' : 39}]], []] - ).results() - + query_results = ( + self.as_connection.query( + "test", + "demo", + ) + .apply( + "query_apply_parameters", + "query_params", + [["age", 2], ["id", ["john", ["hi"]], ["john", {"mary": 39}]], []], + ) + .results() + ) + query_results.sort() assert query_results == [3, 4, 5, 6, 7, 8, 9] diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index bb54d7e63..0e74544d4 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -9,8 +9,7 @@ @pytest.mark.usefixtures("as_connection") @pytest.mark.usefixtures("connection_config") -class TestRemove(): - +class TestRemove: @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_existing_record(self): """ diff --git a/test/new_tests/test_remove_bin.py b/test/new_tests/test_remove_bin.py index 8c678b222..0cefb5990 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -246,7 +246,6 @@ def test_neg_remove_bin_with_none(self, key, bin_for_removal, ex_code, ex_msg): assert exception.code == ex_code assert exception.msg == ex_msg - def test_neg_remove_bin_with_incorrect_meta(self): """ Invoke remove_bin() with incorrect meta diff --git a/test/new_tests/test_scan_apply.py b/test/new_tests/test_scan_apply.py index 8f7ffdec4..39aca4d88 100644 --- a/test/new_tests/test_scan_apply.py +++ b/test/new_tests/test_scan_apply.py @@ -345,9 +345,9 @@ def test_scan_apply_with_correct_parameters_without_connection(self): config = self.connection_config.copy() client1 = aerospike.client(config) - response = client1.scan_apply( - "test", "demo", "bin_lua", "mytransform", ['age', 2]) + response = client1.scan_apply("test", "demo", "bin_lua", "mytransform", ["age", 2]) assert response is not None + def test_scan_apply_with_incorrect_policy(self): """ Invoke scan_apply() with incorrect policy diff --git a/test/new_tests/test_select.py b/test/new_tests/test_select.py index 377d26c0e..dffcced8f 100644 --- a/test/new_tests/test_select.py +++ b/test/new_tests/test_select.py @@ -184,6 +184,7 @@ def test_select_with_key_and_bins_without_connection(self): _, _, bins = disconnected_client.select(self.test_key, bins_to_select) assert bins is not None + def test_select_with_invalid_keys(self, invalid_key): """ Verify that different types of invalid keys will diff --git a/test/new_tests/test_select_many.py b/test/new_tests/test_select_many.py index cf60d8410..556ffe646 100644 --- a/test/new_tests/test_select_many.py +++ b/test/new_tests/test_select_many.py @@ -298,8 +298,7 @@ def test_select_many_with_proper_parameters_without_connection(self): filter_bins = ["title", "name"] - client1.select_many(self.keys, filter_bins, {'timeout': - 20}) + client1.select_many(self.keys, filter_bins, {"timeout": 20}) def test_select_many_with_invalid_keys(self, invalid_key): # invalid_key will be an invalid key_tuple, so we wrap diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index 71c57edde..68ba2187a 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -144,7 +144,6 @@ def setup_class(cls): """ cls.udf_to_load = "example.lua" - def test_udf_remove_with_non_existent_module(self): """ Test to ensure that the removal of a non existant UDF raises an Error diff --git a/test/test_cases.py b/test/test_cases.py index 531ed30ef..f67b2a10b 100644 --- a/test/test_cases.py +++ b/test/test_cases.py @@ -1158,8 +1158,8 @@ def get_aerospike(): # 'keyfile': "/Users/ramarajpandian/code/src/aerospike/enterprise/as-dev-infra/certs/Client-Chainless/key.pem", # noqa: E501 # 'for_login_only': True, # } - 'user':"generic_client", - 'password':"generic_client" + "user": "generic_client", + "password": "generic_client", } # Optionally set policies for various method types write_policies = {"total_timeout": 2000, "max_retries": 0, "key": aerospike.POLICY_KEY_SEND} @@ -1176,6 +1176,10 @@ def run(): # aerospike.set_log_level(aerospike.LOG_LEVEL_INFO) aeros = get_aerospike() + + config = {"hosts": [("bad_addr", 3000)]} + bad_client = aerospike.client(config) + # Connect once to establish a memory usage baseline. connect_to_cluster(aeros) From ca7cfb179cc9969309a0754f3ad6107ea8fbc1b4 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Tue, 11 Oct 2022 18:59:48 +0530 Subject: [PATCH 07/27] roll back and remove connect/close neg test cases which are no-op now --- test/new_tests/test_aggregate.py | 23 ----- test/new_tests/test_append.py | 16 --- test/new_tests/test_apply.py | 14 --- test/new_tests/test_cdt_index.py | 21 ---- test/new_tests/test_close.py | 22 +---- test/new_tests/test_connect.py | 4 + test/new_tests/test_exists.py | 28 ++---- test/new_tests/test_exists_many.py | 14 --- test/new_tests/test_get_async.py | 15 --- test/new_tests/test_get_many.py | 6 -- test/new_tests/test_get_node_names.py | 12 --- test/new_tests/test_get_nodes.py | 12 --- test/new_tests/test_get_put.py | 93 +++++------------- test/new_tests/test_get_udf.py | 12 --- test/new_tests/test_increment.py | 14 +-- test/new_tests/test_index.py | 12 --- test/new_tests/test_info.py | 12 --- test/new_tests/test_info_all.py | 9 -- test/new_tests/test_info_random_node.py | 8 -- test/new_tests/test_info_single_node.py | 8 -- test/new_tests/test_is_connected.py | 8 +- test/new_tests/test_job_info.py | 12 --- test/new_tests/test_list_append.py | 8 -- test/new_tests/test_list_index.py | 17 ---- test/new_tests/test_mapkeys_index.py | 21 +--- test/new_tests/test_mapvalues_index.py | 123 ++++++++++++------------ test/new_tests/test_operate.py | 20 ---- test/new_tests/test_operate_helpers.py | 11 --- test/new_tests/test_operate_ordered.py | 20 ---- test/new_tests/test_prepend.py | 18 +--- test/new_tests/test_put_async.py | 100 +++++-------------- test/new_tests/test_query.py | 17 ---- test/new_tests/test_query_apply.py | 23 ++--- test/new_tests/test_remove.py | 17 +--- test/new_tests/test_scan_apply.py | 11 --- test/new_tests/test_select.py | 9 -- test/new_tests/test_select_many.py | 10 -- test/new_tests/test_touch.py | 11 --- test/new_tests/test_udf_list.py | 15 --- test/new_tests/test_udf_put.py | 13 --- 40 files changed, 140 insertions(+), 699 deletions(-) diff --git a/test/new_tests/test_aggregate.py b/test/new_tests/test_aggregate.py index b34063718..b5288a2c8 100644 --- a/test/new_tests/test_aggregate.py +++ b/test/new_tests/test_aggregate.py @@ -261,29 +261,6 @@ def callback(value): except e.ClientError as exception: assert exception.code == -1 - def test_aggregate_with_correct_parameters_without_connection(self): - """ - Invoke aggregate() with correct arguments without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - try: - query = client1.query("test", "demo") - query.select("name", "test_age") - query.where(p.between("test_age", 1, 5)) - query.apply("stream_example", "count") - - records = [] - - def user_callback(value): - records.append(value) - - query.foreach(user_callback) - - except e.ClusterError as exception: - assert exception.code == 11 - def test_neg_aggregate_with_extra_parameter(self): """ Invoke aggregate() with extra parameter diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index 2c69e0b03..65c5dbfdd 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -7,8 +7,6 @@ # @pytest.mark.usefixtures("as_connection") -# adds cls.connection_config to this class -@pytest.mark.usefixtures("connection_config") class TestAppend(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -425,20 +423,6 @@ def test_neg_append_parameters_as_none(self, key, bin, ex_code, ex_msg): with pytest.raises(e.ParamError): self.as_connection.append(key, bin, "str") - def test_append_with_correct_parameters_without_connection(self): - """ - Invoke append() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - key = ("test", "demo", 1) - - client1.append(key, "name2", "str") - - (key, _, bins) = self.as_connection.get(key) - - assert bins == {"age": 1, "name": "name1", "name2": "str"} - def test_neg_append_with_low_timeout(self): """ Invoke append() with low timeout in policy diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index 2715ee548..c9b81ab54 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -90,8 +90,6 @@ def remove_indexes_and_udfs(client): client.udf_remove(module, policy) -# adds cls.connection_config to this class -@pytest.mark.usefixtures("connection_config") class TestApply(TestBaseClass): def setup_class(cls): # Register setup and teardown functions @@ -293,18 +291,6 @@ def test_apply_with_unicode_module_and_function(self): assert bins["name"] == ["name1", "car"] assert retval == 0 - def test_apply_with_correct_parameters_without_connection(self): - """ - Invoke apply() with correct arguments without connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - - retval = client1.apply(key, "sample", "list_append", ["name", "car"]) - - assert retval == 0 - def test_apply_with_arg_causing_error(self): """ Invoke apply() with ia string argument when integer is required diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 6a70db7a7..60415bb71 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -697,27 +697,6 @@ def test_neg_cdtindex_with_incorrect_set(self): self.as_connection.index_remove("test", "test_numeric_list_cdt_index", policy) ensure_dropped_index(self.as_connection, "test", "test_numeric_list_cdt_index") - def test_cdtindex_with_correct_parameters_no_connection(self): - """ - Invoke index_cdt_create() with correct arguments no connection - """ - policy = {} - config = self.connection_config.copy() - client1 = aerospike.client(config) - - client1.index_cdt_create( - "test", - "demo", - "string_list", - aerospike.INDEX_TYPE_LIST, - aerospike.INDEX_STRING, - "test_string_list_cdt_index", - {"ctx": ctx_list_index}, - policy, - ) - self.as_connection.index_remove("test", "test_string_list_cdt_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_list_cdt_index") - def test_neg_cdtindex_with_no_paramters(self): """ Invoke index_cdt_create() without any mandatory parameters. diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index f3cf740f1..cccc61bf4 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -14,7 +14,6 @@ sys.exit(1) -@pytest.mark.usefixtures("connection_config") class TestClose(): class TestClose: @@ -27,30 +26,14 @@ def setup_class(cls): def test_pos_close(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and no-op to client Invoke close() after positive connect """ self.client = TestBaseClass.get_new_connection() self.closeobject = self.client.close() assert self.closeobject is None - def test_pos_close_without_connection(self): - """ - Invoke close() without connection - """ - config = self.connection_config.copy() - self.client = aerospike.client(config) - - try: - self.closeobject = self.client.close() - - except e.ClusterError as exception: - assert exception.code == 11 - def test_neg_close(self): """ - Connect/Close are deprecated and no-op to client Invoke close() after negative connect """ config = {"hosts": [("127.0.0.1", 2000)]} @@ -63,8 +46,9 @@ def test_neg_close(self): def test_close_twice_in_a_row(self): """ - Connect/Close are deprecated and no-op to client - """ + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client + """ config = TestBaseClass.get_connection_config() if TestClose.user is None and TestClose.password is None: self.client = aerospike.client(config).connect() diff --git a/test/new_tests/test_connect.py b/test/new_tests/test_connect.py index cca945a77..961cffdd5 100644 --- a/test/new_tests/test_connect.py +++ b/test/new_tests/test_connect.py @@ -138,6 +138,10 @@ def test_connect_positive_cluster_name(self): assert err_info.value.code == -1 def test_connect_positive_reconnect(self): + """ + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client + """ config = self.connection_config.copy() with open_as_connection(config) as client: diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index bcd56b347..2dd59d541 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -13,8 +13,8 @@ class SomeClass(object): @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") -class TestExists: +class TestExists(): + @pytest.mark.parametrize("key, record", test_data.pos_data) def test_pos_exists_with_diff_datatype(self, key, record, put_data): """ @@ -104,24 +104,12 @@ def test_neg_exists_with_non_existent_data(self, key, ex, ex_code): except ex as exception: assert exception.code == ex_code - def test_exists_with_only_key_without_connection(self): - """ - Invoke exists() with a key and not policy's dict and no connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - - key, _ = client1.exists(key) - assert key is not None - - @pytest.mark.parametrize( - "key, record, meta, policy", - [ - (("test", "demo", 20), {"name": "John"}, {"gen": 3, "ttl": 1}, {"total_timeout": 2}), - ], - ) - def test_neg_exists_with_low_timeout(self, key, record, meta, policy, put_data): + @pytest.mark.parametrize("key, record, meta, policy", [ + (('test', 'demo', 20), {"name": "John"}, + {'gen': 3, 'ttl': 1}, {'total_timeout': 2}), + ]) + def test_neg_exists_with_low_timeout( + self, key, record, meta, policy, put_data): try: put_data(self.as_connection, key, record, meta, policy) except e.TimeoutError as exception: diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 74a85cd41..5ebefa269 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -26,20 +26,6 @@ def test_pos_exists_many_without_policy(self, put_data): assert isinstance(records, list) assert len(records) == rec_length - def test_pos_exists_many_with_proper_parameters_without_connection(self, put_data): - self.keys = [] - rec_length = 5 - for i in range(rec_length): - key = ("test", "demo", i) - record = {"name": "name%s" % (str(i)), "age": i} - put_data(self.as_connection, key, record) - self.keys.append(key) - records = self.as_connection.exists_many(self.keys, {"total_timeout": 1200}) - - assert isinstance(records, list) - assert len(records) == rec_length - assert Counter([x[0][2] for x in records]) == Counter([0, 1, 2, 3, 4]) - def test_pos_exists_many_with_none_policy(self, put_data): self.keys = [] rec_length = 5 diff --git a/test/new_tests/test_get_async.py b/test/new_tests/test_get_async.py index 4551512dd..39b57cd7f 100644 --- a/test/new_tests/test_get_async.py +++ b/test/new_tests/test_get_async.py @@ -239,18 +239,3 @@ async def async_io(key_input=None, policy_input=None): assert exception.code == 2 await asyncio.gather(async_io(_input)) - - @pytest.mark.asyncio - async def test_get_with_only_key_no_connection(self): - """ - Invoke get() with a key and not policy's dict no connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - - async def async_io(key_input=None, policy_input=None): - with pytest.raises(e.ClusterError): - key, _, _ = await io.get(client1, key_input) - - await asyncio.gather(async_io(key)) diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index a89c07bdc..7e5a6ec91 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -11,7 +11,6 @@ import aerospike from aerospike import exception as e -@pytest.mark.usefixtures("connection_config") class TestGetMany(): class TestGetMany: @@ -212,11 +211,6 @@ def test_neg_get_many_Invalid_Key_without_primary_key(self): with pytest.raises(e.ParamError): key, _, _ = self.as_connection.get(key) - def test_get_many_with_proper_parameters_without_connection(self): - config = self.connection_config.copy() - client1 = aerospike.client(config) - assert client1.get_many(self.keys, {'total_timeout': 20}) is not None - def test_neg_prepend_Invalid_Key_without_set_name(self): """ Invoke prepend() without set name diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index bdc05d8c8..e516a11a9 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -6,7 +6,6 @@ @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") class TestGetNodeNames(object): """ Test Cases for the use of aerospike.Client.get_node_names @@ -28,14 +27,3 @@ def test_pos_get_node_names(self): assert isinstance(response[0]["port"], int) assert isinstance(response[0]["node_name"], str) assert len(response[0]) == 3 - - # Tests for behaviors that raise errors - def test_pos_get_node_names_without_connection(self): - """ - Test that an attempt to call get_node_names before a connection - is established will raise the expected error - """ - config = self.connection_config.copy() - unconnected_client = aerospike.client(config) - response = unconnected_client.get_node_names() - assert response is not None diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index 07ce001c9..1a83d4876 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -34,15 +34,3 @@ def test_get_nodes_with_parameter(self): """ response = self.as_connection.get_nodes("parameter") assert response is not None - - # Tests for behaviors that raise errors - def test_pos_get_nodes_without_connection(self): - """ - Test that an attempt to call get_nodes before a connection - is established will raise the expected error - """ - config = self.connection_config.copy() - unconnected_client = aerospike.client(config) - - response = unconnected_client.get_nodes() - assert response is not None diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index a3260cac4..6d88bb62b 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -726,75 +726,30 @@ def test_neg_put_with_policy_gen_GT_lesser(self): assert {"name": "John"} == bins self.as_connection.remove(key) - def test_put_with_string_record_without_connection(self): - """ - Invoke put() for a record with string data without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - key = ("test", "demo", 1) - bins = {"name": "John"} - - assert 0 == client1.put(key, bins) - self.as_connection.remove(key) - - @pytest.mark.parametrize( - "key, record, meta, policy, ex_code, ex_msg", - [ - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": "wrong", "ttl": 25000}, - {"total_timeout": 1000}, # Gen as string - -2, - "Generation should be an int or long", - ), - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": 3, "ttl": "25000"}, - {"total_timeout": 1000}, # ttl as string - -2, - "TTL should be an int or long", - ), - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": 3, "ttl": 25000}, - {"total_timeout": "1000"}, # Timeout as string - -2, - "timeout is invalid", - ), - ( - ("test", "demo", 1), - {"name": "john"}, # Policy as string - {"gen": 3, "ttl": 25000}, - "Policy", - -2, - "policy must be a dict", - ), - ( - ("test", "demo", 1), - {"i": 13}, # Meta as string - "OK", - {"total_timeout": 1000}, - -2, - "meta must be a dict", - ), - ( - ("test", "demo", 1), - {"i": 13}, # Meta as string - 1234, - {"total_timeout": 1000}, - -2, - "meta must be a dict", - ), - ], - ) - def test_neg_put_with_invalid_metadata(self, key, record, meta, policy, ex_code, ex_msg, put_data): - """ - Invoke put() for a record with generation as string + @pytest.mark.parametrize("key, record, meta, policy, ex_code, ex_msg", [ + (('test', 'demo', 1), {'name': 'john'}, + {'gen': "wrong", 'ttl': 25000}, {'total_timeout': 1000}, # Gen as string + -2, "Generation should be an int or long"), + (('test', 'demo', 1), {'name': 'john'}, + {'gen': 3, 'ttl': "25000"}, {'total_timeout': 1000}, # ttl as string + -2, "TTL should be an int or long"), + (('test', 'demo', 1), {'name': 'john'}, + {'gen': 3, 'ttl': 25000}, {'total_timeout': "1000"}, # Timeout as string + -2, "timeout is invalid"), + (('test', 'demo', 1), {'name': 'john'}, # Policy as string + {'gen': 3, 'ttl': 25000}, "Policy", + -2, "policy must be a dict"), + (('test', 'demo', 1), {'i': 13}, # Meta as string + "OK", {'total_timeout': 1000}, + -2, "meta must be a dict"), + (('test', 'demo', 1), {'i': 13}, # Meta as string + 1234, {'total_timeout': 1000}, + -2, "meta must be a dict"), + ]) + def test_neg_put_with_invalid_metadata( + self, key, record, meta, policy, ex_code, ex_msg, put_data): + """ + Invoke put() for a record with generation as string """ with pytest.raises(e.ParamError): put_data(self.as_connection, key, record, meta, policy) diff --git a/test/new_tests/test_get_udf.py b/test/new_tests/test_get_udf.py index dab200531..63df167ba 100644 --- a/test/new_tests/test_get_udf.py +++ b/test/new_tests/test_get_udf.py @@ -8,7 +8,6 @@ @pytest.mark.usefixtures("connection_with_udf") -@pytest.mark.usefixtures("connection_config") class TestGetRegistered(object): def setup_class(cls): """ @@ -135,14 +134,3 @@ def test_invalid_module_arg_types(self, udf_module): def test_invalid_language_arg_types(self, ltype): with pytest.raises(TypeError): self.as_connection.udf_get(self.loaded_udf_name, ltype) - - def test_udf_get_with_correct_paramters_without_connection(self): - """ - Invoke udf_get() with correct parameters without connection - """ - policy = {"timeout": 5000} - - config = self.connection_config.copy() - client1 = aerospike.client(config) - - assert client1.udf_get(self.loaded_udf_name, self.udf_language, policy) is not None diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 827ea0bbe..6554482d3 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -8,7 +8,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestIncrement(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -338,17 +337,8 @@ def test_increment_with_unicode_bin(self): assert bins == {"age": 11, "name": "name1"} - def test_increment_with_correct_parameters_without_connection(self): - """ - Invoke increment() with correct parameters without connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - - assert 0 == client1.increment(key, "age", 5) - - @pytest.mark.skip(reason="This raises a system error." + " Something else should be raised") + @pytest.mark.skip(reason="This raises a system error." + + " Something else should be raised") def test_increment_with_integer_greaterthan_maxsize(self): """ Invoke increment() with integer greater then(2^63 - 1) diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 7d9bf97d1..32ff01d73 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -7,7 +7,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -436,17 +435,6 @@ def test_createindex_integer_unicode(self): self.as_connection.index_remove("test", "uni_age_index", policy) ensure_dropped_index(self.as_connection, "test", "uni_age_index") - def test_createindex_with_correct_parameters_without_connection(self): - # Invoke createindex() with correct arguments without connection - policy = {} - config = self.connection_config.copy() - client1 = aerospike.client(config) - - assert 0 == client1.index_integer_create( - 'test', 'demo', 'age', 'age_index', policy) - self.as_connection.index_remove('test', 'age_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'age_index') - def test_index_remove_no_args(self): with pytest.raises(TypeError): diff --git a/test/new_tests/test_info.py b/test/new_tests/test_info.py index 82effd0fa..543b3acce 100644 --- a/test/new_tests/test_info.py +++ b/test/new_tests/test_info.py @@ -87,18 +87,6 @@ def test_info_without_parameters(self): assert "argument 'command' (pos 1)" in str(err_info.value) - def test_info_positive_for_sets_without_connection(self): - """ - Test info positive for sets without connection - """ - client1 = aerospike.client(self.connection_config) - - with pytest.raises(e.ClusterError) as err_info: - client1.info("sets", self.connection_config["hosts"]) - - assert err_info.value.code == 11 - assert err_info.value.msg == "No connection to aerospike cluster" - @pytest.mark.parametrize( "host_arg", [ diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index b88fd9fdf..475aed127 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -84,15 +84,6 @@ def test_info_all_without_parameters(self): with pytest.raises(TypeError): self.as_connection.info_all() - def test_info_all_without_connection(self): - """ - Test info positive for sets without connection - """ - client1 = aerospike.client(self.connection_config) - - nodes_info = client1.info_all("sets") - assert nodes_info is not None - def test_info_all_with_invalid_policy_type(self): """ Test that sending a non dict/None as policy raises an error diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index 26f403f22..58d4be1b8 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -130,14 +130,6 @@ def test_info_random_node_for_incorrect_command(self): with pytest.raises(e.ClientError): self.as_connection.info_random_node("abcd") - def test_info_random_node_positive_without_connection(self): - """ - Test info with correct arguments without connection. - """ - client1 = aerospike.client(self.connection_config) - response = client1.info_random_node("bins") - assert response is not None - def test_info_random_node_positive_with_extra_parameters(self): """ Test info with extra parameters. diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index 246ebed5d..bc65f05dc 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -135,14 +135,6 @@ def test_info_single_node_for_incorrect_command(self): with pytest.raises(e.ClientError): self.as_connection.info_single_node("abcd", self.connection_config["hosts"][0]) - def test_info_single_node_positive_without_connection(self): - """ - Test info with correct arguments without connection. - """ - client1 = aerospike.client(self.connection_config) - with pytest.raises(e.ParamError) as err_info: - client1.info_single_node("bins", self.connection_config["hosts"][0][:2]) - def test_info_single_node_positive_with_extra_parameters(self): """ Test info with extra parameters. diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index 1008131a8..463bd84fa 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -26,8 +26,8 @@ def _connect(self): def test_is_connected_before_connect(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and no-op to client + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client """ client = aerospike.client(self.config) assert client.is_connected() is True @@ -52,8 +52,8 @@ def test_pos_is_connected_after_multiple_connects(self): def test_is_connected_after_close(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and no-op to client + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client """ self._connect() assert self.client.is_connected() is True diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index 0ddbda1e6..ad8228bba 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -6,7 +6,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestScanInfo(object): udf_to_load = "bin_lua.lua" @@ -121,17 +120,6 @@ def test_job_info_with_scanid_string(self): ] ) - def test_job_info_with_correct_parameters_without_connection(self): - """ - Invoke job_info() with correct parameters without connection - """ - - config = self.connection_config.copy() - client1 = aerospike.client(config) - - response = client1.job_info(self.job_id, aerospike.JOB_SCAN) - assert response is not None - def test_job_info_with_constant_out_of_valid_values(self): """ Invoke job_info() with the scan module out of the expected range diff --git a/test/new_tests/test_list_append.py b/test/new_tests/test_list_append.py index 96cf7e1c3..54999f2eb 100644 --- a/test/new_tests/test_list_append.py +++ b/test/new_tests/test_list_append.py @@ -6,7 +6,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestListAppend(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -217,10 +216,3 @@ def test_neg_list_append_meta_type_integer(self): except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Metadata should be of type dictionary" - - def test_list_append_with_no_connection(self): - config = self.connection_config.copy() - client = aerospike.client(config) - k = ("test", "demo", "no_con") - response = client.list_append(k, "bob", "item") - assert response is not None diff --git a/test/new_tests/test_list_index.py b/test/new_tests/test_list_index.py index 51923b146..d9e7e9d3e 100644 --- a/test/new_tests/test_list_index.py +++ b/test/new_tests/test_list_index.py @@ -7,7 +7,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestListIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -343,22 +342,6 @@ def test_neg_listindex_with_incorrect_set(self): self.as_connection.index_remove("test", "test_numeric_list_index", policy) ensure_dropped_index(self.as_connection, "test", "test_numeric_list_index") - def test_neg_listindex_with_correct_parameters_no_connection(self): - """ - Invoke index_list_create() with correct arguments no connection - """ - policy = {} - config = self.connection_config.copy() - client1 = aerospike.client(config) - - retobj = client1.index_list_create( - "test", "demo", "string_list", aerospike.INDEX_STRING, "test_string_list_index", policy - ) - - assert retobj == 0 - self.as_connection.index_remove("test", "test_string_list_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_list_index") - def test_neg_listindex_with_no_paramters(self): """ Invoke index_list_create() without any mandatory parameters. diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index 04bb9c32a..572ed0662 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -30,7 +30,6 @@ def remove_map_keys(client): @pytest.mark.usefixtures("connection_with_config_funcs") -@pytest.mark.usefixtures("connection_config") class TestMapKeysIndex(object): def setup_class(cls): cls.connection_setup_functions = [add_map_keys] @@ -326,21 +325,5 @@ def test_create_map_integer_index_unicode(self): ) assert response_code == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "uni_age_index", policy) - ensure_dropped_index(self.as_connection, "test", "uni_age_index") - - def test_mapkeysindex_with_correct_parameters_no_connection(self): - """ - Invoke index_map_keys_create() with correct arguments no connection - """ - policy = {} - config = self.connection_config.copy() - client1 = aerospike.client(config) - - retval = client1.index_map_keys_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy - ) - - assert retval == 0 - self.as_connection.index_remove("test", "test_string_map_index", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index") + self.as_connection.index_remove('test', u'uni_age_index', policy) + ensure_dropped_index(self.as_connection, 'test', u'uni_age_index') diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 546a103f6..0ac4fb4ef 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -32,7 +32,6 @@ def remove_maps_from_client(client): @pytest.mark.usefixtures("connection_with_config_funcs") -@pytest.mark.usefixtures("connection_config") class TestMapValuesIndex(object): def setup_class(cls): """ @@ -57,12 +56,13 @@ def test_mapvaluesindex_with_correct_parameters(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index1", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") + self.as_connection.index_remove('test', 'test_string_map_index', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') def test_mapvaluesindex_with_correct_parameters_no_policy(self): """ @@ -70,12 +70,12 @@ def test_mapvaluesindex_with_correct_parameters_no_policy(self): and the policy argument not passed """ retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index2" - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index') assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index2") - ensure_dropped_index(self.as_connection, "test", "test_string_map_index2") + self.as_connection.index_remove('test', 'test_string_map_index') + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') def test_mapvaluesindex_with_correct_parameters_numeric(self): """ @@ -99,8 +99,9 @@ def test_mapvalues_index_with_correct_parameters_set_length_extra(self): policy = {} with pytest.raises(e.InvalidRequest) as err_info: self.as_connection.index_map_values_create( - "test", set_name, "string_map", aerospike.INDEX_STRING, "test_string_map_index3", policy - ) + 'test', set_name, + 'string_map', aerospike.INDEX_STRING, + "test_string_map_index", policy) err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_REQUEST_INVALID @@ -138,22 +139,23 @@ def test_mapvaluesindex_with_incorrect_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map1", aerospike.INDEX_STRING, "test_string_map_index4", policy - ) + 'test', 'demo', 'string_map1', aerospike.INDEX_STRING, + 'test_string_map_index', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index4", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index4") + self.as_connection.index_remove('test', 'test_string_map_index', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') @pytest.mark.parametrize( "test_ns, test_set, test_bin, test_idx_name", ( - (None, "demo", "string_map", "test_string_map_index5"), - (1, "demo", "string_map", "test_string_map_index6"), - ("test", 1, "string_map", "test_string_map_index7"), - ("test", "demo", None, "test_string_map_index8"), - ("test", "demo", "string_map", None), - ("test", "demo", "string_map", 1), + (None, 'demo', 'string_map', 'test_string_map_index'), + (1, 'demo', 'string_map', 'test_string_map_index'), + ('test', 1, 'string_map', 'test_string_map_index'), + ('test', 'demo', None, 'test_string_map_index'), + ('test', 'demo', 'string_map', None), + ('test', 'demo', 'string_map', 1), ), ids=("ns is None", "ns is int", "set is int", "bin is None", "index name is none", "index name is int"), ) @@ -176,11 +178,12 @@ def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): with pytest.raises(e.ParamError) as err_info: self.as_connection.index_map_values_create( - "test", "demo", "string_map", idx_val, "test_string_map_index9", policy - ) + 'test', 'demo', 'string_map', idx_val, + "test_string_map_index", policy) try: - self.as_connection.index_remove("test", "test_string_map_index9") - ensure_dropped_index(self.as_connection, "test", "test_string_map_index9") + self.as_connection.index_remove( + 'test', 'test_string_map_index') + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') except: pass @@ -216,19 +219,21 @@ def test_create_same_mapvaluesindex_multiple_times_different_bin(self): policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index10", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK with pytest.raises(e.IndexFoundError): retobj = self.as_connection.index_map_values_create( - "test", "demo", "numeric_map", aerospike.INDEX_NUMERIC, "test_string_map_index10", policy - ) - self.as_connection.index_remove("test", "test_string_map_index10", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index10") + 'test', 'demo', 'numeric_map', aerospike.INDEX_NUMERIC, + 'test_string_map_index', policy) + self.as_connection.index_remove( + 'test', 'test_string_map_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') - self.as_connection.index_remove("test", "test_string_map_index10", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index10") + self.as_connection.index_remove( + 'test', 'test_string_map_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ @@ -237,23 +242,26 @@ def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index11", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK try: retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy - ) - self.as_connection.index_remove("test", "test_string_map_index1", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") - self.as_connection.index_remove("test", "test_string_map_index11", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index11") + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index1', policy) + self.as_connection.index_remove( + 'test', 'test_string_map_index1', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') + self.as_connection.index_remove( + 'test', 'test_string_map_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') except e.IndexFoundError: assert self.server_version < [6, 1] - self.as_connection.index_remove("test", "test_string_map_index11", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index11") + self.as_connection.index_remove( + 'test', 'test_string_map_index', policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') def test_createmapvaluesindex_with_policy(self): """ @@ -274,12 +282,13 @@ def test_createmapvaluesindex_with_policystring(self): """ policy = {"timeout": 1000} retobj = self.as_connection.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index12", policy - ) + 'test', 'demo', 'string_map', aerospike.INDEX_STRING, + 'test_string_map_index', policy) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "test_string_map_index12", policy) - ensure_dropped_index(self.as_connection, "test", "test_string_map_index12") + self.as_connection.index_remove('test', 'test_string_map_index', + policy) + ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') """ This test case causes a db crash and hence has been commented. Work pending @@ -322,20 +331,6 @@ def test_create_map_values_integer_index_unicode(self): ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove("test", "uni_age_index", policy) - ensure_dropped_index(self.as_connection, "test", "uni_age_index") - - def test_mapvaluesindex_with_correct_parameters_no_connection(self): - """ - Invoke index_mapvalues_create() with correct arguments no - connection - """ - policy = {} - config = self.connection_config.copy() - client1 = aerospike.client(config) - - retval = client1.index_map_values_create( - "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index13", policy - ) - - assert retval == 0 + self.as_connection.index_remove( + 'test', u'uni_age_index', policy) + ensure_dropped_index(self.as_connection, 'test', u'uni_age_index') diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index 88ff4bcbf..8cbbd6b89 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -53,7 +53,6 @@ # aerospike.OP_MAP_GET_BY_RANK_RANGE -@pytest.mark.usefixtures("connection_config") class TestOperate(object): def setup_class(cls): """ @@ -526,25 +525,6 @@ def test_pos_operate_increment_nonexistent_bin(self): assert bins == {"my_age": 5, "age": 1, "name": "name1"} - def test_pos_operate_with_correct_paramters_without_connection(self): - """ - Invoke operate() with correct parameters without connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - llist = [ - {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, - {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, - {"op": aerospike.OPERATOR_READ, "bin": "name"}, - ] - - try: - key, _, _ = client1.operate(key, llist) - - except e.ClusterError as exception: - assert exception.code == 11 - def test_pos_operate_write_set_to_aerospike_null(self): """ Invoke operate() with write command with bin set to aerospike_null diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index 59e69b07c..2b774dcc5 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -54,7 +54,6 @@ # aerospike.OP_MAP_GET_BY_RANK_RANGE -@pytest.mark.usefixtures("connection_config") class TestOperate(object): def setup_class(cls): """ @@ -438,16 +437,6 @@ def test_pos_operate_increment_nonexistent_key(self): self.as_connection.remove(key) - def test_pos_operate_with_correct_paramters_without_connection(self): - """ - Invoke operate() with correct parameters without connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - llist = [operations.touch()] - - assert client1.operate(key, llist) is not None def test_pos_operate_write_set_to_aerospike_null(self): """ diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index c5488e2f5..bb398b13d 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -6,7 +6,6 @@ from aerospike import exception as e -@pytest.mark.usefixtures("connection_config") class TestOperateOrdered(object): def setup_class(cls): """ @@ -659,25 +658,6 @@ def test_neg_operate_ordered_with_policy_gen_GT_lesser(self): bytearray(b"\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8"), ) - def test_neg_operate_ordered_without_connection(self): - """ - Invoke operate_ordered() with correct parameters without connection - """ - key = ("test", "demo", 1) - config = self.connection_config.copy() - client1 = aerospike.client(config) - llist = [ - {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, - {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, - {"op": aerospike.OPERATOR_READ, "bin": "name"}, - ] - - try: - key, _, _ = client1.operate_ordered(key, llist) - - except e.ClusterError as exception: - assert exception.code == 11 - def test_neg_operate_ordered_prepend_set_to_aerospike_null(self): """ Invoke operate_ordered() with prepend command bin set to aerospike_null diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index f7051486e..0349ef193 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -5,8 +5,8 @@ from aerospike import exception as e -@pytest.mark.usefixtures("connection_config") -class TestPrepend: +class TestPrepend(): + @pytest.fixture(autouse=True) def setup(self, request, as_connection): """ @@ -478,17 +478,3 @@ def test_neg_prepend_without_bin_name(self): except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Cannot concatenate 'str' and 'non-str' objects" - - def test_neg_prepend_with_correct_parameters_without_connection(self): - """ - Invoke prepend() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - key = ("test", "demo", 1) - - try: - client1.prepend(key, "name", "str") - - except e.ClusterError as exception: - assert exception.code == 11 diff --git a/test/new_tests/test_put_async.py b/test/new_tests/test_put_async.py index 2a9796370..826b685d9 100644 --- a/test/new_tests/test_put_async.py +++ b/test/new_tests/test_put_async.py @@ -637,82 +637,30 @@ async def async_io(key=None, rec=None, meta=None, policy=None, serialize=None): assert {"name": "John"} == bins self.as_connection.remove(key) - @pytest.mark.asyncio - async def test_neg_put_with_string_record_without_connection(self): - """ - Invoke put() for a record with string data without connection - """ - config = {"hosts": [("127.0.0.1", 3000)]} - client1 = aerospike.client(config) - - key = ("test", "demo", 1) - - bins = {"name": "John"} - - async def async_io(key=None, rec=None, meta=None, policy=None, serialize=None): - try: - assert 0 == await io.put(client1, key, rec, meta, policy, serialize) - except e.ClusterError as exception: - assert exception.code == 11 - - await asyncio.gather(async_io(key, bins)) - - @pytest.mark.parametrize( - "key, record, meta, policy, ex_code, ex_msg", - [ - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": "wrong", "ttl": 25000}, - {"total_timeout": 1000}, # Gen as string - -2, - "Generation should be an int or long", - ), - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": 3, "ttl": "25000"}, - {"total_timeout": 1000}, # ttl as string - -2, - "TTL should be an int or long", - ), - ( - ("test", "demo", 1), - {"name": "john"}, - {"gen": 3, "ttl": 25000}, - {"total_timeout": "1000"}, # Timeout as string - -2, - "timeout is invalid", - ), - ( - ("test", "demo", 1), - {"name": "john"}, # Policy as string - {"gen": 3, "ttl": 25000}, - "Policy", - -2, - "policy must be a dict", - ), - ( - ("test", "demo", 1), - {"i": 13}, # Meta as string - "OK", - {"total_timeout": 1000}, - -2, - "meta must be a dict", - ), - ( - ("test", "demo", 1), - {"i": 13}, # Meta as string - 1234, - {"total_timeout": 1000}, - -2, - "meta must be a dict", - ), - ], - ) - def test_neg_put_with_invalid_metadata(self, key, record, meta, policy, ex_code, ex_msg, put_data): - """ - Invoke put() for a record with generation as string + @pytest.mark.parametrize("key, record, meta, policy, ex_code, ex_msg", [ + (('test', 'demo', 1), {'name': 'john'}, + {'gen': "wrong", 'ttl': 25000}, {'total_timeout': 1000}, # Gen as string + -2, "Generation should be an int or long"), + (('test', 'demo', 1), {'name': 'john'}, + {'gen': 3, 'ttl': "25000"}, {'total_timeout': 1000}, # ttl as string + -2, "TTL should be an int or long"), + (('test', 'demo', 1), {'name': 'john'}, + {'gen': 3, 'ttl': 25000}, {'total_timeout': "1000"}, # Timeout as string + -2, "timeout is invalid"), + (('test', 'demo', 1), {'name': 'john'}, # Policy as string + {'gen': 3, 'ttl': 25000}, "Policy", + -2, "policy must be a dict"), + (('test', 'demo', 1), {'i': 13}, # Meta as string + "OK", {'total_timeout': 1000}, + -2, "meta must be a dict"), + (('test', 'demo', 1), {'i': 13}, # Meta as string + 1234, {'total_timeout': 1000}, + -2, "meta must be a dict"), + ]) + def test_neg_put_with_invalid_metadata( + self, key, record, meta, policy, ex_code, ex_msg, put_data): + """ + Invoke put() for a record with generation as string """ with pytest.raises(e.ParamError): put_data(self.as_connection, key, record, meta, policy) diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index 3146cd4db..b28fb413c 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -57,7 +57,6 @@ def add_ctx_op(ctx_type, value): ctx_map_value.append(add_ctx_op(map_value, 3)) -@pytest.mark.usefixtures("connection_config") class TestQuery(TestBaseClass): def setup_class(cls): client = TestBaseClass.get_new_connection() @@ -959,22 +958,6 @@ def test_query_with_set_int(self): err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_PARAM - def test_query_with_correct_parameters_without_connection(self): - """ - Invoke query() with correct arguments without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - query = client1.query("test", "demo") - query.select("name", "test_age") - query.where(p.equals("test_age", 1)) - - def callback(input_tuple): - pass - - query.foreach(callback) - @pytest.mark.skip(reason="segfault") def test_query_predicate_range_wrong_no_args(self): """ """ diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index e222413e1..5fd528c08 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -75,29 +75,18 @@ class TestQueryApply(object): # These functions will run once for this test class, and do all of the # required setup and teardown - age_range_pred = p.between("age", 0, 4) # Predicate for ages between [0,5) - no_set_key = ("test", None, "no_set") # Key for item stored in a namespace but not in a set + connection_setup_functions = (add_test_udf, add_test_parameter_udf, + add_indexes_to_client, create_records) + connection_teardown_functions = (drop_test_udf, drop_test_parameter_udf, + remove_indexes_from_client, drop_records) + age_range_pred = p.between('age', 0, 4) # Predicate for ages between [0,5) + no_set_key = ('test', None, "no_set") # Key for item stored in a namespace but not in a set @pytest.fixture(autouse=True) def setup(self, request, connection_with_config_funcs): client = connection_with_config_funcs - add_test_udf(client) - add_test_parameter_udf(client) - add_indexes_to_client(client) create_records(client) - def teardown(): - """ - Teardown method - """ - - # drop_test_udf(client) - # drop_test_parameter_udf(client) - # remove_indexes_from_client(client) - # drop_records(client) - - request.addfinalizer(teardown) - def test_query_apply_with_no_parameters(self): """ Invoke query_apply() without any mandatory parameters. diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index 0e74544d4..e60212a0f 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -8,8 +8,8 @@ @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") -class TestRemove: +class TestRemove(): + @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_existing_record(self): """ @@ -301,19 +301,6 @@ def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): (code, _, _, _) = exception.value assert code == ex_code - def test_remove_with_correct_parameters_without_connection(self): - """ - Invoke remove() with correct arguments without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - key = ("test", "demo", 1) - - with pytest.raises(e.RecordNotFound) as exception: - client1.remove(key) - (code, _, _, _) = exception.value - assert code == 2 - def test_neg_remove_with_no_parameters(self): """ Invoke remove() without any mandatory parameters. diff --git a/test/new_tests/test_scan_apply.py b/test/new_tests/test_scan_apply.py index 39aca4d88..c62e7d31f 100644 --- a/test/new_tests/test_scan_apply.py +++ b/test/new_tests/test_scan_apply.py @@ -20,7 +20,6 @@ def wait_for_job_completion(as_connection, job_id): time.sleep(0.1) -@pytest.mark.usefixtures("connection_config") class TestScanApply(object): def setup_class(cls): cls.udf_to_load = "bin_lua.lua" @@ -338,16 +337,6 @@ def test_scan_apply_with_argument_is_string(self): err_code = err_info.value.code assert err_code is AerospikeStatus.AEROSPIKE_ERR_PARAM - def test_scan_apply_with_correct_parameters_without_connection(self): - """ - Invoke scan_apply() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - - response = client1.scan_apply("test", "demo", "bin_lua", "mytransform", ["age", 2]) - assert response is not None - def test_scan_apply_with_incorrect_policy(self): """ Invoke scan_apply() with incorrect policy diff --git a/test/new_tests/test_select.py b/test/new_tests/test_select.py index dffcced8f..4edf072c7 100644 --- a/test/new_tests/test_select.py +++ b/test/new_tests/test_select.py @@ -176,15 +176,6 @@ def test_select_without_any_parameter(self): assert "argument 'key' (pos 1)" in str(typeError.value) - def test_select_with_key_and_bins_without_connection(self): - - bins_to_select = ["a"] - config = self.connection_config - disconnected_client = aerospike.client(config) - - _, _, bins = disconnected_client.select(self.test_key, bins_to_select) - assert bins is not None - def test_select_with_invalid_keys(self, invalid_key): """ Verify that different types of invalid keys will diff --git a/test/new_tests/test_select_many.py b/test/new_tests/test_select_many.py index 556ffe646..576fa2289 100644 --- a/test/new_tests/test_select_many.py +++ b/test/new_tests/test_select_many.py @@ -23,7 +23,6 @@ def get_primary_key(record): return record[0][2] -@pytest.mark.usefixtures("connection_config") class TestSelectMany(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -291,15 +290,6 @@ def test_select_many_without_any_parameter(self): assert "argument 'keys' (pos 1)" in str(typeError.value) - def test_select_many_with_proper_parameters_without_connection(self): - - config = self.connection_config.copy() - client1 = aerospike.client(config) - - filter_bins = ["title", "name"] - - client1.select_many(self.keys, filter_bins, {"timeout": 20}) - def test_select_many_with_invalid_keys(self, invalid_key): # invalid_key will be an invalid key_tuple, so we wrap # it with a valid key in a list diff --git a/test/new_tests/test_touch.py b/test/new_tests/test_touch.py index f7552f17d..da4d33afe 100644 --- a/test/new_tests/test_touch.py +++ b/test/new_tests/test_touch.py @@ -6,7 +6,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestTouch(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): @@ -257,16 +256,6 @@ def test_touch_policy_is_string(self): assert err_info.value.code == AerospikeStatus.AEROSPIKE_ERR_PARAM - def test_touch_with_correct_paramters_without_connection(self): - """ - Invoke touch() with correct parameters without connection - """ - config = self.connection_config.copy() - client1 = aerospike.client(config) - key = ("test", "demo", 1) - - client1.touch(key, 120) - def test_touch_withttlvalue_greaterthan_maxsize(self): """ Invoke touch() with ttl value greater than (2^63-1) diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index f29180af4..f8b918c88 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -6,7 +6,6 @@ import aerospike -@pytest.mark.usefixtures("connection_config") class TestUdfList(object): def setup_class(cls): """ @@ -104,17 +103,3 @@ def test_udf_list_with_wrong_policy_type(self, policy): """ with pytest.raises(e.ParamError): self.client.udf_list(policy) - - def test_udf_list_with_proper_parameters_without_connection(self): - """ - Test to verify call to udf_list without - first calling connect - """ - config = self.connection_config.copy() - - client1 = aerospike.client(config) - - policy = {"timeout": 0} - - udf_list = client1.udf_list(policy) - assert udf_list is not None diff --git a/test/new_tests/test_udf_put.py b/test/new_tests/test_udf_put.py index 84c7fcf4d..28659dd40 100644 --- a/test/new_tests/test_udf_put.py +++ b/test/new_tests/test_udf_put.py @@ -10,7 +10,6 @@ @pytest.mark.usefixtures("as_connection") -@pytest.mark.usefixtures("connection_config") class TestUdfPut(TestBaseClass): def setup_class(cls): cls.udf_name = "example.lua" @@ -124,18 +123,6 @@ def test_udf_put_with_empty_filename_beginning_with_slash(self): with pytest.raises(e.ParamError): self.as_connection.udf_put(filename, udf_type, policy) - def test_udf_put_with_proper_parameters_without_connection(self): - - policy = {} - filename = self.udf_name - udf_type = 0 - - config = self.connection_config.copy() - - client1 = aerospike.client(config) - - client1.udf_put(filename, udf_type, policy) - def test_udf_put_with_invalid_timeout_policy_value(self): """ Test that invalid timeout policy causes an error on udf put From 76596707cdf3aa5c491276977474f6d831cf06ec Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Fri, 14 Oct 2022 22:16:11 +0530 Subject: [PATCH 08/27] release doc update --- Releases.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Releases.md b/Releases.md index f8df9a1db..d48d07c03 100644 --- a/Releases.md +++ b/Releases.md @@ -7,8 +7,28 @@ date: 10/14/2022 ## Deprecations​ - - client().connect() has been deprecated and it is an no-op. Client call itself establishes the connection object. - - client().close() has been deprecated and it is an no-op. Client destroy unwinds the conection. + - client().connect() has been deprecated and it is a no-op. Client call itself establishes the connection object. + - client().close() has been deprecated and it is a no-op. Client destroy unwinds the conection. + - If user authentication method is used, then make sure to add user/password information into config dictionary for client call to succeed + +ex) config = { + 'hosts': hosts, + 'policies': {'auth_mode': aerospike.AUTH_INTERNAL}, + } + client = aerospike.client(config) + client.connect(user, password) + + the above is changed to: + +config = { + 'hosts': hosts, + 'policies': {'auth_mode': aerospike.AUTH_INTERNAL}, + 'user': user, + 'password': password + } + client = aerospike.client(config) + #following is no-op + client.connect(user, password) # Version 7.1.1 From cbf3188743edb3014fb2784d0689454675a6f27f Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Fri, 14 Oct 2022 22:19:27 +0530 Subject: [PATCH 09/27] test cases update --- test/config.conf | 2 +- test/test_cases.py | 47 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/test/config.conf b/test/config.conf index 226f4bcc7..54d04e76b 100644 --- a/test/config.conf +++ b/test/config.conf @@ -1,5 +1,5 @@ [community-edition] -hosts : 127.0.0.1:3000 +hosts:bob-cluster-a:3000 [enterprise-edition] hosts :172.17.0.3:3000 diff --git a/test/test_cases.py b/test/test_cases.py index f67b2a10b..e41ebd131 100644 --- a/test/test_cases.py +++ b/test/test_cases.py @@ -117,7 +117,7 @@ def gccallback(phase, info): def connect_to_cluster(aeros): - client = aeros.connect("generic_client", "generic_client") + client = aeros.connect('admin', 'admin') client.close() # gc.collect() @@ -1137,12 +1137,41 @@ def test_send_key(aeros, namespace, setname): client.close() +def test_create_user(aeros, namespace, setname): + policy = {"timeout": 1000} + user = "generic_client" + password = "generic_client" + #roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "quota-4k-2k-role", "sindex-admin", "truncate"] + roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "sindex-admin", "truncate"] + + client = aeros.connect('admin', 'admin') + + usr_sys_admin_privs = [ + {"code": aerospike.PRIV_USER_ADMIN}, + {"code": aerospike.PRIV_SYS_ADMIN}] + try: + aeros.admin_drop_role("quota-4k-2k-role") + time.sleep(2) + except: + pass + # aeros.admin_create_role( + # "quota-4k-2k-role", usr_sys_admin_privs, read_quota=40000, write_quota=20000) + # time.sleep(1) + + try: + aeros.admin_drop_user(user, policy) + time.sleep(2) + except: + pass + + status = aeros.admin_create_user(user, password, roles, policy) def get_aerospike(): # tls_name = 'bob-cluster-a' - tls_name = "172.17.0.3" + tls_name = '172.31.1.163' - endpoints = [("172.17.0.3", 3000)] + endpoints = [ + ('172.31.1.163', 3000)] hosts = [(address[0], address[1], tls_name) for address in endpoints] @@ -1158,8 +1187,8 @@ def get_aerospike(): # 'keyfile': "/Users/ramarajpandian/code/src/aerospike/enterprise/as-dev-infra/certs/Client-Chainless/key.pem", # noqa: E501 # 'for_login_only': True, # } - "user": "generic_client", - "password": "generic_client", + 'user':"admin", + 'password':"admin" } # Optionally set policies for various method types write_policies = {"total_timeout": 2000, "max_retries": 0, "key": aerospike.POLICY_KEY_SEND} @@ -1177,13 +1206,13 @@ def run(): aeros = get_aerospike() - config = {"hosts": [("bad_addr", 3000)]} - bad_client = aerospike.client(config) + # config = {"hosts": [("bad_addr", 3000)]} + # bad_client = aerospike.client(config) # Connect once to establish a memory usage baseline. connect_to_cluster(aeros) - - test_memleak(aeros, "test", "demo") + test_create_user(aeros, "test", "demo") + # test_memleak(aeros, "test", "demo") # test_50levelcdt(aeros, "test", "demo") # test_sindex(aeros, "test", "demo") # test_send_key(aeros, "test", "demo") From 0cead58ac7319b6357a38728470e09cb2ff851d6 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Mon, 17 Oct 2022 11:51:00 +0530 Subject: [PATCH 10/27] point master 6.2.0 c-client --- aerospike-client-c | 1 - 1 file changed, 1 deletion(-) delete mode 160000 aerospike-client-c diff --git a/aerospike-client-c b/aerospike-client-c deleted file mode 160000 index 84cfce3dd..000000000 --- a/aerospike-client-c +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 84cfce3dda7216b05b39b0be437b570e30b2f06f From c2e6ce52f0467e35898bf7b877ee856b472a45e9 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian Date: Tue, 1 Nov 2022 11:33:21 -0700 Subject: [PATCH 11/27] test cases update --- src/main/client/batch_get_ops.c | 88 ++++++++++++++-------------- test/{ => misc}/test_cases.py | 21 +++++++ test/new_tests/test_batch_get_ops.py | 25 ++++---- 3 files changed, 80 insertions(+), 54 deletions(-) rename test/{ => misc}/test_cases.py (99%) diff --git a/src/main/client/batch_get_ops.c b/src/main/client/batch_get_ops.c index 58774787a..2ab7b259e 100644 --- a/src/main/client/batch_get_ops.c +++ b/src/main/client/batch_get_ops.c @@ -51,50 +51,50 @@ typedef struct { static bool batch_read_operate_cb(const as_batch_read *results, uint32_t n, void *udata) { - // Extract callback user-data - LocalData *data = (LocalData *)udata; - as_batch_read *r = NULL; - - // Lock Python State - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - for (uint32_t i = 0; i < n; i++) { - PyObject *py_key = NULL; - PyObject *py_rec = NULL; - PyObject *py_rec_meta = NULL; - PyObject *py_rec_bins = NULL; - as_record *rec = NULL; - as_error err; - - r = (as_batch_read *)&results[i]; - py_key = PyList_GetItem(data->py_keys, i); - rec = &r->record; - - as_error_init(&err); - err.code = r->result; - - if (err.code == AEROSPIKE_OK) { - metadata_to_pyobject(&err, rec, &py_rec_meta); - bins_to_pyobject(data->client, &err, rec, &py_rec_bins, false); - } - else { - py_rec_meta = raise_exception(&err); - Py_INCREF(Py_None); - py_rec_bins = Py_None; - } - - py_rec = PyTuple_New(3); - PyTuple_SetItem(py_rec, 0, py_key); - PyTuple_SetItem(py_rec, 1, py_rec_meta); - PyTuple_SetItem(py_rec, 2, py_rec_bins); - - PyList_Append(data->py_results, py_rec); - } - - PyGILState_Release(gstate); - - return true; + // Extract callback user-data + LocalData *data = (LocalData *)udata; + as_batch_read *r = NULL; + + // Lock Python State + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + for (uint32_t i = 0; i < n; i++) { + PyObject *py_key = NULL; + PyObject *py_rec = NULL; + PyObject *py_rec_meta = NULL; + PyObject *py_rec_bins = NULL; + as_record *rec = NULL; + as_error err; + + r = (as_batch_read *)&results[i]; + py_key = PyList_GetItem(data->py_keys, i); + // key_to_pyobject(&err, &r->key, &py_key); + rec = &r->record; + + as_error_init(&err); + err.code = r->result; + + if (err.code == AEROSPIKE_OK) { + metadata_to_pyobject(&err, rec, &py_rec_meta); + bins_to_pyobject(data->client, &err, rec, &py_rec_bins, false); + } else { + py_rec_meta = raise_exception(&err); + Py_INCREF(Py_None); + py_rec_bins = Py_None; + } + + py_rec = PyTuple_New(3); + PyTuple_SetItem(py_rec, 0, py_key); + PyTuple_SetItem(py_rec, 1, py_rec_meta); + PyTuple_SetItem(py_rec, 2, py_rec_bins); + + PyList_Append(data->py_results, py_rec); + } + + PyGILState_Release(gstate); + + return true; } /** diff --git a/test/test_cases.py b/test/misc/test_cases.py similarity index 99% rename from test/test_cases.py rename to test/misc/test_cases.py index e41ebd131..0cf903ba6 100644 --- a/test/test_cases.py +++ b/test/misc/test_cases.py @@ -1166,6 +1166,27 @@ def test_create_user(aeros, namespace, setname): status = aeros.admin_create_user(user, password, roles, policy) +def test_large_put(aeros, namespace, setname): + + client = aeros.connect('generic_client', 'generic_client') + + # Records are addressable via a tuple of (namespace, set, primary key) + key = (namespace, setname, 'send-key-test') + + f = open('/home/randersen/NYTZ131.json') + data = json.load(f) + f.close() + + #Test to make sure the doc was properly loaded + print(data["TimeZoneName"]) + + key = (namespace, setname, "America/New_York") + + try: + client.put(key, {"tzzone": data}) + except Exception as e: + print(e) + def get_aerospike(): # tls_name = 'bob-cluster-a' tls_name = '172.31.1.163' diff --git a/test/new_tests/test_batch_get_ops.py b/test/new_tests/test_batch_get_ops.py index 16ee66361..281051826 100644 --- a/test/new_tests/test_batch_get_ops.py +++ b/test/new_tests/test_batch_get_ops.py @@ -137,23 +137,28 @@ def test_batch_result_output_format(self): ops = [mh.map_get_by_rank_range("scores", -3, 3, aerospike.MAP_RETURN_KEY_VALUE)] non_existent_key = ("test", "demo", "batch-ops-non_existent_key") - rec = self.as_connection.batch_get_ops([key1, key2, non_existent_key], ops, policy=policy) + rec = self.as_connection.batch_get_ops([key1, key2, non_existent_key], ops, policy) - self.as_connection.remove(key1) - self.as_connection.remove(key2) - - # print("\nThe record from batch_get_ops") - # pp.pprint(rec) + print("\nThe record from batch_get_ops") + pp.pprint(rec) assert rec[0][-1] is not None assert rec[1][-1] is not None assert rec[2][-2] == e.RecordNotFound - assert rec[2][-1] is None - - # print("\nThe record coming from opreate") - # rec = self.as_connection.operate(key1, ops, policy=policy) + assert rec[2][-1] == None + + # rec = self.as_connection.select_many([non_existent_key], ['name']) + # print("\nFor comparison, here's batch-read (select_many) is an array of records") # pp.pprint(rec) # rec = self.as_connection.get_many([key1, key2, non_existent_key], policy) # print("\nFor comparison, here's batch-read (get_many) is an array of records") # pp.pprint(rec) + + # print("\nThe record coming from opreate") + # rec = self.as_connection.operate(key1, ops, policy=policy) + # pp.pprint(rec) + + self.as_connection.remove(key1) + self.as_connection.remove(key2) + From 54271449d746905eae088bcc088bb39d4b3298c6 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Fri, 4 Nov 2022 10:59:40 -0700 Subject: [PATCH 12/27] add conditional connect and revert back close --- src/main/client/close.c | 31 +++++++++++++++++++++++++++---- src/main/client/connect.c | 28 +++++++++++----------------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/main/client/close.c b/src/main/client/close.c index f2f7aa277..8a8666652 100644 --- a/src/main/client/close.c +++ b/src/main/client/close.c @@ -56,11 +56,34 @@ PyObject *AerospikeClient_Close(AerospikeClient *self, PyObject *args, goto CLEANUP; } - if (!self->has_connected) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, - "Invalid aerospike client configuration"); - goto CLEANUP; + if (!self->is_conn_16) { + goto CLEANUP; + } + + if (self->use_shared_connection) { + alias_to_search = return_search_string(self->as); + py_persistent_item = + PyDict_GetItemString(py_global_hosts, alias_to_search); + + if (py_persistent_item) { + global_host = (AerospikeGlobalHosts *)py_persistent_item; + // It is only safe to do a reference counted close if the + // local as is pointing to the global as + if (self->as == global_host->as) { + close_aerospike_object(self->as, &err, alias_to_search, + py_persistent_item, false); + } + } + + PyMem_Free(alias_to_search); + alias_to_search = NULL; + } + else { + Py_BEGIN_ALLOW_THREADS + aerospike_close(self->as, &err); + Py_END_ALLOW_THREADS } + self->is_conn_16 = false; CLEANUP: if (err.code != AEROSPIKE_OK) { diff --git a/src/main/client/connect.c b/src/main/client/connect.c index 329550750..19b38f84a 100644 --- a/src/main/client/connect.c +++ b/src/main/client/connect.c @@ -172,30 +172,24 @@ PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, PyObject *py_username = NULL; PyObject *py_password = NULL; + if (self->as && aerospike_cluster_is_connected(self->as)) { + Py_INCREF(self); + return (PyObject *)self; + } + if (PyArg_ParseTuple(args, "|OO:connect", &py_username, &py_password) == false) { return NULL; } - if (!self->has_connected) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, - "Invalid aerospike client configuration"); - goto CLEANUP; + if (py_username && PyString_Check(py_username) && py_password && + PyString_Check(py_password)) { + char *username = PyString_AsString(py_username); + char *password = PyString_AsString(py_password); + as_config_set_user(&self->as->config, username, password); } -CLEANUP: - - if (err.code != AEROSPIKE_OK) { - PyObject *py_err = NULL; - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - - return NULL; - } - Py_INCREF(self); - return (PyObject *)self; + return AerospikeClientConnect(self); } /** From 014c358a8d69d8f8c161f6592651a7c649acc6c5 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Fri, 4 Nov 2022 11:18:16 -0700 Subject: [PATCH 13/27] test case updte for conditional connect --- test/new_tests/test_close.py | 4 ++-- test/new_tests/test_connect.py | 3 ++- test/new_tests/test_is_connected.py | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index cccc61bf4..73a962585 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -57,8 +57,8 @@ def test_close_twice_in_a_row(self): assert self.client.is_connected() self.client.close() - assert self.client.is_connected() is True + assert self.client.is_connected() is False # This second call should not raise any errors self.client.close() - assert self.client.is_connected() is True + assert self.client.is_connected() is False diff --git a/test/new_tests/test_connect.py b/test/new_tests/test_connect.py index 961cffdd5..067076704 100644 --- a/test/new_tests/test_connect.py +++ b/test/new_tests/test_connect.py @@ -148,7 +148,7 @@ def test_connect_positive_reconnect(self): assert client is not None assert client.is_connected() client.close() - assert client.is_connected() is True + assert client.is_connected() is False if TestBaseClass.user is None and TestBaseClass.password is None: client.connect() else: @@ -172,6 +172,7 @@ def test_connect_on_connected_client(self): def test_connect_with_extra_args(self): with pytest.raises(TypeError): client = aerospike.client(self.connection_config) + client.close() client.connect("username", "password", "extra arg") @pytest.mark.parametrize( diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index 463bd84fa..96ff3e0ef 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -58,4 +58,4 @@ def test_is_connected_after_close(self): self._connect() assert self.client.is_connected() is True self.client.close() - assert self.client.is_connected() is True + assert self.client.is_connected() is False From dd6dcdb90afe323fb4b64852c93f28333dc038b2 Mon Sep 17 00:00:00 2001 From: juliannguyen4 <109386615+juliannguyen4@users.noreply.github.com> Date: Fri, 4 Nov 2022 15:34:35 -0700 Subject: [PATCH 14/27] Update docs --- doc/aerospike.rst | 7 +++++-- doc/client.rst | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/aerospike.rst b/doc/aerospike.rst index 52b4f6563..0e499d962 100644 --- a/doc/aerospike.rst +++ b/doc/aerospike.rst @@ -28,9 +28,8 @@ Client .. py:function:: client(config) - Creates a new instance of the :class:`Client` class. + Creates a new instance of the :class:`Client` class and immediately connects to the cluster. - This client can connect to the cluster and perform operations on the database. See :ref:`client` for more details. Internally, this is a wrapper function which calls the constructor for the :class:`Client` class. @@ -360,6 +359,10 @@ Only the `hosts` key is required; the rest of the keys are optional. If ``tls-name`` is specified, it must match the tls-name specified in the node's \ server configuration file, as well as the server's CA certificate. + * **user** (:class:`str`) + (Optional) A defined user with roles in the cluster. See :meth:`admin_create_user`. + * **password** (:class:`str`) + (Optional) The password will be hashed by the client using bcrypt. * **lua** (:class:`dict`) (Optional) Contains the paths to two types of Lua modules diff --git a/doc/client.rst b/doc/client.rst index d39880c5f..b83c979c4 100755 --- a/doc/client.rst +++ b/doc/client.rst @@ -56,7 +56,7 @@ Connection .. method:: connect([username, password]) - Connect to the cluster. The optional *username* and *password* only + If there is currently no connection to the cluster, connect to it. The optional *username* and *password* only apply when connecting to the Enterprise Edition of Aerospike. :param str username: a defined user with roles in the cluster. See :meth:`admin_create_user`. @@ -86,6 +86,8 @@ Connection Close all connections to the cluster. It is recommended to explicitly \ call this method when the program is done communicating with the cluster. + You may call :meth:`~aerospike.Client.connect` again after closing the connection. + Record Operations ----------------- From dd7caf34b7e9f89a8e46e1033c795ce25b78dc61 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 17:33:00 -0800 Subject: [PATCH 15/27] test case fixes --- test/config.conf | 2 +- test/new_tests/test_close.py | 2 -- test/new_tests/test_get_many.py | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/test/config.conf b/test/config.conf index 54d04e76b..34aa40486 100644 --- a/test/config.conf +++ b/test/config.conf @@ -2,6 +2,6 @@ hosts:bob-cluster-a:3000 [enterprise-edition] -hosts :172.17.0.3:3000 +hosts :172.28.0.1:3000 user :generic_client password :generic_client diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index 73a962585..a27928c18 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -15,8 +15,6 @@ class TestClose(): - -class TestClose: def setup_class(cls): config = TestBaseClass.get_connection_config() TestClose.hostlist = config["hosts"] diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index 7e5a6ec91..6913eefe7 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -12,8 +12,6 @@ from aerospike import exception as e class TestGetMany(): - -class TestGetMany: @pytest.fixture(autouse=True) def setup(self, request, as_connection): self.keys = [] From 82749374c288ca270d4fe8310dfbd11525f9d409 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 17:47:14 -0800 Subject: [PATCH 16/27] black formatter --- test/misc/test_cases.py | 44 +++++----- test/new_tests/test_batch_get_ops.py | 3 +- test/new_tests/test_close.py | 11 ++- test/new_tests/test_connect.py | 3 +- test/new_tests/test_exists.py | 16 ++-- test/new_tests/test_get_many.py | 3 +- test/new_tests/test_get_put.py | 80 ++++++++++++------ test/new_tests/test_increment.py | 3 +- test/new_tests/test_index.py | 1 + test/new_tests/test_is_connected.py | 8 +- test/new_tests/test_mapkeys_index.py | 4 +- test/new_tests/test_mapvalues_index.py | 107 +++++++++++-------------- test/new_tests/test_operate_helpers.py | 1 - test/new_tests/test_prepend.py | 3 +- test/new_tests/test_put_async.py | 80 ++++++++++++------ test/new_tests/test_query_apply.py | 10 +-- test/new_tests/test_remove.py | 3 +- 17 files changed, 213 insertions(+), 167 deletions(-) diff --git a/test/misc/test_cases.py b/test/misc/test_cases.py index 0cf903ba6..93dcc8878 100644 --- a/test/misc/test_cases.py +++ b/test/misc/test_cases.py @@ -117,7 +117,7 @@ def gccallback(phase, info): def connect_to_cluster(aeros): - client = aeros.connect('admin', 'admin') + client = aeros.connect("admin", "admin") client.close() # gc.collect() @@ -1137,18 +1137,17 @@ def test_send_key(aeros, namespace, setname): client.close() + def test_create_user(aeros, namespace, setname): policy = {"timeout": 1000} user = "generic_client" password = "generic_client" - #roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "quota-4k-2k-role", "sindex-admin", "truncate"] + # roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "quota-4k-2k-role", "sindex-admin", "truncate"] roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "sindex-admin", "truncate"] - client = aeros.connect('admin', 'admin') - - usr_sys_admin_privs = [ - {"code": aerospike.PRIV_USER_ADMIN}, - {"code": aerospike.PRIV_SYS_ADMIN}] + client = aeros.connect("admin", "admin") + + usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] try: aeros.admin_drop_role("quota-4k-2k-role") time.sleep(2) @@ -1159,40 +1158,41 @@ def test_create_user(aeros, namespace, setname): # time.sleep(1) try: - aeros.admin_drop_user(user, policy) - time.sleep(2) + aeros.admin_drop_user(user, policy) + time.sleep(2) except: - pass + pass status = aeros.admin_create_user(user, password, roles, policy) + def test_large_put(aeros, namespace, setname): - client = aeros.connect('generic_client', 'generic_client') + client = aeros.connect("generic_client", "generic_client") # Records are addressable via a tuple of (namespace, set, primary key) - key = (namespace, setname, 'send-key-test') + key = (namespace, setname, "send-key-test") - f = open('/home/randersen/NYTZ131.json') + f = open("/home/randersen/NYTZ131.json") data = json.load(f) f.close() - - #Test to make sure the doc was properly loaded + + # Test to make sure the doc was properly loaded print(data["TimeZoneName"]) - + key = (namespace, setname, "America/New_York") - + try: client.put(key, {"tzzone": data}) except Exception as e: print(e) + def get_aerospike(): # tls_name = 'bob-cluster-a' - tls_name = '172.31.1.163' + tls_name = "172.31.1.163" - endpoints = [ - ('172.31.1.163', 3000)] + endpoints = [("172.31.1.163", 3000)] hosts = [(address[0], address[1], tls_name) for address in endpoints] @@ -1208,8 +1208,8 @@ def get_aerospike(): # 'keyfile': "/Users/ramarajpandian/code/src/aerospike/enterprise/as-dev-infra/certs/Client-Chainless/key.pem", # noqa: E501 # 'for_login_only': True, # } - 'user':"admin", - 'password':"admin" + "user": "admin", + "password": "admin", } # Optionally set policies for various method types write_policies = {"total_timeout": 2000, "max_retries": 0, "key": aerospike.POLICY_KEY_SEND} diff --git a/test/new_tests/test_batch_get_ops.py b/test/new_tests/test_batch_get_ops.py index 281051826..a6d77d297 100644 --- a/test/new_tests/test_batch_get_ops.py +++ b/test/new_tests/test_batch_get_ops.py @@ -146,7 +146,7 @@ def test_batch_result_output_format(self): assert rec[1][-1] is not None assert rec[2][-2] == e.RecordNotFound assert rec[2][-1] == None - + # rec = self.as_connection.select_many([non_existent_key], ['name']) # print("\nFor comparison, here's batch-read (select_many) is an array of records") # pp.pprint(rec) @@ -161,4 +161,3 @@ def test_batch_result_output_format(self): self.as_connection.remove(key1) self.as_connection.remove(key2) - diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index a27928c18..e596241c7 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -14,7 +14,7 @@ sys.exit(1) -class TestClose(): +class TestClose: def setup_class(cls): config = TestBaseClass.get_connection_config() TestClose.hostlist = config["hosts"] @@ -24,7 +24,7 @@ def setup_class(cls): def test_pos_close(self): """ - Invoke close() after positive connect + Invoke close() after positive connect """ self.client = TestBaseClass.get_new_connection() self.closeobject = self.client.close() @@ -32,7 +32,7 @@ def test_pos_close(self): def test_neg_close(self): """ - Invoke close() after negative connect + Invoke close() after negative connect """ config = {"hosts": [("127.0.0.1", 2000)]} @@ -44,9 +44,8 @@ def test_neg_close(self): def test_close_twice_in_a_row(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and it is no-op to client - """ + Client call itself establishes connection. + """ config = TestBaseClass.get_connection_config() if TestClose.user is None and TestClose.password is None: self.client = aerospike.client(config).connect() diff --git a/test/new_tests/test_connect.py b/test/new_tests/test_connect.py index 067076704..7e7bddbb6 100644 --- a/test/new_tests/test_connect.py +++ b/test/new_tests/test_connect.py @@ -139,8 +139,7 @@ def test_connect_positive_cluster_name(self): def test_connect_positive_reconnect(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and it is no-op to client + Client call itself establishes connection. """ config = self.connection_config.copy() diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 2dd59d541..7c075ee7d 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -13,8 +13,7 @@ class SomeClass(object): @pytest.mark.usefixtures("as_connection") -class TestExists(): - +class TestExists: @pytest.mark.parametrize("key, record", test_data.pos_data) def test_pos_exists_with_diff_datatype(self, key, record, put_data): """ @@ -104,12 +103,13 @@ def test_neg_exists_with_non_existent_data(self, key, ex, ex_code): except ex as exception: assert exception.code == ex_code - @pytest.mark.parametrize("key, record, meta, policy", [ - (('test', 'demo', 20), {"name": "John"}, - {'gen': 3, 'ttl': 1}, {'total_timeout': 2}), - ]) - def test_neg_exists_with_low_timeout( - self, key, record, meta, policy, put_data): + @pytest.mark.parametrize( + "key, record, meta, policy", + [ + (("test", "demo", 20), {"name": "John"}, {"gen": 3, "ttl": 1}, {"total_timeout": 2}), + ], + ) + def test_neg_exists_with_low_timeout(self, key, record, meta, policy, put_data): try: put_data(self.as_connection, key, record, meta, policy) except e.TimeoutError as exception: diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index 6913eefe7..46a1e2252 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -11,7 +11,8 @@ import aerospike from aerospike import exception as e -class TestGetMany(): + +class TestGetMany: @pytest.fixture(autouse=True) def setup(self, request, as_connection): self.keys = [] diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index 6d88bb62b..bb6fe2f63 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -726,30 +726,62 @@ def test_neg_put_with_policy_gen_GT_lesser(self): assert {"name": "John"} == bins self.as_connection.remove(key) - @pytest.mark.parametrize("key, record, meta, policy, ex_code, ex_msg", [ - (('test', 'demo', 1), {'name': 'john'}, - {'gen': "wrong", 'ttl': 25000}, {'total_timeout': 1000}, # Gen as string - -2, "Generation should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, - {'gen': 3, 'ttl': "25000"}, {'total_timeout': 1000}, # ttl as string - -2, "TTL should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, - {'gen': 3, 'ttl': 25000}, {'total_timeout': "1000"}, # Timeout as string - -2, "timeout is invalid"), - (('test', 'demo', 1), {'name': 'john'}, # Policy as string - {'gen': 3, 'ttl': 25000}, "Policy", - -2, "policy must be a dict"), - (('test', 'demo', 1), {'i': 13}, # Meta as string - "OK", {'total_timeout': 1000}, - -2, "meta must be a dict"), - (('test', 'demo', 1), {'i': 13}, # Meta as string - 1234, {'total_timeout': 1000}, - -2, "meta must be a dict"), - ]) - def test_neg_put_with_invalid_metadata( - self, key, record, meta, policy, ex_code, ex_msg, put_data): - """ - Invoke put() for a record with generation as string + @pytest.mark.parametrize( + "key, record, meta, policy, ex_code, ex_msg", + [ + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": "wrong", "ttl": 25000}, + {"total_timeout": 1000}, # Gen as string + -2, + "Generation should be an int or long", + ), + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": 3, "ttl": "25000"}, + {"total_timeout": 1000}, # ttl as string + -2, + "TTL should be an int or long", + ), + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": 3, "ttl": 25000}, + {"total_timeout": "1000"}, # Timeout as string + -2, + "timeout is invalid", + ), + ( + ("test", "demo", 1), + {"name": "john"}, # Policy as string + {"gen": 3, "ttl": 25000}, + "Policy", + -2, + "policy must be a dict", + ), + ( + ("test", "demo", 1), + {"i": 13}, # Meta as string + "OK", + {"total_timeout": 1000}, + -2, + "meta must be a dict", + ), + ( + ("test", "demo", 1), + {"i": 13}, # Meta as string + 1234, + {"total_timeout": 1000}, + -2, + "meta must be a dict", + ), + ], + ) + def test_neg_put_with_invalid_metadata(self, key, record, meta, policy, ex_code, ex_msg, put_data): + """ + Invoke put() for a record with generation as string """ with pytest.raises(e.ParamError): put_data(self.as_connection, key, record, meta, policy) diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 6554482d3..160ff79c4 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -337,8 +337,7 @@ def test_increment_with_unicode_bin(self): assert bins == {"age": 11, "name": "name1"} - @pytest.mark.skip(reason="This raises a system error." + - " Something else should be raised") + @pytest.mark.skip(reason="This raises a system error." + " Something else should be raised") def test_increment_with_integer_greaterthan_maxsize(self): """ Invoke increment() with integer greater then(2^63 - 1) diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 32ff01d73..8521d20a6 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -7,6 +7,7 @@ import aerospike + class TestIndex(object): @pytest.fixture(autouse=True) def setup(self, request, as_connection): diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index 96ff3e0ef..aec2f74d5 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -26,8 +26,8 @@ def _connect(self): def test_is_connected_before_connect(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and it is no-op to client + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client """ client = aerospike.client(self.config) assert client.is_connected() is True @@ -52,8 +52,8 @@ def test_pos_is_connected_after_multiple_connects(self): def test_is_connected_after_close(self): """ - Client call itself establishes connection. - Connect/Close are deprecated and it is no-op to client + Client call itself establishes connection. + Connect/Close are deprecated and it is no-op to client """ self._connect() assert self.client.is_connected() is True diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index 572ed0662..b120d76a9 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -325,5 +325,5 @@ def test_create_map_integer_index_unicode(self): ) assert response_code == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', u'uni_age_index', policy) - ensure_dropped_index(self.as_connection, 'test', u'uni_age_index') + self.as_connection.index_remove("test", "uni_age_index", policy) + ensure_dropped_index(self.as_connection, "test", "uni_age_index") diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 0ac4fb4ef..30c90ee43 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -56,13 +56,12 @@ def test_mapvaluesindex_with_correct_parameters(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") def test_mapvaluesindex_with_correct_parameters_no_policy(self): """ @@ -70,12 +69,12 @@ def test_mapvaluesindex_with_correct_parameters_no_policy(self): and the policy argument not passed """ retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index') + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index" + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index') - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index") + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") def test_mapvaluesindex_with_correct_parameters_numeric(self): """ @@ -99,9 +98,8 @@ def test_mapvalues_index_with_correct_parameters_set_length_extra(self): policy = {} with pytest.raises(e.InvalidRequest) as err_info: self.as_connection.index_map_values_create( - 'test', set_name, - 'string_map', aerospike.INDEX_STRING, - "test_string_map_index", policy) + "test", set_name, "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_REQUEST_INVALID @@ -139,23 +137,22 @@ def test_mapvaluesindex_with_incorrect_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map1', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map1", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") @pytest.mark.parametrize( "test_ns, test_set, test_bin, test_idx_name", ( - (None, 'demo', 'string_map', 'test_string_map_index'), - (1, 'demo', 'string_map', 'test_string_map_index'), - ('test', 1, 'string_map', 'test_string_map_index'), - ('test', 'demo', None, 'test_string_map_index'), - ('test', 'demo', 'string_map', None), - ('test', 'demo', 'string_map', 1), + (None, "demo", "string_map", "test_string_map_index"), + (1, "demo", "string_map", "test_string_map_index"), + ("test", 1, "string_map", "test_string_map_index"), + ("test", "demo", None, "test_string_map_index"), + ("test", "demo", "string_map", None), + ("test", "demo", "string_map", 1), ), ids=("ns is None", "ns is int", "set is int", "bin is None", "index name is none", "index name is int"), ) @@ -178,12 +175,11 @@ def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): with pytest.raises(e.ParamError) as err_info: self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', idx_val, - "test_string_map_index", policy) + "test", "demo", "string_map", idx_val, "test_string_map_index", policy + ) try: - self.as_connection.index_remove( - 'test', 'test_string_map_index') - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index") + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") except: pass @@ -219,21 +215,19 @@ def test_create_same_mapvaluesindex_multiple_times_different_bin(self): policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK with pytest.raises(e.IndexFoundError): retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'numeric_map', aerospike.INDEX_NUMERIC, - 'test_string_map_index', policy) - self.as_connection.index_remove( - 'test', 'test_string_map_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + "test", "demo", "numeric_map", aerospike.INDEX_NUMERIC, "test_string_map_index", policy + ) + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") - self.as_connection.index_remove( - 'test', 'test_string_map_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ @@ -242,26 +236,23 @@ def test_create_different_mapvaluesindex_multiple_times_same_bin(self): """ policy = {} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK try: retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index1', policy) - self.as_connection.index_remove( - 'test', 'test_string_map_index1', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index1') - self.as_connection.index_remove( - 'test', 'test_string_map_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index1", policy + ) + self.as_connection.index_remove("test", "test_string_map_index1", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index1") + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") except e.IndexFoundError: assert self.server_version < [6, 1] - self.as_connection.index_remove( - 'test', 'test_string_map_index', policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") def test_createmapvaluesindex_with_policy(self): """ @@ -282,13 +273,12 @@ def test_createmapvaluesindex_with_policystring(self): """ policy = {"timeout": 1000} retobj = self.as_connection.index_map_values_create( - 'test', 'demo', 'string_map', aerospike.INDEX_STRING, - 'test_string_map_index', policy) + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove('test', 'test_string_map_index', - policy) - ensure_dropped_index(self.as_connection, 'test', 'test_string_map_index') + self.as_connection.index_remove("test", "test_string_map_index", policy) + ensure_dropped_index(self.as_connection, "test", "test_string_map_index") """ This test case causes a db crash and hence has been commented. Work pending @@ -331,6 +321,5 @@ def test_create_map_values_integer_index_unicode(self): ) assert retobj == AerospikeStatus.AEROSPIKE_OK - self.as_connection.index_remove( - 'test', u'uni_age_index', policy) - ensure_dropped_index(self.as_connection, 'test', u'uni_age_index') + self.as_connection.index_remove("test", "uni_age_index", policy) + ensure_dropped_index(self.as_connection, "test", "uni_age_index") diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index 2b774dcc5..e7f697db8 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -437,7 +437,6 @@ def test_pos_operate_increment_nonexistent_key(self): self.as_connection.remove(key) - def test_pos_operate_write_set_to_aerospike_null(self): """ Invoke operate() with write command with bin set to aerospike_null diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index 0349ef193..a9c1f9d44 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -5,8 +5,7 @@ from aerospike import exception as e -class TestPrepend(): - +class TestPrepend: @pytest.fixture(autouse=True) def setup(self, request, as_connection): """ diff --git a/test/new_tests/test_put_async.py b/test/new_tests/test_put_async.py index 826b685d9..c4ce157bf 100644 --- a/test/new_tests/test_put_async.py +++ b/test/new_tests/test_put_async.py @@ -637,30 +637,62 @@ async def async_io(key=None, rec=None, meta=None, policy=None, serialize=None): assert {"name": "John"} == bins self.as_connection.remove(key) - @pytest.mark.parametrize("key, record, meta, policy, ex_code, ex_msg", [ - (('test', 'demo', 1), {'name': 'john'}, - {'gen': "wrong", 'ttl': 25000}, {'total_timeout': 1000}, # Gen as string - -2, "Generation should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, - {'gen': 3, 'ttl': "25000"}, {'total_timeout': 1000}, # ttl as string - -2, "TTL should be an int or long"), - (('test', 'demo', 1), {'name': 'john'}, - {'gen': 3, 'ttl': 25000}, {'total_timeout': "1000"}, # Timeout as string - -2, "timeout is invalid"), - (('test', 'demo', 1), {'name': 'john'}, # Policy as string - {'gen': 3, 'ttl': 25000}, "Policy", - -2, "policy must be a dict"), - (('test', 'demo', 1), {'i': 13}, # Meta as string - "OK", {'total_timeout': 1000}, - -2, "meta must be a dict"), - (('test', 'demo', 1), {'i': 13}, # Meta as string - 1234, {'total_timeout': 1000}, - -2, "meta must be a dict"), - ]) - def test_neg_put_with_invalid_metadata( - self, key, record, meta, policy, ex_code, ex_msg, put_data): - """ - Invoke put() for a record with generation as string + @pytest.mark.parametrize( + "key, record, meta, policy, ex_code, ex_msg", + [ + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": "wrong", "ttl": 25000}, + {"total_timeout": 1000}, # Gen as string + -2, + "Generation should be an int or long", + ), + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": 3, "ttl": "25000"}, + {"total_timeout": 1000}, # ttl as string + -2, + "TTL should be an int or long", + ), + ( + ("test", "demo", 1), + {"name": "john"}, + {"gen": 3, "ttl": 25000}, + {"total_timeout": "1000"}, # Timeout as string + -2, + "timeout is invalid", + ), + ( + ("test", "demo", 1), + {"name": "john"}, # Policy as string + {"gen": 3, "ttl": 25000}, + "Policy", + -2, + "policy must be a dict", + ), + ( + ("test", "demo", 1), + {"i": 13}, # Meta as string + "OK", + {"total_timeout": 1000}, + -2, + "meta must be a dict", + ), + ( + ("test", "demo", 1), + {"i": 13}, # Meta as string + 1234, + {"total_timeout": 1000}, + -2, + "meta must be a dict", + ), + ], + ) + def test_neg_put_with_invalid_metadata(self, key, record, meta, policy, ex_code, ex_msg, put_data): + """ + Invoke put() for a record with generation as string """ with pytest.raises(e.ParamError): put_data(self.as_connection, key, record, meta, policy) diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index 5fd528c08..32726bed6 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -75,12 +75,10 @@ class TestQueryApply(object): # These functions will run once for this test class, and do all of the # required setup and teardown - connection_setup_functions = (add_test_udf, add_test_parameter_udf, - add_indexes_to_client, create_records) - connection_teardown_functions = (drop_test_udf, drop_test_parameter_udf, - remove_indexes_from_client, drop_records) - age_range_pred = p.between('age', 0, 4) # Predicate for ages between [0,5) - no_set_key = ('test', None, "no_set") # Key for item stored in a namespace but not in a set + connection_setup_functions = (add_test_udf, add_test_parameter_udf, add_indexes_to_client, create_records) + connection_teardown_functions = (drop_test_udf, drop_test_parameter_udf, remove_indexes_from_client, drop_records) + age_range_pred = p.between("age", 0, 4) # Predicate for ages between [0,5) + no_set_key = ("test", None, "no_set") # Key for item stored in a namespace but not in a set @pytest.fixture(autouse=True) def setup(self, request, connection_with_config_funcs): diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index e60212a0f..51e777c9f 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -8,8 +8,7 @@ @pytest.mark.usefixtures("as_connection") -class TestRemove(): - +class TestRemove: @pytest.mark.xfail(reason="open bug #client-533") def test_pos_remove_with_existing_record(self): """ From 880d4f7cb35ae0811efbd7728ce7007214269c14 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 18:22:18 -0800 Subject: [PATCH 17/27] flake8 fixes --- test/misc/test_cases.py | 42 +++++++++++++------------ test/new_tests/test_aggregate.py | 5 --- test/new_tests/test_apply.py | 2 -- test/new_tests/test_batch_get_ops.py | 6 ++-- test/new_tests/test_close.py | 9 ------ test/new_tests/test_exists.py | 3 -- test/new_tests/test_get_many.py | 4 --- test/new_tests/test_get_node_names.py | 4 --- test/new_tests/test_get_nodes.py | 4 --- test/new_tests/test_index.py | 4 --- test/new_tests/test_info_all.py | 4 --- test/new_tests/test_info_random_node.py | 3 -- test/new_tests/test_info_single_node.py | 4 --- test/new_tests/test_job_info.py | 5 --- test/new_tests/test_mapvalues_index.py | 3 -- test/new_tests/test_udf_list.py | 4 --- test/new_tests/test_udf_put.py | 3 -- test/new_tests/test_udf_remove.py | 2 -- 18 files changed, 25 insertions(+), 86 deletions(-) diff --git a/test/misc/test_cases.py b/test/misc/test_cases.py index 93dcc8878..c5fa082d5 100644 --- a/test/misc/test_cases.py +++ b/test/misc/test_cases.py @@ -1142,16 +1142,18 @@ def test_create_user(aeros, namespace, setname): policy = {"timeout": 1000} user = "generic_client" password = "generic_client" - # roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "quota-4k-2k-role", "sindex-admin", "truncate"] + # roles = ["data-admin", "user-admin", "sys-admin", + # "read-write", "read-write-udf", "quota-4k-2k-role", + # "sindex-admin", "truncate"] roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "sindex-admin", "truncate"] - client = aeros.connect("admin", "admin") + aeros.connect("admin", "admin") - usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] + # usr_sys_admin_privs = [{"code": aerospike.PRIV_USER_ADMIN}, {"code": aerospike.PRIV_SYS_ADMIN}] try: aeros.admin_drop_role("quota-4k-2k-role") time.sleep(2) - except: + except Exception: pass # aeros.admin_create_role( # "quota-4k-2k-role", usr_sys_admin_privs, read_quota=40000, write_quota=20000) @@ -1160,32 +1162,32 @@ def test_create_user(aeros, namespace, setname): try: aeros.admin_drop_user(user, policy) time.sleep(2) - except: + except Exception: pass - status = aeros.admin_create_user(user, password, roles, policy) + aeros.admin_create_user(user, password, roles, policy) -def test_large_put(aeros, namespace, setname): +# def test_large_put(aeros, namespace, setname): - client = aeros.connect("generic_client", "generic_client") +# client = aeros.connect("generic_client", "generic_client") - # Records are addressable via a tuple of (namespace, set, primary key) - key = (namespace, setname, "send-key-test") +# # Records are addressable via a tuple of (namespace, set, primary key) +# key = (namespace, setname, "send-key-test") - f = open("/home/randersen/NYTZ131.json") - data = json.load(f) - f.close() +# f = open("/home/randersen/NYTZ131.json") +# data = json.load(f) +# f.close() - # Test to make sure the doc was properly loaded - print(data["TimeZoneName"]) +# # Test to make sure the doc was properly loaded +# print(data["TimeZoneName"]) - key = (namespace, setname, "America/New_York") +# key = (namespace, setname, "America/New_York") - try: - client.put(key, {"tzzone": data}) - except Exception as e: - print(e) +# try: +# client.put(key, {"tzzone": data}) +# except Exception as e: +# print(e) def get_aerospike(): diff --git a/test/new_tests/test_aggregate.py b/test/new_tests/test_aggregate.py index b5288a2c8..b92fc63ea 100644 --- a/test/new_tests/test_aggregate.py +++ b/test/new_tests/test_aggregate.py @@ -1,10 +1,5 @@ # -*- coding: utf-8 -*- import pytest -from aerospike import exception as e -from aerospike import predicates as p - -import aerospike - def add_stream_udf(client): client.udf_put("stream_example.lua", 0) diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index c9b81ab54..2a957c472 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -4,9 +4,7 @@ from .test_base_class import TestBaseClass from .as_status_codes import AerospikeStatus -import aerospike from aerospike_helpers import expressions as exp -from aerospike import exception as e """ diff --git a/test/new_tests/test_batch_get_ops.py b/test/new_tests/test_batch_get_ops.py index a6d77d297..78553caab 100644 --- a/test/new_tests/test_batch_get_ops.py +++ b/test/new_tests/test_batch_get_ops.py @@ -139,13 +139,13 @@ def test_batch_result_output_format(self): non_existent_key = ("test", "demo", "batch-ops-non_existent_key") rec = self.as_connection.batch_get_ops([key1, key2, non_existent_key], ops, policy) - print("\nThe record from batch_get_ops") - pp.pprint(rec) + # print("\nThe record from batch_get_ops") + # pp.pprint(rec) assert rec[0][-1] is not None assert rec[1][-1] is not None assert rec[2][-2] == e.RecordNotFound - assert rec[2][-1] == None + assert rec[2][-1] is None # rec = self.as_connection.select_many([non_existent_key], ['name']) # print("\nFor comparison, here's batch-read (select_many) is an array of records") diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index e596241c7..6a0d8f1fd 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -3,15 +3,6 @@ import pytest from .test_base_class import TestBaseClass import aerospike -from aerospike import exception as e - -aerospike = pytest.importorskip("aerospike") -try: - import aerospike - from aerospike import exception as e -except: - print("Please install aerospike python client.") - sys.exit(1) class TestClose: diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 7c075ee7d..0888a114c 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -4,9 +4,6 @@ import time from . import test_data -import aerospike -from aerospike import exception as e - class SomeClass(object): pass diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index 46a1e2252..b2ebfbd8d 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -8,10 +8,6 @@ except ImportError: from counter26 import Counter -import aerospike -from aerospike import exception as e - - class TestGetMany: @pytest.fixture(autouse=True) def setup(self, request, as_connection): diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index e516a11a9..104b1a8a3 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -1,9 +1,5 @@ # -*- coding: utf-8 -*- import pytest -from aerospike import exception as e - -import aerospike - @pytest.mark.usefixtures("as_connection") class TestGetNodeNames(object): diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index 1a83d4876..2ea43abae 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -1,10 +1,6 @@ # -*- coding: utf-8 -*- import pytest from .test_base_class import TestBaseClass -from aerospike import exception as e - -import aerospike - @pytest.mark.xfail(TestBaseClass.tls_in_use(), reason="get_nodes may fail when using TLS") @pytest.mark.usefixtures("as_connection") diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 8521d20a6..00c619190 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -3,10 +3,6 @@ import pytest from .as_status_codes import AerospikeStatus from .index_helpers import ensure_dropped_index -from aerospike import exception as e - -import aerospike - class TestIndex(object): @pytest.fixture(autouse=True) diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index 475aed127..57f7f5256 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -2,10 +2,6 @@ import pytest -from aerospike import exception as e - -import aerospike - @pytest.mark.usefixtures("as_connection", "connection_config") class TestInfo(object): diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index 58d4be1b8..bd28c0aa4 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -3,9 +3,6 @@ import time from .test_base_class import TestBaseClass -from aerospike import exception as e - -import aerospike @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index bc65f05dc..73fee6eda 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -3,10 +3,6 @@ import time from .test_base_class import TestBaseClass -from aerospike import exception as e - -import aerospike - @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") @pytest.mark.usefixtures("as_connection", "connection_config") diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index ad8228bba..5f604ea6b 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -1,10 +1,5 @@ # -*- coding: utf-8 -*- import pytest -from .as_status_codes import AerospikeStatus -from aerospike import exception as e - -import aerospike - class TestScanInfo(object): diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 30c90ee43..42f58a548 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -2,11 +2,8 @@ import pytest from .as_status_codes import AerospikeStatus -from aerospike import exception as e from .index_helpers import ensure_dropped_index -import aerospike - def add_maps_to_client(client): """ diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index f8b918c88..ce8bd8919 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -1,11 +1,7 @@ # -*- coding: utf-8 -*- import pytest -from aerospike import exception as e from .test_base_class import TestBaseClass -import aerospike - - class TestUdfList(object): def setup_class(cls): """ diff --git a/test/new_tests/test_udf_put.py b/test/new_tests/test_udf_put.py index 28659dd40..064bf6e4b 100644 --- a/test/new_tests/test_udf_put.py +++ b/test/new_tests/test_udf_put.py @@ -4,9 +4,6 @@ from .as_status_codes import AerospikeStatus from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist from .test_base_class import TestBaseClass -from aerospike import exception as e - -import aerospike @pytest.mark.usefixtures("as_connection") diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index 68ba2187a..abb8475ee 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -6,8 +6,6 @@ import pytest from .as_status_codes import AerospikeStatus from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist -import aerospike -from aerospike import exception as e def is_greater_451(version_str): From 4285514a2c9a94be0dc3913a3213e3776117010d Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 18:43:51 -0800 Subject: [PATCH 18/27] flake8 fixes --- test/misc/test_cases.py | 4 ++-- test/new_tests/test_aggregate.py | 3 +++ test/new_tests/test_apply.py | 1 + test/new_tests/test_exists.py | 1 + test/new_tests/test_exists_many.py | 1 - test/new_tests/test_get_many.py | 2 ++ test/new_tests/test_get_node_names.py | 1 + test/new_tests/test_get_nodes.py | 1 + test/new_tests/test_index.py | 2 ++ test/new_tests/test_info.py | 3 --- test/new_tests/test_info_all.py | 1 + test/new_tests/test_info_random_node.py | 1 + test/new_tests/test_info_single_node.py | 2 ++ test/new_tests/test_job_info.py | 3 +++ test/new_tests/test_mapvalues_index.py | 5 ++++- test/new_tests/test_udf_list.py | 2 ++ test/new_tests/test_udf_put.py | 1 + test/new_tests/test_udf_remove.py | 1 + 18 files changed, 28 insertions(+), 7 deletions(-) diff --git a/test/misc/test_cases.py b/test/misc/test_cases.py index c5fa082d5..3e653c83a 100644 --- a/test/misc/test_cases.py +++ b/test/misc/test_cases.py @@ -1142,8 +1142,8 @@ def test_create_user(aeros, namespace, setname): policy = {"timeout": 1000} user = "generic_client" password = "generic_client" - # roles = ["data-admin", "user-admin", "sys-admin", - # "read-write", "read-write-udf", "quota-4k-2k-role", + # roles = ["data-admin", "user-admin", "sys-admin", + # "read-write", "read-write-udf", "quota-4k-2k-role", # "sindex-admin", "truncate"] roles = ["data-admin", "user-admin", "sys-admin", "read-write", "read-write-udf", "sindex-admin", "truncate"] diff --git a/test/new_tests/test_aggregate.py b/test/new_tests/test_aggregate.py index b92fc63ea..07bbe02b3 100644 --- a/test/new_tests/test_aggregate.py +++ b/test/new_tests/test_aggregate.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- import pytest +from aerospike import exception as e +from aerospike import predicates as p + def add_stream_udf(client): client.udf_put("stream_example.lua", 0) diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index 2a957c472..512ab1b30 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -5,6 +5,7 @@ from .test_base_class import TestBaseClass from .as_status_codes import AerospikeStatus from aerospike_helpers import expressions as exp +from aerospike import exception as e """ diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index 0888a114c..f0c3d0874 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -3,6 +3,7 @@ import pytest import time from . import test_data +from aerospike import exception as e class SomeClass(object): diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 5ebefa269..561fd6540 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -8,7 +8,6 @@ except ImportError: from counter26 import Counter -import aerospike from aerospike import exception as e diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index b2ebfbd8d..241531ae8 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -7,6 +7,8 @@ from collections import Counter except ImportError: from counter26 import Counter +from aerospike import exception as e + class TestGetMany: @pytest.fixture(autouse=True) diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index 104b1a8a3..19ecaa3e8 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest + @pytest.mark.usefixtures("as_connection") class TestGetNodeNames(object): """ diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index 2ea43abae..fccf2aefd 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -2,6 +2,7 @@ import pytest from .test_base_class import TestBaseClass + @pytest.mark.xfail(TestBaseClass.tls_in_use(), reason="get_nodes may fail when using TLS") @pytest.mark.usefixtures("as_connection") class TestGetNodes(object): diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 00c619190..552093ae4 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -3,6 +3,8 @@ import pytest from .as_status_codes import AerospikeStatus from .index_helpers import ensure_dropped_index +from aerospike import exception as e + class TestIndex(object): @pytest.fixture(autouse=True) diff --git a/test/new_tests/test_info.py b/test/new_tests/test_info.py index 543b3acce..c3bc0b3ec 100644 --- a/test/new_tests/test_info.py +++ b/test/new_tests/test_info.py @@ -4,9 +4,6 @@ from aerospike import exception as e -import aerospike - - @pytest.mark.xfail(reason="Method is deprecated") @pytest.mark.usefixtures("as_connection", "connection_config") class TestInfo(object): diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index 57f7f5256..28f26c643 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest +from aerospike import exception as e @pytest.mark.usefixtures("as_connection", "connection_config") diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index bd28c0aa4..4586b5a82 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -3,6 +3,7 @@ import time from .test_base_class import TestBaseClass +from aerospike import exception as e @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index 73fee6eda..e2eb73f77 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -3,6 +3,8 @@ import time from .test_base_class import TestBaseClass +from aerospike import exception as e + @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") @pytest.mark.usefixtures("as_connection", "connection_config") diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index 5f604ea6b..88e76fc89 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- import pytest +from aerospike import exception as e + +import aerospike class TestScanInfo(object): diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index 42f58a548..b6c3ae300 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -2,8 +2,11 @@ import pytest from .as_status_codes import AerospikeStatus +from aerospike import exception as e from .index_helpers import ensure_dropped_index +import aerospike + def add_maps_to_client(client): """ @@ -177,7 +180,7 @@ def test_mapvaluesindex_with_invalid_idx_values(self, idx_val): try: self.as_connection.index_remove("test", "test_string_map_index") ensure_dropped_index(self.as_connection, "test", "test_string_map_index") - except: + except Exception: pass err_code = err_info.value.code diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index ce8bd8919..8acca6fab 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- import pytest from .test_base_class import TestBaseClass +from aerospike import exception as e + class TestUdfList(object): def setup_class(cls): diff --git a/test/new_tests/test_udf_put.py b/test/new_tests/test_udf_put.py index 064bf6e4b..2cd0c8f96 100644 --- a/test/new_tests/test_udf_put.py +++ b/test/new_tests/test_udf_put.py @@ -4,6 +4,7 @@ from .as_status_codes import AerospikeStatus from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist from .test_base_class import TestBaseClass +from aerospike import exception as e @pytest.mark.usefixtures("as_connection") diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index abb8475ee..410d85dd5 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -6,6 +6,7 @@ import pytest from .as_status_codes import AerospikeStatus from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist +from aerospike import exception as e def is_greater_451(version_str): From 05b0f045781c78c05746d3b3bb7f72fa6663b5d8 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 18:46:04 -0800 Subject: [PATCH 19/27] flake8 fixes --- test/new_tests/test_info.py | 1 + test/new_tests/test_job_info.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/new_tests/test_info.py b/test/new_tests/test_info.py index c3bc0b3ec..0678f583f 100644 --- a/test/new_tests/test_info.py +++ b/test/new_tests/test_info.py @@ -4,6 +4,7 @@ from aerospike import exception as e + @pytest.mark.xfail(reason="Method is deprecated") @pytest.mark.usefixtures("as_connection", "connection_config") class TestInfo(object): diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index 88e76fc89..6d512d543 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- import pytest from aerospike import exception as e - import aerospike + class TestScanInfo(object): udf_to_load = "bin_lua.lua" From 99bb1776cc94e5b1dc15f70331d07aba909081b1 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 18:50:10 -0800 Subject: [PATCH 20/27] clangformat fixes --- src/main/client/close.c | 82 ++++----- src/main/client/connect.c | 210 ++++++++++----------- src/main/client/type.c | 374 +++++++++++++++++++------------------- 3 files changed, 334 insertions(+), 332 deletions(-) diff --git a/src/main/client/close.c b/src/main/client/close.c index 8a8666652..4ce5f30ae 100644 --- a/src/main/client/close.c +++ b/src/main/client/close.c @@ -43,47 +43,47 @@ PyObject *AerospikeClient_Close(AerospikeClient *self, PyObject *args, PyObject *kwds) { - as_error err; - char *alias_to_search = NULL; - PyObject *py_persistent_item = NULL; - AerospikeGlobalHosts *global_host = NULL; - - // Initialize error - as_error_init(&err); - - if (!self || !self->as) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); - goto CLEANUP; - } - - if (!self->is_conn_16) { - goto CLEANUP; - } - - if (self->use_shared_connection) { - alias_to_search = return_search_string(self->as); - py_persistent_item = - PyDict_GetItemString(py_global_hosts, alias_to_search); - - if (py_persistent_item) { - global_host = (AerospikeGlobalHosts *)py_persistent_item; - // It is only safe to do a reference counted close if the - // local as is pointing to the global as - if (self->as == global_host->as) { - close_aerospike_object(self->as, &err, alias_to_search, - py_persistent_item, false); - } - } - - PyMem_Free(alias_to_search); - alias_to_search = NULL; - } - else { - Py_BEGIN_ALLOW_THREADS - aerospike_close(self->as, &err); - Py_END_ALLOW_THREADS - } - self->is_conn_16 = false; + as_error err; + char *alias_to_search = NULL; + PyObject *py_persistent_item = NULL; + AerospikeGlobalHosts *global_host = NULL; + + // Initialize error + as_error_init(&err); + + if (!self || !self->as) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, "Invalid aerospike object"); + goto CLEANUP; + } + + if (!self->is_conn_16) { + goto CLEANUP; + } + + if (self->use_shared_connection) { + alias_to_search = return_search_string(self->as); + py_persistent_item = + PyDict_GetItemString(py_global_hosts, alias_to_search); + + if (py_persistent_item) { + global_host = (AerospikeGlobalHosts *)py_persistent_item; + // It is only safe to do a reference counted close if the + // local as is pointing to the global as + if (self->as == global_host->as) { + close_aerospike_object(self->as, &err, alias_to_search, + py_persistent_item, false); + } + } + + PyMem_Free(alias_to_search); + alias_to_search = NULL; + } + else { + Py_BEGIN_ALLOW_THREADS + aerospike_close(self->as, &err); + Py_END_ALLOW_THREADS + } + self->is_conn_16 = false; CLEANUP: if (err.code != AEROSPIKE_OK) { diff --git a/src/main/client/connect.c b/src/main/client/connect.c index 19b38f84a..440ee4f71 100644 --- a/src/main/client/connect.c +++ b/src/main/client/connect.c @@ -38,96 +38,96 @@ */ PyObject *AerospikeClientConnect(AerospikeClient *self) { - as_error err; - as_error_init(&err); - char *alias_to_search = NULL; - bool free_alias_to_search = false; + as_error err; + as_error_init(&err); + char *alias_to_search = NULL; + bool free_alias_to_search = false; - if (!self || !self->as || !self->as->config.hosts || - !self->as->config.hosts->size) { - as_error_update(&err, AEROSPIKE_ERR_PARAM, - "Invalid aerospike object or hosts not configured"); - goto CLEANUP; - } + if (!self || !self->as || !self->as->config.hosts || + !self->as->config.hosts->size) { + as_error_update(&err, AEROSPIKE_ERR_PARAM, + "Invalid aerospike object or hosts not configured"); + goto CLEANUP; + } - alias_to_search = return_search_string(self->as); - free_alias_to_search = true; + alias_to_search = return_search_string(self->as); + free_alias_to_search = true; - if (self->use_shared_connection) { - PyObject *py_persistent_item = - PyDict_GetItemString(py_global_hosts, alias_to_search); - if (py_persistent_item) { - aerospike *as = ((AerospikeGlobalHosts *)py_persistent_item)->as; - //Destroy the initial aerospike object as it has to point to the one in - //the persistent list now - if (as != self->as) { - // If the client has previously connected - // Other clients may share its aerospike* pointer - // So it is not safe to destroy it - if (!self->has_connected) { - aerospike_destroy(self->as); - } - self->as = as; - self->as->config.shm_key = - ((AerospikeGlobalHosts *)py_persistent_item)->shm_key; + if (self->use_shared_connection) { + PyObject *py_persistent_item = + PyDict_GetItemString(py_global_hosts, alias_to_search); + if (py_persistent_item) { + aerospike *as = ((AerospikeGlobalHosts *)py_persistent_item)->as; + //Destroy the initial aerospike object as it has to point to the one in + //the persistent list now + if (as != self->as) { + // If the client has previously connected + // Other clients may share its aerospike* pointer + // So it is not safe to destroy it + if (!self->has_connected) { + aerospike_destroy(self->as); + } + self->as = as; + self->as->config.shm_key = + ((AerospikeGlobalHosts *)py_persistent_item)->shm_key; - //Increase ref count of global host entry - ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; - } - else { - // If there is a matching global host entry, - // and this client was disconnected, increment the ref_cnt of the global. - // If the client is already connected, do nothing. - if (!self->is_conn_16) { - ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; - } - } - goto CLEANUP; - } - } - //Generate unique shm_key - PyObject *py_key, *py_value; - Py_ssize_t pos = 0; - int flag = 0; - int shm_key; - if (self->as->config.use_shm) { - if (user_shm_key) { - shm_key = self->as->config.shm_key; - user_shm_key = false; - } - else { - shm_key = counter; - } - while (1) { - flag = 0; - while (PyDict_Next(py_global_hosts, &pos, &py_key, &py_value)) { - if (((AerospikeGlobalHosts *)py_value)->as->config.use_shm) { - if (((AerospikeGlobalHosts *)py_value)->shm_key == - shm_key) { - flag = 1; - break; - } - } - } - if (!flag) { - self->as->config.shm_key = shm_key; - break; - } - shm_key = shm_key + 1; - } - self->as->config.shm_key = shm_key; - } + //Increase ref count of global host entry + ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; + } + else { + // If there is a matching global host entry, + // and this client was disconnected, increment the ref_cnt of the global. + // If the client is already connected, do nothing. + if (!self->is_conn_16) { + ((AerospikeGlobalHosts *)py_persistent_item)->ref_cnt++; + } + } + goto CLEANUP; + } + } + //Generate unique shm_key + PyObject *py_key, *py_value; + Py_ssize_t pos = 0; + int flag = 0; + int shm_key; + if (self->as->config.use_shm) { + if (user_shm_key) { + shm_key = self->as->config.shm_key; + user_shm_key = false; + } + else { + shm_key = counter; + } + while (1) { + flag = 0; + while (PyDict_Next(py_global_hosts, &pos, &py_key, &py_value)) { + if (((AerospikeGlobalHosts *)py_value)->as->config.use_shm) { + if (((AerospikeGlobalHosts *)py_value)->shm_key == + shm_key) { + flag = 1; + break; + } + } + } + if (!flag) { + self->as->config.shm_key = shm_key; + break; + } + shm_key = shm_key + 1; + } + self->as->config.shm_key = shm_key; + } - Py_BEGIN_ALLOW_THREADS - aerospike_connect(self->as, &err); - Py_END_ALLOW_THREADS - if (err.code != AEROSPIKE_OK) { - goto CLEANUP; - } - if (self->use_shared_connection) { - PyObject *py_newobject = (PyObject *)AerospikeGobalHosts_New(self->as); - PyDict_SetItemString(py_global_hosts, alias_to_search, py_newobject); - } + Py_BEGIN_ALLOW_THREADS + aerospike_connect(self->as, &err); + Py_END_ALLOW_THREADS + if (err.code != AEROSPIKE_OK) { + goto CLEANUP; + } + if (self->use_shared_connection) { + PyObject *py_newobject = (PyObject *)AerospikeGobalHosts_New(self->as); + PyDict_SetItemString(py_global_hosts, alias_to_search, py_newobject); + } CLEANUP: if (free_alias_to_search && alias_to_search) { @@ -165,31 +165,31 @@ PyObject *AerospikeClientConnect(AerospikeClient *self) ******************************************************************************************************* */ PyObject *AerospikeClient_Connect(AerospikeClient *self, PyObject *args, - PyObject *kwds) + PyObject *kwds) { - as_error err; - as_error_init(&err); - PyObject *py_username = NULL; - PyObject *py_password = NULL; + as_error err; + as_error_init(&err); + PyObject *py_username = NULL; + PyObject *py_password = NULL; - if (self->as && aerospike_cluster_is_connected(self->as)) { - Py_INCREF(self); - return (PyObject *)self; - } + if (self->as && aerospike_cluster_is_connected(self->as)) { + Py_INCREF(self); + return (PyObject *)self; + } - if (PyArg_ParseTuple(args, "|OO:connect", &py_username, &py_password) == - false) { - return NULL; - } + if (PyArg_ParseTuple(args, "|OO:connect", &py_username, &py_password) == + false) { + return NULL; + } - if (py_username && PyString_Check(py_username) && py_password && - PyString_Check(py_password)) { - char *username = PyString_AsString(py_username); - char *password = PyString_AsString(py_password); - as_config_set_user(&self->as->config, username, password); - } + if (py_username && PyString_Check(py_username) && py_password && + PyString_Check(py_password)) { + char *username = PyString_AsString(py_username); + char *password = PyString_AsString(py_password); + as_config_set_user(&self->as->config, username, password); + } - return AerospikeClientConnect(self); + return AerospikeClientConnect(self); } /** diff --git a/src/main/client/type.c b/src/main/client/type.c index 308e7a05e..43d8e996f 100644 --- a/src/main/client/type.c +++ b/src/main/client/type.c @@ -1260,159 +1260,161 @@ static int AerospikeClient_Type_Init(AerospikeClient *self, PyObject *args, * Set the individual policy groups new in 3.0 * */ - if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - - PyObject *py_login_timeout = - PyDict_GetItemString(py_policies, "login_timeout_ms"); - if (py_login_timeout && PyInt_Check(py_login_timeout)) { - config.login_timeout_ms = PyInt_AsLong(py_login_timeout); - } - - PyObject *py_auth_mode = PyDict_GetItemString(py_policies, "auth_mode"); - if (py_auth_mode) { - if (PyInt_Check(py_auth_mode)) { - long auth_mode = PyInt_AsLong(py_auth_mode); - if ((long)AS_AUTH_INTERNAL == auth_mode || - (long)AS_AUTH_EXTERNAL == auth_mode || - (long)AS_AUTH_EXTERNAL_INSECURE == auth_mode || - (long)AS_AUTH_PKI == auth_mode) { - config.auth_mode = auth_mode; - } - else { - error_code = INIT_INVALID_AUTHMODE_ERR; - goto CONSTRUCTOR_ERROR; - } - } - else { - //it may come like auth_mode = None, for those non-integer cases, treat them as non-set - //error_code = INIT_INVALID_AUTHMODE_ERR; - //goto CONSTRUCTOR_ERROR; - } - } - } - - // thread_pool_size - PyObject *py_thread_pool_size = - PyDict_GetItemString(py_config, "thread_pool_size"); - if (py_thread_pool_size && PyInt_Check(py_thread_pool_size)) { - config.thread_pool_size = PyInt_AsLong(py_thread_pool_size); - } - - // max_threads (backward compatibility) - PyObject *py_max_threads = PyDict_GetItemString(py_config, "max_threads"); - if (py_max_threads && - (PyInt_Check(py_max_threads) || PyLong_Check(py_max_threads))) { - config.max_conns_per_node = PyInt_AsLong(py_max_threads); - } - - // max_conns_per_node - PyObject *py_max_conns = - PyDict_GetItemString(py_config, "max_conns_per_node"); - if (py_max_conns && - (PyInt_Check(py_max_conns) || PyLong_Check(py_max_conns))) { - config.max_conns_per_node = PyInt_AsLong(py_max_conns); - } - - //conn_timeout_ms - PyObject *py_connect_timeout = - PyDict_GetItemString(py_config, "connect_timeout"); - if (py_connect_timeout && PyInt_Check(py_connect_timeout)) { - config.conn_timeout_ms = PyInt_AsLong(py_connect_timeout); - } - - //Whether to utilize shared connection - PyObject *py_share_connect = - PyDict_GetItemString(py_config, "use_shared_connection"); - if (py_share_connect) { - self->use_shared_connection = PyObject_IsTrue(py_share_connect); - } - - PyObject *py_send_bool_as = PyDict_GetItemString(py_config, "send_bool_as"); - if (py_send_bool_as != NULL && PyLong_Check(py_send_bool_as)) { - int send_bool_as_temp = PyLong_AsLong(py_send_bool_as); - if (send_bool_as_temp >= SEND_BOOL_AS_PY_BYTES && - send_bool_as_temp <= SEND_BOOL_AS_AS_BOOL) { - self->send_bool_as = send_bool_as_temp; - } - } - - //compression_threshold - PyObject *py_compression_threshold = - PyDict_GetItemString(py_config, "compression_threshold"); - if (py_compression_threshold && PyInt_Check(py_compression_threshold)) { - int compression_value = PyInt_AsLong(py_compression_threshold); - if (compression_value >= 0) { - config.policies.write.compression_threshold = compression_value; - } - else { - error_code = INIT_COMPRESSION_ERR; - goto CONSTRUCTOR_ERROR; - } - } - - PyObject *py_tend_interval = - PyDict_GetItemString(py_config, "tend_interval"); - if (py_tend_interval && PyInt_Check(py_tend_interval)) { - config.tender_interval = PyInt_AsLong(py_tend_interval); - } - - PyObject *py_cluster_name = PyDict_GetItemString(py_config, "cluster_name"); - if (py_cluster_name && PyString_Check(py_cluster_name)) { - as_config_set_cluster_name(&config, - strdup(PyString_AsString(py_cluster_name))); - } - - //strict_types check - self->strict_types = true; - PyObject *py_strict_types = PyDict_GetItemString(py_config, "strict_types"); - if (py_strict_types && PyBool_Check(py_strict_types)) { - if (Py_False == py_strict_types) { - self->strict_types = false; - } - } - - if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { - error_code = INIT_POLICY_PARAM_ERR; - goto CONSTRUCTOR_ERROR; - } - - PyObject *py_max_socket_idle = NULL; - py_max_socket_idle = PyDict_GetItemString(py_config, "max_socket_idle"); - if (py_max_socket_idle && PyInt_Check(py_max_socket_idle)) { - long max_socket_idle = PyInt_AsLong(py_max_socket_idle); - if (max_socket_idle >= 0) { - config.max_socket_idle = (uint32_t)max_socket_idle; - } - } - - PyObject *py_fail_if_not_connected = PyDict_GetItemString(py_config, "fail_if_not_connected"); - if (py_fail_if_not_connected && PyBool_Check(py_fail_if_not_connected)) { - config.fail_if_not_connected = PyObject_IsTrue(py_fail_if_not_connected); - } - - PyObject *py_user_name = PyDict_GetItemString(py_config, "user"); - PyObject *py_user_pwd = PyDict_GetItemString(py_config, "password"); - if (py_user_name && PyString_Check(py_user_name) && py_user_pwd && - PyString_Check(py_user_pwd)) { - char *username = PyString_AsString(py_user_name); - char *password = PyString_AsString(py_user_pwd); - as_config_set_user(&config, username, password); - } - - self->as = aerospike_new(&config); - - if (AerospikeClientConnect(self) == NULL) { - return -1; - } - - return 0; + if (set_subpolicies(&config, py_policies) != AEROSPIKE_OK) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + + PyObject *py_login_timeout = + PyDict_GetItemString(py_policies, "login_timeout_ms"); + if (py_login_timeout && PyInt_Check(py_login_timeout)) { + config.login_timeout_ms = PyInt_AsLong(py_login_timeout); + } + + PyObject *py_auth_mode = PyDict_GetItemString(py_policies, "auth_mode"); + if (py_auth_mode) { + if (PyInt_Check(py_auth_mode)) { + long auth_mode = PyInt_AsLong(py_auth_mode); + if ((long)AS_AUTH_INTERNAL == auth_mode || + (long)AS_AUTH_EXTERNAL == auth_mode || + (long)AS_AUTH_EXTERNAL_INSECURE == auth_mode || + (long)AS_AUTH_PKI == auth_mode) { + config.auth_mode = auth_mode; + } + else { + error_code = INIT_INVALID_AUTHMODE_ERR; + goto CONSTRUCTOR_ERROR; + } + } + else { + //it may come like auth_mode = None, for those non-integer cases, treat them as non-set + //error_code = INIT_INVALID_AUTHMODE_ERR; + //goto CONSTRUCTOR_ERROR; + } + } + } + + // thread_pool_size + PyObject *py_thread_pool_size = + PyDict_GetItemString(py_config, "thread_pool_size"); + if (py_thread_pool_size && PyInt_Check(py_thread_pool_size)) { + config.thread_pool_size = PyInt_AsLong(py_thread_pool_size); + } + + // max_threads (backward compatibility) + PyObject *py_max_threads = PyDict_GetItemString(py_config, "max_threads"); + if (py_max_threads && + (PyInt_Check(py_max_threads) || PyLong_Check(py_max_threads))) { + config.max_conns_per_node = PyInt_AsLong(py_max_threads); + } + + // max_conns_per_node + PyObject *py_max_conns = + PyDict_GetItemString(py_config, "max_conns_per_node"); + if (py_max_conns && + (PyInt_Check(py_max_conns) || PyLong_Check(py_max_conns))) { + config.max_conns_per_node = PyInt_AsLong(py_max_conns); + } + + //conn_timeout_ms + PyObject *py_connect_timeout = + PyDict_GetItemString(py_config, "connect_timeout"); + if (py_connect_timeout && PyInt_Check(py_connect_timeout)) { + config.conn_timeout_ms = PyInt_AsLong(py_connect_timeout); + } + + //Whether to utilize shared connection + PyObject *py_share_connect = + PyDict_GetItemString(py_config, "use_shared_connection"); + if (py_share_connect) { + self->use_shared_connection = PyObject_IsTrue(py_share_connect); + } + + PyObject *py_send_bool_as = PyDict_GetItemString(py_config, "send_bool_as"); + if (py_send_bool_as != NULL && PyLong_Check(py_send_bool_as)) { + int send_bool_as_temp = PyLong_AsLong(py_send_bool_as); + if (send_bool_as_temp >= SEND_BOOL_AS_PY_BYTES && + send_bool_as_temp <= SEND_BOOL_AS_AS_BOOL) { + self->send_bool_as = send_bool_as_temp; + } + } + + //compression_threshold + PyObject *py_compression_threshold = + PyDict_GetItemString(py_config, "compression_threshold"); + if (py_compression_threshold && PyInt_Check(py_compression_threshold)) { + int compression_value = PyInt_AsLong(py_compression_threshold); + if (compression_value >= 0) { + config.policies.write.compression_threshold = compression_value; + } + else { + error_code = INIT_COMPRESSION_ERR; + goto CONSTRUCTOR_ERROR; + } + } + + PyObject *py_tend_interval = + PyDict_GetItemString(py_config, "tend_interval"); + if (py_tend_interval && PyInt_Check(py_tend_interval)) { + config.tender_interval = PyInt_AsLong(py_tend_interval); + } + + PyObject *py_cluster_name = PyDict_GetItemString(py_config, "cluster_name"); + if (py_cluster_name && PyString_Check(py_cluster_name)) { + as_config_set_cluster_name(&config, + strdup(PyString_AsString(py_cluster_name))); + } + + //strict_types check + self->strict_types = true; + PyObject *py_strict_types = PyDict_GetItemString(py_config, "strict_types"); + if (py_strict_types && PyBool_Check(py_strict_types)) { + if (Py_False == py_strict_types) { + self->strict_types = false; + } + } + + if (set_rack_aware_config(&config, py_config) != INIT_SUCCESS) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + if (set_use_services_alternate(&config, py_config) != INIT_SUCCESS) { + error_code = INIT_POLICY_PARAM_ERR; + goto CONSTRUCTOR_ERROR; + } + + PyObject *py_max_socket_idle = NULL; + py_max_socket_idle = PyDict_GetItemString(py_config, "max_socket_idle"); + if (py_max_socket_idle && PyInt_Check(py_max_socket_idle)) { + long max_socket_idle = PyInt_AsLong(py_max_socket_idle); + if (max_socket_idle >= 0) { + config.max_socket_idle = (uint32_t)max_socket_idle; + } + } + + PyObject *py_fail_if_not_connected = + PyDict_GetItemString(py_config, "fail_if_not_connected"); + if (py_fail_if_not_connected && PyBool_Check(py_fail_if_not_connected)) { + config.fail_if_not_connected = + PyObject_IsTrue(py_fail_if_not_connected); + } + + PyObject *py_user_name = PyDict_GetItemString(py_config, "user"); + PyObject *py_user_pwd = PyDict_GetItemString(py_config, "password"); + if (py_user_name && PyString_Check(py_user_name) && py_user_pwd && + PyString_Check(py_user_pwd)) { + char *username = PyString_AsString(py_user_name); + char *password = PyString_AsString(py_user_pwd); + as_config_set_user(&config, username, password); + } + + self->as = aerospike_new(&config); + + if (AerospikeClientConnect(self) == NULL) { + return -1; + } + + return 0; CONSTRUCTOR_ERROR: @@ -1661,37 +1663,37 @@ PyTypeObject *AerospikeClient_Ready() AerospikeClient *AerospikeClient_New(PyObject *parent, PyObject *args, PyObject *kwds) { - AerospikeClient *self = (AerospikeClient *)AerospikeClient_Type.tp_new( - &AerospikeClient_Type, args, kwds); - as_error err; - as_error_init(&err); - int return_code = 0; - return_code = AerospikeClient_Type.tp_init((PyObject *)self, args, kwds); - - switch (return_code) { - // 0 Is success - case 0: { - return self; - } - case -1: { - if (PyErr_Occurred()) { - return NULL; - } - break; - } - default: { - if (PyErr_Occurred()) { - return NULL; - } - break; - } - } - - PyObject *py_err = NULL; - as_error_update(&err, AEROSPIKE_ERR_PARAM, "Failed to construct object"); - error_to_pyobject(&err, &py_err); - PyObject *exception_type = raise_exception(&err); - PyErr_SetObject(exception_type, py_err); - Py_DECREF(py_err); - return NULL; + AerospikeClient *self = (AerospikeClient *)AerospikeClient_Type.tp_new( + &AerospikeClient_Type, args, kwds); + as_error err; + as_error_init(&err); + int return_code = 0; + return_code = AerospikeClient_Type.tp_init((PyObject *)self, args, kwds); + + switch (return_code) { + // 0 Is success + case 0: { + return self; + } + case -1: { + if (PyErr_Occurred()) { + return NULL; + } + break; + } + default: { + if (PyErr_Occurred()) { + return NULL; + } + break; + } + } + + PyObject *py_err = NULL; + as_error_update(&err, AEROSPIKE_ERR_PARAM, "Failed to construct object"); + error_to_pyobject(&err, &py_err); + PyObject *exception_type = raise_exception(&err); + PyErr_SetObject(exception_type, py_err); + Py_DECREF(py_err); + return NULL; } From e5e66ce3084478fdf9ac2848232e2835c5eadfeb Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 18:52:32 -0800 Subject: [PATCH 21/27] clangformat fixes --- src/main/client/batch_get_ops.c | 89 +++++++++++++++++---------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/src/main/client/batch_get_ops.c b/src/main/client/batch_get_ops.c index 2ab7b259e..abd20b29d 100644 --- a/src/main/client/batch_get_ops.c +++ b/src/main/client/batch_get_ops.c @@ -51,50 +51,51 @@ typedef struct { static bool batch_read_operate_cb(const as_batch_read *results, uint32_t n, void *udata) { - // Extract callback user-data - LocalData *data = (LocalData *)udata; - as_batch_read *r = NULL; - - // Lock Python State - PyGILState_STATE gstate; - gstate = PyGILState_Ensure(); - - for (uint32_t i = 0; i < n; i++) { - PyObject *py_key = NULL; - PyObject *py_rec = NULL; - PyObject *py_rec_meta = NULL; - PyObject *py_rec_bins = NULL; - as_record *rec = NULL; - as_error err; - - r = (as_batch_read *)&results[i]; - py_key = PyList_GetItem(data->py_keys, i); - // key_to_pyobject(&err, &r->key, &py_key); - rec = &r->record; - - as_error_init(&err); - err.code = r->result; - - if (err.code == AEROSPIKE_OK) { - metadata_to_pyobject(&err, rec, &py_rec_meta); - bins_to_pyobject(data->client, &err, rec, &py_rec_bins, false); - } else { - py_rec_meta = raise_exception(&err); - Py_INCREF(Py_None); - py_rec_bins = Py_None; - } - - py_rec = PyTuple_New(3); - PyTuple_SetItem(py_rec, 0, py_key); - PyTuple_SetItem(py_rec, 1, py_rec_meta); - PyTuple_SetItem(py_rec, 2, py_rec_bins); - - PyList_Append(data->py_results, py_rec); - } - - PyGILState_Release(gstate); - - return true; + // Extract callback user-data + LocalData *data = (LocalData *)udata; + as_batch_read *r = NULL; + + // Lock Python State + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); + + for (uint32_t i = 0; i < n; i++) { + PyObject *py_key = NULL; + PyObject *py_rec = NULL; + PyObject *py_rec_meta = NULL; + PyObject *py_rec_bins = NULL; + as_record *rec = NULL; + as_error err; + + r = (as_batch_read *)&results[i]; + py_key = PyList_GetItem(data->py_keys, i); + // key_to_pyobject(&err, &r->key, &py_key); + rec = &r->record; + + as_error_init(&err); + err.code = r->result; + + if (err.code == AEROSPIKE_OK) { + metadata_to_pyobject(&err, rec, &py_rec_meta); + bins_to_pyobject(data->client, &err, rec, &py_rec_bins, false); + } + else { + py_rec_meta = raise_exception(&err); + Py_INCREF(Py_None); + py_rec_bins = Py_None; + } + + py_rec = PyTuple_New(3); + PyTuple_SetItem(py_rec, 0, py_key); + PyTuple_SetItem(py_rec, 1, py_rec_meta); + PyTuple_SetItem(py_rec, 2, py_rec_bins); + + PyList_Append(data->py_results, py_rec); + } + + PyGILState_Release(gstate); + + return true; } /** From 1f957b4bd4585bb379591508f7475793c9567cfd Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 19:20:45 -0800 Subject: [PATCH 22/27] point to latest c-client stage branch --- .gitmodules | 2 +- aerospike-client-c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 160000 aerospike-client-c diff --git a/.gitmodules b/.gitmodules index 136ba68cb..52ecea4af 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "aerospike-client-c"] path = aerospike-client-c # url = git@github.com:aerospike/aerospike-client-c.git - url = https://github.com/aerospike/aerospike-client-c.git + url = git@github.com:aerospike/aerospike-client-c.git branch = stage diff --git a/aerospike-client-c b/aerospike-client-c new file mode 160000 index 000000000..46b285e3c --- /dev/null +++ b/aerospike-client-c @@ -0,0 +1 @@ +Subproject commit 46b285e3c9a24da5e4b5d1d10f353210bcd461a8 From fa25aa08efbb04409ea2b42b92d1052d4d79f79d Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Mon, 7 Nov 2022 19:28:30 -0800 Subject: [PATCH 23/27] config rollback --- test/config.conf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/config.conf b/test/config.conf index 34aa40486..e9fd3924a 100644 --- a/test/config.conf +++ b/test/config.conf @@ -1,7 +1,7 @@ [community-edition] -hosts:bob-cluster-a:3000 +hosts: 127.0.0.1:3000 [enterprise-edition] -hosts :172.28.0.1:3000 -user :generic_client -password :generic_client +hosts : +user : +password : From 65d909133a907cc18ed8861ce50b450a88372ce3 Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Tue, 8 Nov 2022 12:34:46 -0800 Subject: [PATCH 24/27] add negative client connect test cases --- test/misc/test_cases.py | 2 +- test/new_tests/test_aggregate.py | 27 +++++++++++++++++++ test/new_tests/test_append.py | 16 +++++++++++ test/new_tests/test_apply.py | 17 ++++++++++++ test/new_tests/test_batch_apply.py | 16 +++++++++++ test/new_tests/test_batch_operate.py | 14 ++++++++++ test/new_tests/test_batch_remove.py | 13 +++++++++ test/new_tests/test_batch_write.py | 13 +++++++++ test/new_tests/test_cdt_index.py | 24 +++++++++++++++++ test/new_tests/test_close.py | 15 +++++++++++ test/new_tests/test_exists.py | 18 +++++++++++++ test/new_tests/test_exists_many.py | 35 +++++++++++++++++++++++++ test/new_tests/test_get_async.py | 17 ++++++++++++ test/new_tests/test_get_many.py | 10 +++++++ test/new_tests/test_get_node_names.py | 21 +++++++++++++++ test/new_tests/test_get_nodes.py | 20 ++++++++++++++ test/new_tests/test_get_put.py | 29 ++++++++++++++++++++ test/new_tests/test_get_udf.py | 16 +++++++++++ test/new_tests/test_increment.py | 17 ++++++++++++ test/new_tests/test_index.py | 16 +++++++++++ test/new_tests/test_info.py | 16 ++++++++++- test/new_tests/test_info_all.py | 13 +++++++++ test/new_tests/test_info_random_node.py | 14 ++++++++++ test/new_tests/test_info_single_node.py | 14 ++++++++++ test/new_tests/test_is_connected.py | 1 - test/new_tests/test_job_info.py | 17 ++++++++++++ test/new_tests/test_list_append.py | 9 +++++++ test/new_tests/test_list_index.py | 18 +++++++++++++ test/new_tests/test_mapkeys_index.py | 18 +++++++++++++ test/new_tests/test_mapvalues_index.py | 19 ++++++++++++++ test/new_tests/test_operate.py | 20 ++++++++++++++ test/new_tests/test_operate_helpers.py | 13 +++++++++ test/new_tests/test_operate_ordered.py | 20 ++++++++++++++ test/new_tests/test_prepend.py | 16 +++++++++++ test/new_tests/test_put_async.py | 22 ++++++++++++++++ test/new_tests/test_query.py | 21 +++++++++++++++ test/new_tests/test_query_apply.py | 15 +++++++++++ test/new_tests/test_remove.py | 15 +++++++++++ test/new_tests/test_remove_bin.py | 17 ++++++++++++ test/new_tests/test_scan_apply.py | 15 +++++++++++ test/new_tests/test_select.py | 12 +++++++++ test/new_tests/test_select_many.py | 13 +++++++++ test/new_tests/test_touch.py | 16 +++++++++++ test/new_tests/test_udf_list.py | 22 +++++++++++++++- test/new_tests/test_udf_put.py | 18 +++++++++++++ test/new_tests/test_udf_remove.py | 19 ++++++++++++++ 46 files changed, 765 insertions(+), 4 deletions(-) diff --git a/test/misc/test_cases.py b/test/misc/test_cases.py index 3e653c83a..b7dc1a4d9 100644 --- a/test/misc/test_cases.py +++ b/test/misc/test_cases.py @@ -1194,7 +1194,7 @@ def get_aerospike(): # tls_name = 'bob-cluster-a' tls_name = "172.31.1.163" - endpoints = [("172.31.1.163", 3000)] + endpoints = [("172.28.0.1", 3000)] hosts = [(address[0], address[1], tls_name) for address in endpoints] diff --git a/test/new_tests/test_aggregate.py b/test/new_tests/test_aggregate.py index 07bbe02b3..7f6bbfdce 100644 --- a/test/new_tests/test_aggregate.py +++ b/test/new_tests/test_aggregate.py @@ -2,6 +2,9 @@ import pytest from aerospike import exception as e from aerospike import predicates as p +from .test_base_class import TestBaseClass + +import aerospike def add_stream_udf(client): @@ -259,6 +262,30 @@ def callback(value): except e.ClientError as exception: assert exception.code == -1 + def test_neg_aggregate_with_correct_parameters_without_connection(self): + """ + Invoke aggregate() with correct arguments without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + try: + query = client1.query("test", "demo") + query.select("name", "test_age") + query.where(p.between("test_age", 1, 5)) + query.apply("stream_example", "count") + + records = [] + + def user_callback(value): + records.append(value) + + query.foreach(user_callback) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_aggregate_with_extra_parameter(self): """ Invoke aggregate() with extra parameter diff --git a/test/new_tests/test_append.py b/test/new_tests/test_append.py index 65c5dbfdd..c72c911a4 100644 --- a/test/new_tests/test_append.py +++ b/test/new_tests/test_append.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass from aerospike import exception as e import aerospike @@ -423,6 +424,21 @@ def test_neg_append_parameters_as_none(self, key, bin, ex_code, ex_msg): with pytest.raises(e.ParamError): self.as_connection.append(key, bin, "str") + def test_neg_append_with_correct_parameters_without_connection(self): + """ + Invoke append() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + key = ("test", "demo", 1) + + try: + client1.append(key, "name", "str") + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_append_with_low_timeout(self): """ Invoke append() with low timeout in policy diff --git a/test/new_tests/test_apply.py b/test/new_tests/test_apply.py index 512ab1b30..85fa81e51 100644 --- a/test/new_tests/test_apply.py +++ b/test/new_tests/test_apply.py @@ -4,6 +4,7 @@ from .test_base_class import TestBaseClass from .as_status_codes import AerospikeStatus +import aerospike from aerospike_helpers import expressions as exp from aerospike import exception as e @@ -290,6 +291,22 @@ def test_apply_with_unicode_module_and_function(self): assert bins["name"] == ["name1", "car"] assert retval == 0 + def test_apply_with_correct_parameters_without_connection(self): + """ + Invoke apply() with correct arguments without connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.apply(key, "sample", "list_append", ["name", "car"]) + + err_code = err_info.value.code + + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_apply_with_arg_causing_error(self): """ Invoke apply() with ia string argument when integer is required diff --git a/test/new_tests/test_batch_apply.py b/test/new_tests/test_batch_apply.py index fabdf752c..649229790 100644 --- a/test/new_tests/test_batch_apply.py +++ b/test/new_tests/test_batch_apply.py @@ -324,3 +324,19 @@ def test_batch_apply_neg(self, name, keys, module, function, args, policy_batch, with pytest.raises(exp_res): self.as_connection.batch_apply(keys, module, function, args, policy_batch, policy_batch_apply) + + def test_batch_apply_neg_connection(self): + """ + Test batch_apply negative with bad connection. + """ + + module = "lua_mod" + function = "lua_func" + args = [] + keys = [] + + exp_res = e.ClientError + + with pytest.raises(exp_res): + bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) + bad_client.batch_apply(keys, module, function, args) diff --git a/test/new_tests/test_batch_operate.py b/test/new_tests/test_batch_operate.py index ebe046ead..5546b9b1a 100644 --- a/test/new_tests/test_batch_operate.py +++ b/test/new_tests/test_batch_operate.py @@ -251,3 +251,17 @@ def test_batch_operate_neg(self, name, keys, ops, policy_batch, policy_batch_wri with pytest.raises(exp_res): self.as_connection.batch_operate(keys, ops, policy_batch, policy_batch_write) + + def test_batch_operate_neg_connection(self): + """ + Test batch_operate negative with bad connection. + """ + + keys = [] + ops = ["doesn't_matter"] + + exp_res = e.ClientError + + with pytest.raises(exp_res): + bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) + bad_client.batch_operate(keys, ops) diff --git a/test/new_tests/test_batch_remove.py b/test/new_tests/test_batch_remove.py index 027267eee..d77d26a48 100644 --- a/test/new_tests/test_batch_remove.py +++ b/test/new_tests/test_batch_remove.py @@ -186,3 +186,16 @@ def test_batch_remove_neg(self, name, keys, policy_batch, policy_batch_remove, e with pytest.raises(exp_res): self.as_connection.batch_remove(keys, policy_batch, policy_batch_remove) + + def test_batch_remove_neg_connection(self): + """ + Test batch_remove negative with bad connection. + """ + + keys = [] + + exp_res = e.ClientError + + with pytest.raises(exp_res): + bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) + bad_client.batch_remove(keys) diff --git a/test/new_tests/test_batch_write.py b/test/new_tests/test_batch_write.py index 5b5d1d967..1d54df3de 100644 --- a/test/new_tests/test_batch_write.py +++ b/test/new_tests/test_batch_write.py @@ -453,3 +453,16 @@ def test_batch_write_neg(self, name, batch_records, policy, exp_res): with pytest.raises(exp_res): self.as_connection.batch_write(batch_records, policy) + + def test_batch_write_neg_connection(self): + """ + Test batch_write negative with bad connection. + """ + + batch_records = [] + + exp_res = e.ClientError + + with pytest.raises(exp_res): + bad_client = aerospike.client({"hosts": [("bad_addr", 3000)]}) + bad_client.batch_write(batch_records) diff --git a/test/new_tests/test_cdt_index.py b/test/new_tests/test_cdt_index.py index 60415bb71..9dccbaf5e 100644 --- a/test/new_tests/test_cdt_index.py +++ b/test/new_tests/test_cdt_index.py @@ -697,6 +697,30 @@ def test_neg_cdtindex_with_incorrect_set(self): self.as_connection.index_remove("test", "test_numeric_list_cdt_index", policy) ensure_dropped_index(self.as_connection, "test", "test_numeric_list_cdt_index") + def test_neg_cdtindex_with_correct_parameters_no_connection(self): + """ + Invoke index_cdt_create() with correct arguments no connection + """ + policy = {} + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + try: + client1.index_cdt_create( + "test", + "demo", + "string_list", + aerospike.INDEX_TYPE_LIST, + aerospike.INDEX_STRING, + "test_string_list_cdt_index", + {"ctx": ctx_list_index}, + policy, + ) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_cdtindex_with_no_paramters(self): """ Invoke index_cdt_create() without any mandatory parameters. diff --git a/test/new_tests/test_close.py b/test/new_tests/test_close.py index 6a0d8f1fd..d2598fd8d 100644 --- a/test/new_tests/test_close.py +++ b/test/new_tests/test_close.py @@ -3,6 +3,7 @@ import pytest from .test_base_class import TestBaseClass import aerospike +from aerospike import exception as e class TestClose: @@ -21,6 +22,20 @@ def test_pos_close(self): self.closeobject = self.client.close() assert self.closeobject is None + def test_pos_close_without_connection(self): + """ + Invoke close() without connection + """ + config = TestBaseClass.get_connection_config() + self.client = aerospike.client(config) + self.client.close() + + try: + self.closeobject = self.client.close() + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_close(self): """ Invoke close() after negative connect diff --git a/test/new_tests/test_exists.py b/test/new_tests/test_exists.py index f0c3d0874..4d86573c1 100644 --- a/test/new_tests/test_exists.py +++ b/test/new_tests/test_exists.py @@ -3,6 +3,9 @@ import pytest import time from . import test_data + +from .test_base_class import TestBaseClass +import aerospike from aerospike import exception as e @@ -101,6 +104,21 @@ def test_neg_exists_with_non_existent_data(self, key, ex, ex_code): except ex as exception: assert exception.code == ex_code + def test_neg_exists_with_only_key_without_connection(self): + """ + Invoke exists() with a key and not policy's dict and no connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + try: + key, _ = client1.exists(key) + + except e.ClusterError as exception: + assert exception.code == 11 + @pytest.mark.parametrize( "key, record, meta, policy", [ diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index 561fd6540..b6bee490b 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -8,6 +8,8 @@ except ImportError: from counter26 import Counter +from .test_base_class import TestBaseClass +import aerospike from aerospike import exception as e @@ -25,6 +27,20 @@ def test_pos_exists_many_without_policy(self, put_data): assert isinstance(records, list) assert len(records) == rec_length + def test_pos_exists_many_with_proper_parameters_without_connection(self, put_data): + self.keys = [] + rec_length = 5 + for i in range(rec_length): + key = ("test", "demo", i) + record = {"name": "name%s" % (str(i)), "age": i} + put_data(self.as_connection, key, record) + self.keys.append(key) + records = self.as_connection.exists_many(self.keys, {"total_timeout": 1200}) + + assert isinstance(records, list) + assert len(records) == rec_length + assert Counter([x[0][2] for x in records]) == Counter([0, 1, 2, 3, 4]) + def test_pos_exists_many_with_none_policy(self, put_data): self.keys = [] rec_length = 5 @@ -179,6 +195,25 @@ def test_neg_exists_many_with_invalid_timeout(self, put_data): with pytest.raises(e.ParamError): self.as_connection.exists_many(self.keys, policies) + def test_neg_exists_many_with_proper_parameters_without_connection(self, put_data): + self.keys = [] + rec_length = 5 + for i in range(rec_length): + key = ("test", "demo", i) + record = {"name": "name%s" % (str(i)), "age": i} + put_data(self.as_connection, key, record) + self.keys.append(key) + + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + try: + client1.exists_many(self.keys, {"total_timeout": 20}) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_exists_many_with_extra_parameter_in_key(self, put_data): keys = [] key = ("test", "demo", None, bytearray("asd;as[d'as;djk;uyfl", "utf-8")) diff --git a/test/new_tests/test_get_async.py b/test/new_tests/test_get_async.py index 39b57cd7f..585fb4764 100644 --- a/test/new_tests/test_get_async.py +++ b/test/new_tests/test_get_async.py @@ -11,6 +11,7 @@ # from collections import OrderedDict +from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e from aerospike_helpers.awaitable import io @@ -239,3 +240,19 @@ async def async_io(key_input=None, policy_input=None): assert exception.code == 2 await asyncio.gather(async_io(_input)) + + @pytest.mark.asyncio + async def test_neg_get_with_only_key_no_connection(self): + """ + Invoke get() with a key and not policy's dict no connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + async def async_io(key_input=None, policy_input=None): + with pytest.raises(e.ClusterError): + key, _, _ = await io.get(client1, key_input) + + await asyncio.gather(async_io(key)) diff --git a/test/new_tests/test_get_many.py b/test/new_tests/test_get_many.py index 241531ae8..3206004f5 100644 --- a/test/new_tests/test_get_many.py +++ b/test/new_tests/test_get_many.py @@ -7,6 +7,8 @@ from collections import Counter except ImportError: from counter26 import Counter + +import aerospike from aerospike import exception as e @@ -208,6 +210,14 @@ def test_neg_get_many_Invalid_Key_without_primary_key(self): with pytest.raises(e.ParamError): key, _, _ = self.as_connection.get(key) + def test_neg_get_many_with_proper_parameters_without_connection(self): + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError): + client1.get_many(self.keys, {"total_timeout": 20}) + def test_neg_prepend_Invalid_Key_without_set_name(self): """ Invoke prepend() without set name diff --git a/test/new_tests/test_get_node_names.py b/test/new_tests/test_get_node_names.py index 19ecaa3e8..25c058174 100644 --- a/test/new_tests/test_get_node_names.py +++ b/test/new_tests/test_get_node_names.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass +from aerospike import exception as e + +import aerospike @pytest.mark.usefixtures("as_connection") @@ -24,3 +28,20 @@ def test_pos_get_node_names(self): assert isinstance(response[0]["port"], int) assert isinstance(response[0]["node_name"], str) assert len(response[0]) == 3 + + # Tests for behaviors that raise errors + def test_pos_get_node_names_without_connection(self): + """ + Test that an attempt to call get_node_names before a connection + is established will raise the expected error + """ + config = TestBaseClass.get_connection_config() + unconnected_client = aerospike.client(config) + unconnected_client.close() + + try: + unconnected_client.get_node_names() + + except e.ClusterError as exception: + assert exception.code == 11 + assert exception.msg == "No connection to aerospike cluster." diff --git a/test/new_tests/test_get_nodes.py b/test/new_tests/test_get_nodes.py index fccf2aefd..69efbdd58 100644 --- a/test/new_tests/test_get_nodes.py +++ b/test/new_tests/test_get_nodes.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- import pytest from .test_base_class import TestBaseClass +from aerospike import exception as e + +import aerospike @pytest.mark.xfail(TestBaseClass.tls_in_use(), reason="get_nodes may fail when using TLS") @@ -31,3 +34,20 @@ def test_get_nodes_with_parameter(self): """ response = self.as_connection.get_nodes("parameter") assert response is not None + + # Tests for behaviors that raise errors + def test_pos_get_nodes_without_connection(self): + """ + Test that an attempt to call get_nodes before a connection + is established will raise the expected error + """ + config = TestBaseClass.get_connection_config() + unconnected_client = aerospike.client(config) + unconnected_client.close() + + try: + unconnected_client.get_nodes() + + except e.ClusterError as exception: + assert exception.code == 11 + assert exception.msg == "No connection to aerospike cluster" diff --git a/test/new_tests/test_get_put.py b/test/new_tests/test_get_put.py index bb6fe2f63..6b850dbe0 100644 --- a/test/new_tests/test_get_put.py +++ b/test/new_tests/test_get_put.py @@ -235,6 +235,18 @@ def test_neg_get_remove_key_and_check_get(self, _input, _expected, put_data): except e.RecordNotFound as exception: assert exception.code == 2 + def test_neg_get_with_only_key_no_connection(self): + """ + Invoke get() with a key and not policy's dict no connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError): + key, _, _ = client1.get(key) + # Put Tests def test_pos_put_with_policy_exists_create_or_replace(self): """ @@ -726,6 +738,23 @@ def test_neg_put_with_policy_gen_GT_lesser(self): assert {"name": "John"} == bins self.as_connection.remove(key) + def test_neg_put_with_string_record_without_connection(self): + """ + Invoke put() for a record with string data without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + key = ("test", "demo", 1) + + bins = {"name": "John"} + + try: + client1.put(key, bins) + except e.ClusterError as exception: + assert exception.code == 11 + @pytest.mark.parametrize( "key, record, meta, policy, ex_code, ex_msg", [ diff --git a/test/new_tests/test_get_udf.py b/test/new_tests/test_get_udf.py index 63df167ba..a946664ec 100644 --- a/test/new_tests/test_get_udf.py +++ b/test/new_tests/test_get_udf.py @@ -2,6 +2,7 @@ import pytest from .as_status_codes import AerospikeStatus +from .test_base_class import TestBaseClass from aerospike import exception as e import aerospike @@ -134,3 +135,18 @@ def test_invalid_module_arg_types(self, udf_module): def test_invalid_language_arg_types(self, ltype): with pytest.raises(TypeError): self.as_connection.udf_get(self.loaded_udf_name, ltype) + + def test_udf_get_with_correct_paramters_without_connection(self): + """ + Invoke udf_get() with correct parameters without connection + """ + policy = {"timeout": 5000} + + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.udf_get(self.loaded_udf_name, self.udf_language, policy) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR diff --git a/test/new_tests/test_increment.py b/test/new_tests/test_increment.py index 160ff79c4..d6a58841d 100644 --- a/test/new_tests/test_increment.py +++ b/test/new_tests/test_increment.py @@ -3,6 +3,7 @@ import sys from .as_status_codes import AerospikeStatus +from .test_base_class import TestBaseClass from aerospike import exception as e import aerospike @@ -337,6 +338,22 @@ def test_increment_with_unicode_bin(self): assert bins == {"age": 11, "name": "name1"} + def test_increment_with_correct_parameters_without_connection(self): + """ + Invoke increment() with correct parameters without connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.increment(key, "age", 5) + + err_code = err_info.value.code + + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + @pytest.mark.skip(reason="This raises a system error." + " Something else should be raised") def test_increment_with_integer_greaterthan_maxsize(self): """ diff --git a/test/new_tests/test_index.py b/test/new_tests/test_index.py index 552093ae4..f298fd6c9 100644 --- a/test/new_tests/test_index.py +++ b/test/new_tests/test_index.py @@ -3,8 +3,11 @@ import pytest from .as_status_codes import AerospikeStatus from .index_helpers import ensure_dropped_index +from .test_base_class import TestBaseClass from aerospike import exception as e +import aerospike + class TestIndex(object): @pytest.fixture(autouse=True) @@ -434,6 +437,19 @@ def test_createindex_integer_unicode(self): self.as_connection.index_remove("test", "uni_age_index", policy) ensure_dropped_index(self.as_connection, "test", "uni_age_index") + def test_createindex_with_correct_parameters_without_connection(self): + # Invoke createindex() with correct arguments without connection + policy = {} + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.index_integer_create("test", "demo", "age", "age_index", policy) + + err_code = err_info.value.code + assert err_code is AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_index_remove_no_args(self): with pytest.raises(TypeError): diff --git a/test/new_tests/test_info.py b/test/new_tests/test_info.py index 0678f583f..ea3e6727f 100644 --- a/test/new_tests/test_info.py +++ b/test/new_tests/test_info.py @@ -1,9 +1,10 @@ # -*- coding: utf-8 -*- import pytest - from aerospike import exception as e +import aerospike + @pytest.mark.xfail(reason="Method is deprecated") @pytest.mark.usefixtures("as_connection", "connection_config") @@ -85,6 +86,19 @@ def test_info_without_parameters(self): assert "argument 'command' (pos 1)" in str(err_info.value) + def test_info_positive_for_sets_without_connection(self): + """ + Test info positive for sets without connection + """ + client1 = aerospike.client(self.connection_config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.info("sets", self.connection_config["hosts"]) + + assert err_info.value.code == 11 + assert err_info.value.msg == "No connection to aerospike cluster" + @pytest.mark.parametrize( "host_arg", [ diff --git a/test/new_tests/test_info_all.py b/test/new_tests/test_info_all.py index 28f26c643..0e12b9877 100644 --- a/test/new_tests/test_info_all.py +++ b/test/new_tests/test_info_all.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- import pytest + from aerospike import exception as e +import aerospike + @pytest.mark.usefixtures("as_connection", "connection_config") class TestInfo(object): @@ -81,6 +84,16 @@ def test_info_all_without_parameters(self): with pytest.raises(TypeError): self.as_connection.info_all() + def test_info_all_without_connection(self): + """ + Test info positive for sets without connection + """ + client1 = aerospike.client(self.connection_config) + client1.close() + + with pytest.raises(e.ClusterError): + client1.info_all("sets") + def test_info_all_with_invalid_policy_type(self): """ Test that sending a non dict/None as policy raises an error diff --git a/test/new_tests/test_info_random_node.py b/test/new_tests/test_info_random_node.py index 4586b5a82..c9c8e2b01 100644 --- a/test/new_tests/test_info_random_node.py +++ b/test/new_tests/test_info_random_node.py @@ -5,6 +5,8 @@ from .test_base_class import TestBaseClass from aerospike import exception as e +import aerospike + @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") @pytest.mark.usefixtures("as_connection", "connection_config") @@ -128,6 +130,18 @@ def test_info_random_node_for_incorrect_command(self): with pytest.raises(e.ClientError): self.as_connection.info_random_node("abcd") + def test_info_random_node_positive_without_connection(self): + """ + Test info with correct arguments without connection. + """ + client1 = aerospike.client(self.connection_config) + client1.close() + with pytest.raises(e.ClusterError) as err_info: + client1.info_random_node("bins") + + assert err_info.value.code == 11 + assert err_info.value.msg == "No connection to aerospike cluster." + def test_info_random_node_positive_with_extra_parameters(self): """ Test info with extra parameters. diff --git a/test/new_tests/test_info_single_node.py b/test/new_tests/test_info_single_node.py index e2eb73f77..591dd9d15 100644 --- a/test/new_tests/test_info_single_node.py +++ b/test/new_tests/test_info_single_node.py @@ -5,6 +5,8 @@ from .test_base_class import TestBaseClass from aerospike import exception as e +import aerospike + @pytest.mark.xfail(TestBaseClass.temporary_xfail(), reason="xfail variable set") @pytest.mark.usefixtures("as_connection", "connection_config") @@ -133,6 +135,18 @@ def test_info_single_node_for_incorrect_command(self): with pytest.raises(e.ClientError): self.as_connection.info_single_node("abcd", self.connection_config["hosts"][0]) + def test_info_single_node_positive_without_connection(self): + """ + Test info with correct arguments without connection. + """ + client1 = aerospike.client(self.connection_config) + client1.close() + with pytest.raises(e.ClusterError) as err_info: + client1.info_single_node("bins", self.connection_config["hosts"][0][:2]) + + assert err_info.value.code == 11 + assert err_info.value.msg == "No connection to aerospike cluster." + def test_info_single_node_positive_with_extra_parameters(self): """ Test info with extra parameters. diff --git a/test/new_tests/test_is_connected.py b/test/new_tests/test_is_connected.py index aec2f74d5..14c33ee0d 100644 --- a/test/new_tests/test_is_connected.py +++ b/test/new_tests/test_is_connected.py @@ -27,7 +27,6 @@ def _connect(self): def test_is_connected_before_connect(self): """ Client call itself establishes connection. - Connect/Close are deprecated and it is no-op to client """ client = aerospike.client(self.config) assert client.is_connected() is True diff --git a/test/new_tests/test_job_info.py b/test/new_tests/test_job_info.py index 6d512d543..5e292734c 100644 --- a/test/new_tests/test_job_info.py +++ b/test/new_tests/test_job_info.py @@ -1,6 +1,9 @@ # -*- coding: utf-8 -*- import pytest +from .as_status_codes import AerospikeStatus +from .test_base_class import TestBaseClass from aerospike import exception as e + import aerospike @@ -118,6 +121,20 @@ def test_job_info_with_scanid_string(self): ] ) + def test_job_info_with_correct_parameters_without_connection(self): + """ + Invoke job_info() with correct parameters without connection + """ + + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.job_info(self.job_id, aerospike.JOB_SCAN) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_job_info_with_constant_out_of_valid_values(self): """ Invoke job_info() with the scan module out of the expected range diff --git a/test/new_tests/test_list_append.py b/test/new_tests/test_list_append.py index 54999f2eb..0b7d454ba 100644 --- a/test/new_tests/test_list_append.py +++ b/test/new_tests/test_list_append.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest import random +from .test_base_class import TestBaseClass from aerospike import exception as e import aerospike @@ -216,3 +217,11 @@ def test_neg_list_append_meta_type_integer(self): except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Metadata should be of type dictionary" + + def test_list_append_with_no_connection(self): + config = TestBaseClass.get_connection_config() + client = aerospike.client(config) + client.close() + k = ("test", "demo", "no_con") + with pytest.raises(e.ClusterError): + client.list_append(k, "bob", "item") diff --git a/test/new_tests/test_list_index.py b/test/new_tests/test_list_index.py index d9e7e9d3e..f2092679f 100644 --- a/test/new_tests/test_list_index.py +++ b/test/new_tests/test_list_index.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass from aerospike import exception as e from .index_helpers import ensure_dropped_index @@ -342,6 +343,23 @@ def test_neg_listindex_with_incorrect_set(self): self.as_connection.index_remove("test", "test_numeric_list_index", policy) ensure_dropped_index(self.as_connection, "test", "test_numeric_list_index") + def test_neg_listindex_with_correct_parameters_no_connection(self): + """ + Invoke index_list_create() with correct arguments no connection + """ + policy = {} + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + try: + client1.index_list_create( + "test", "demo", "string_list", aerospike.INDEX_STRING, "test_string_list_index", policy + ) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_listindex_with_no_paramters(self): """ Invoke index_list_create() without any mandatory parameters. diff --git a/test/new_tests/test_mapkeys_index.py b/test/new_tests/test_mapkeys_index.py index b120d76a9..6ab0b6862 100644 --- a/test/new_tests/test_mapkeys_index.py +++ b/test/new_tests/test_mapkeys_index.py @@ -2,6 +2,7 @@ import pytest from .as_status_codes import AerospikeStatus +from .test_base_class import TestBaseClass from aerospike import exception as e from .index_helpers import ensure_dropped_index @@ -327,3 +328,20 @@ def test_create_map_integer_index_unicode(self): assert response_code == AerospikeStatus.AEROSPIKE_OK self.as_connection.index_remove("test", "uni_age_index", policy) ensure_dropped_index(self.as_connection, "test", "uni_age_index") + + def test_mapkeysindex_with_correct_parameters_no_connection(self): + """ + Invoke index_map_keys_create() with correct arguments no connection + """ + policy = {} + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.index_map_keys_create( + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) + + err_code = err_info.value.code + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR diff --git a/test/new_tests/test_mapvalues_index.py b/test/new_tests/test_mapvalues_index.py index b6c3ae300..99c0be608 100644 --- a/test/new_tests/test_mapvalues_index.py +++ b/test/new_tests/test_mapvalues_index.py @@ -2,6 +2,7 @@ import pytest from .as_status_codes import AerospikeStatus +from .test_base_class import TestBaseClass from aerospike import exception as e from .index_helpers import ensure_dropped_index @@ -323,3 +324,21 @@ def test_create_map_values_integer_index_unicode(self): assert retobj == AerospikeStatus.AEROSPIKE_OK self.as_connection.index_remove("test", "uni_age_index", policy) ensure_dropped_index(self.as_connection, "test", "uni_age_index") + + def test_mapvaluesindex_with_correct_parameters_no_connection(self): + """ + Invoke index_mapvalues_create() with correct arguments no + connection + """ + policy = {} + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.index_map_values_create( + "test", "demo", "string_map", aerospike.INDEX_STRING, "test_string_map_index", policy + ) + + err_code = err_info.value.code + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR diff --git a/test/new_tests/test_operate.py b/test/new_tests/test_operate.py index 8cbbd6b89..748f6924a 100644 --- a/test/new_tests/test_operate.py +++ b/test/new_tests/test_operate.py @@ -525,6 +525,26 @@ def test_pos_operate_increment_nonexistent_bin(self): assert bins == {"my_age": 5, "age": 1, "name": "name1"} + def test_pos_operate_with_correct_paramters_without_connection(self): + """ + Invoke operate() with correct parameters without connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + llist = [ + {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, + {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, + {"op": aerospike.OPERATOR_READ, "bin": "name"}, + ] + + try: + key, _, _ = client1.operate(key, llist) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_pos_operate_write_set_to_aerospike_null(self): """ Invoke operate() with write command with bin set to aerospike_null diff --git a/test/new_tests/test_operate_helpers.py b/test/new_tests/test_operate_helpers.py index e7f697db8..c275c38bd 100644 --- a/test/new_tests/test_operate_helpers.py +++ b/test/new_tests/test_operate_helpers.py @@ -437,6 +437,19 @@ def test_pos_operate_increment_nonexistent_key(self): self.as_connection.remove(key) + def test_pos_operate_with_correct_paramters_without_connection(self): + """ + Invoke operate() with correct parameters without connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + llist = [operations.touch()] + + with pytest.raises(e.ClusterError): + client1.operate(key, llist) + def test_pos_operate_write_set_to_aerospike_null(self): """ Invoke operate() with write command with bin set to aerospike_null diff --git a/test/new_tests/test_operate_ordered.py b/test/new_tests/test_operate_ordered.py index bb398b13d..6e00394fa 100644 --- a/test/new_tests/test_operate_ordered.py +++ b/test/new_tests/test_operate_ordered.py @@ -658,6 +658,26 @@ def test_neg_operate_ordered_with_policy_gen_GT_lesser(self): bytearray(b"\xb7\xf4\xb88\x89\xe2\xdag\xdeh>\x1d\xf6\x91\x9a\x1e\xac\xc4F\xc8"), ) + def test_neg_operate_ordered_without_connection(self): + """ + Invoke operate_ordered() with correct parameters without connection + """ + key = ("test", "demo", 1) + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + llist = [ + {"op": aerospike.OPERATOR_PREPEND, "bin": "name", "val": "ram"}, + {"op": aerospike.OPERATOR_INCR, "bin": "age", "val": 3}, + {"op": aerospike.OPERATOR_READ, "bin": "name"}, + ] + + try: + key, _, _ = client1.operate_ordered(key, llist) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_operate_ordered_prepend_set_to_aerospike_null(self): """ Invoke operate_ordered() with prepend command bin set to aerospike_null diff --git a/test/new_tests/test_prepend.py b/test/new_tests/test_prepend.py index a9c1f9d44..03fb08bb3 100644 --- a/test/new_tests/test_prepend.py +++ b/test/new_tests/test_prepend.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e @@ -477,3 +478,18 @@ def test_neg_prepend_without_bin_name(self): except e.ParamError as exception: assert exception.code == -2 assert exception.msg == "Cannot concatenate 'str' and 'non-str' objects" + + def test_neg_prepend_with_correct_parameters_without_connection(self): + """ + Invoke prepend() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + key = ("test", "demo", 1) + + try: + client1.prepend(key, "name", "str") + + except e.ClusterError as exception: + assert exception.code == 11 diff --git a/test/new_tests/test_put_async.py b/test/new_tests/test_put_async.py index c4ce157bf..6c70da5f8 100644 --- a/test/new_tests/test_put_async.py +++ b/test/new_tests/test_put_async.py @@ -11,6 +11,7 @@ # from collections import OrderedDict +from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e from aerospike_helpers.awaitable import io @@ -637,6 +638,27 @@ async def async_io(key=None, rec=None, meta=None, policy=None, serialize=None): assert {"name": "John"} == bins self.as_connection.remove(key) + @pytest.mark.asyncio + async def test_neg_put_with_string_record_without_connection(self): + """ + Invoke put() for a record with string data without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + key = ("test", "demo", 1) + + bins = {"name": "John"} + + async def async_io(key=None, rec=None, meta=None, policy=None, serialize=None): + try: + assert 0 == await io.put(client1, key, rec, meta, policy, serialize) + except e.ClusterError as exception: + assert exception.code == 11 + + await asyncio.gather(async_io(key, bins)) + @pytest.mark.parametrize( "key, record, meta, policy, ex_code, ex_msg", [ diff --git a/test/new_tests/test_query.py b/test/new_tests/test_query.py index b28fb413c..2eff8ea27 100644 --- a/test/new_tests/test_query.py +++ b/test/new_tests/test_query.py @@ -958,6 +958,27 @@ def test_query_with_set_int(self): err_code = err_info.value.code assert err_code == AerospikeStatus.AEROSPIKE_ERR_PARAM + def test_query_with_correct_parameters_without_connection(self): + """ + Invoke query() with correct arguments without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + query = client1.query("test", "demo") + query.select("name", "test_age") + query.where(p.equals("test_age", 1)) + + def callback(input_tuple): + pass + + query.foreach(callback) + + err_code = err_info.value.code + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + @pytest.mark.skip(reason="segfault") def test_query_predicate_range_wrong_no_args(self): """ """ diff --git a/test/new_tests/test_query_apply.py b/test/new_tests/test_query_apply.py index 32726bed6..a8ef2d5f7 100644 --- a/test/new_tests/test_query_apply.py +++ b/test/new_tests/test_query_apply.py @@ -296,6 +296,21 @@ def test_query_apply_unicode_literal_for_strings(self): self._wait_for_query_complete(query_id) self._correct_items_have_been_applied() + def test_query_apply_with_correct_parameters_without_connection(self): + """ + Invoke query_apply() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.query_apply("test", "demo", self.age_range_pred, "query_apply", "mark_as_applied", ["name", 2]) + + err_code = err_info.value.code + + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + @pytest.mark.parametrize( "predicate", ( diff --git a/test/new_tests/test_remove.py b/test/new_tests/test_remove.py index 51e777c9f..00adf8d9a 100644 --- a/test/new_tests/test_remove.py +++ b/test/new_tests/test_remove.py @@ -3,6 +3,7 @@ import pytest from .test_data import key_neg +from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e @@ -300,6 +301,20 @@ def test_neg_remove_with_missing_record(self, key, ex_name, ex_code): (code, _, _, _) = exception.value assert code == ex_code + def test_neg_remove_with_correct_parameters_without_connection(self): + """ + Invoke remove() with correct arguments without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + key = ("test", "demo", 1) + + with pytest.raises(e.ClusterError) as exception: + client1.remove(key) + (code, _, _, _) = exception.value + assert code == 11 + def test_neg_remove_with_no_parameters(self): """ Invoke remove() without any mandatory parameters. diff --git a/test/new_tests/test_remove_bin.py b/test/new_tests/test_remove_bin.py index 0cefb5990..85e481df0 100644 --- a/test/new_tests/test_remove_bin.py +++ b/test/new_tests/test_remove_bin.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass import aerospike from aerospike import exception as e @@ -246,6 +247,22 @@ def test_neg_remove_bin_with_none(self, key, bin_for_removal, ex_code, ex_msg): assert exception.code == ex_code assert exception.msg == ex_msg + def test_neg_remove_bin_with_correct_parameters_without_connection(self): + """ + Invoke remove_bin() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + key = ("test", "demo", 1) + + try: + client1.remove_bin(key, ["age"]) + + except e.ClusterError as exception: + assert exception.code == 11 + def test_neg_remove_bin_with_incorrect_meta(self): """ Invoke remove_bin() with incorrect meta diff --git a/test/new_tests/test_scan_apply.py b/test/new_tests/test_scan_apply.py index c62e7d31f..7b90b182d 100644 --- a/test/new_tests/test_scan_apply.py +++ b/test/new_tests/test_scan_apply.py @@ -3,6 +3,7 @@ import time from .as_status_codes import AerospikeStatus from aerospike_helpers import expressions as exp +from .test_base_class import TestBaseClass from aerospike import exception as e import aerospike @@ -337,6 +338,20 @@ def test_scan_apply_with_argument_is_string(self): err_code = err_info.value.code assert err_code is AerospikeStatus.AEROSPIKE_ERR_PARAM + def test_scan_apply_with_correct_parameters_without_connection(self): + """ + Invoke scan_apply() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.scan_apply("test", "demo", "bin_lua", "mytransform", ["age", 2]) + + err_code = err_info.value.code + assert err_code is AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_scan_apply_with_incorrect_policy(self): """ Invoke scan_apply() with incorrect policy diff --git a/test/new_tests/test_select.py b/test/new_tests/test_select.py index 4edf072c7..7887a50c0 100644 --- a/test/new_tests/test_select.py +++ b/test/new_tests/test_select.py @@ -176,6 +176,18 @@ def test_select_without_any_parameter(self): assert "argument 'key' (pos 1)" in str(typeError.value) + def test_select_with_key_and_bins_without_connection(self): + + bins_to_select = ["a"] + config = self.connection_config + disconnected_client = aerospike.client(config) + disconnected_client.close() + + with pytest.raises(e.ClusterError) as err_info: + disconnected_client.select(self.test_key, bins_to_select) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_select_with_invalid_keys(self, invalid_key): """ Verify that different types of invalid keys will diff --git a/test/new_tests/test_select_many.py b/test/new_tests/test_select_many.py index 576fa2289..8c089dda0 100644 --- a/test/new_tests/test_select_many.py +++ b/test/new_tests/test_select_many.py @@ -290,6 +290,19 @@ def test_select_many_without_any_parameter(self): assert "argument 'keys' (pos 1)" in str(typeError.value) + def test_select_many_with_proper_parameters_without_connection(self): + + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + + filter_bins = ["title", "name"] + + with pytest.raises(e.ClusterError) as err_info: + client1.select_many(self.keys, filter_bins, {"timeout": 20}) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_select_many_with_invalid_keys(self, invalid_key): # invalid_key will be an invalid key_tuple, so we wrap # it with a valid key in a list diff --git a/test/new_tests/test_touch.py b/test/new_tests/test_touch.py index da4d33afe..f87ec50d2 100644 --- a/test/new_tests/test_touch.py +++ b/test/new_tests/test_touch.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- import pytest +from .test_base_class import TestBaseClass from aerospike import exception as e from .as_status_codes import AerospikeStatus @@ -256,6 +257,21 @@ def test_touch_policy_is_string(self): assert err_info.value.code == AerospikeStatus.AEROSPIKE_ERR_PARAM + def test_touch_with_correct_paramters_without_connection(self): + """ + Invoke touch() with correct parameters without connection + """ + config = TestBaseClass.get_connection_config() + client1 = aerospike.client(config) + client1.close() + key = ("test", "demo", 1) + + with pytest.raises(e.ClusterError) as err_info: + client1.touch(key, 120) + + err_code = err_info.value.code + assert err_code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_touch_withttlvalue_greaterthan_maxsize(self): """ Invoke touch() with ttl value greater than (2^63-1) diff --git a/test/new_tests/test_udf_list.py b/test/new_tests/test_udf_list.py index 8acca6fab..645dc6a9d 100644 --- a/test/new_tests/test_udf_list.py +++ b/test/new_tests/test_udf_list.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- import pytest -from .test_base_class import TestBaseClass from aerospike import exception as e +from .test_base_class import TestBaseClass + +import aerospike class TestUdfList(object): @@ -101,3 +103,21 @@ def test_udf_list_with_wrong_policy_type(self, policy): """ with pytest.raises(e.ParamError): self.client.udf_list(policy) + + def test_udf_list_with_proper_parameters_without_connection(self): + """ + Test to verify error raised by trying to call udf_list without + first calling connect + """ + config = TestBaseClass.get_connection_config() + + client1 = aerospike.client(config) + client1.close() + + policy = {"timeout": 0} + + with pytest.raises(e.ClusterError) as cluster_error: + client1.udf_list(policy) + + assert cluster_error.value.code == 11 + assert cluster_error.value.msg == "No connection to aerospike cluster" diff --git a/test/new_tests/test_udf_put.py b/test/new_tests/test_udf_put.py index 2cd0c8f96..164b7fde5 100644 --- a/test/new_tests/test_udf_put.py +++ b/test/new_tests/test_udf_put.py @@ -6,6 +6,8 @@ from .test_base_class import TestBaseClass from aerospike import exception as e +import aerospike + @pytest.mark.usefixtures("as_connection") class TestUdfPut(TestBaseClass): @@ -121,6 +123,22 @@ def test_udf_put_with_empty_filename_beginning_with_slash(self): with pytest.raises(e.ParamError): self.as_connection.udf_put(filename, udf_type, policy) + def test_udf_put_with_proper_parameters_without_connection(self): + + policy = {} + filename = self.udf_name + udf_type = 0 + + config = TestBaseClass.get_connection_config() + + client1 = aerospike.client(config) + client1.close() + + with pytest.raises(e.ClusterError) as err_info: + client1.udf_put(filename, udf_type, policy) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_udf_put_with_invalid_timeout_policy_value(self): """ Test that invalid timeout policy causes an error on udf put diff --git a/test/new_tests/test_udf_remove.py b/test/new_tests/test_udf_remove.py index 410d85dd5..8311510e5 100644 --- a/test/new_tests/test_udf_remove.py +++ b/test/new_tests/test_udf_remove.py @@ -6,6 +6,8 @@ import pytest from .as_status_codes import AerospikeStatus from .udf_helpers import wait_for_udf_removal, wait_for_udf_to_exist +from .test_base_class import TestBaseClass +import aerospike from aerospike import exception as e @@ -143,6 +145,23 @@ def setup_class(cls): """ cls.udf_to_load = "example.lua" + def test_udf_remove_with_proper_parameters_without_connection(self): + """ + Test to verify that attempting to remove a UDF before connection + raises an error + """ + config = TestBaseClass.get_connection_config() + + client1 = aerospike.client(config) + client1.close() + policy = {"timeout": 100} + module = "example.lua" + + with pytest.raises(e.ClusterError) as err_info: + client1.udf_remove(module, policy) + + assert err_info.value.code == AerospikeStatus.AEROSPIKE_CLUSTER_ERROR + def test_udf_remove_with_non_existent_module(self): """ Test to ensure that the removal of a non existant UDF raises an Error From 59c3d1d4d38fa24d686f1b58187e113177441d1e Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Tue, 8 Nov 2022 13:21:05 -0800 Subject: [PATCH 25/27] use https path for submodule --- .gitmodules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitmodules b/.gitmodules index 52ecea4af..136ba68cb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,5 +1,5 @@ [submodule "aerospike-client-c"] path = aerospike-client-c # url = git@github.com:aerospike/aerospike-client-c.git - url = git@github.com:aerospike/aerospike-client-c.git + url = https://github.com/aerospike/aerospike-client-c.git branch = stage From ab65515cbaf967fb4f3159869fb41c963a32401b Mon Sep 17 00:00:00 2001 From: rpandian-spike Date: Tue, 8 Nov 2022 13:26:44 -0800 Subject: [PATCH 26/27] test case name update --- test/new_tests/test_exists_many.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/new_tests/test_exists_many.py b/test/new_tests/test_exists_many.py index b6bee490b..c33f9dff6 100644 --- a/test/new_tests/test_exists_many.py +++ b/test/new_tests/test_exists_many.py @@ -27,7 +27,7 @@ def test_pos_exists_many_without_policy(self, put_data): assert isinstance(records, list) assert len(records) == rec_length - def test_pos_exists_many_with_proper_parameters_without_connection(self, put_data): + def test_pos_exists_many_with_proper_parameters(self, put_data): self.keys = [] rec_length = 5 for i in range(rec_length): From 1eeae69fb6858290086373210e4bc4ea7b23ca13 Mon Sep 17 00:00:00 2001 From: Ramaraj Pandian <84588160+rpandian-spike@users.noreply.github.com> Date: Tue, 8 Nov 2022 14:04:39 -0800 Subject: [PATCH 27/27] Update aerospike_helpers/operations/bitwise_operations.py Co-authored-by: juliannguyen4 <109386615+juliannguyen4@users.noreply.github.com> --- aerospike_helpers/operations/bitwise_operations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aerospike_helpers/operations/bitwise_operations.py b/aerospike_helpers/operations/bitwise_operations.py index 921123a6a..759162cf2 100644 --- a/aerospike_helpers/operations/bitwise_operations.py +++ b/aerospike_helpers/operations/bitwise_operations.py @@ -81,7 +81,7 @@ from aerospike import exception as e from aerospike_helpers.operations import bitwise_operations - config = self.connection_config.copy() + config = {'hosts': [('127.0.0.1', 3000)]} client = aerospike.client(config).connect() key = ('test', 'demo', 'bit_example')