From: Brian Aker Date: Sun, 15 Sep 2013 07:19:20 +0000 (-0400) Subject: Adds additional test cases and checks for binary for increment and decrement with... X-Git-Tag: 1.0.18~19^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=dd1ce96a2171e9a2e13c08e56e22b03008e87367;p=m6w6%2Flibmemcached Adds additional test cases and checks for binary for increment and decrement with initial. --- diff --git a/docs/memcached_auto.rst b/docs/memcached_auto.rst index c3f4c7f5..0f78e6e7 100644 --- a/docs/memcached_auto.rst +++ b/docs/memcached_auto.rst @@ -53,7 +53,8 @@ MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. The flags will be set to zero.The value is then returned via the uint32_t -value pointer you pass to it. +value pointer you pass to it. memcached_increment_with_initial is only available +when using the binary protocol. memcached_decrement_with_initial takes a key and keylength and decrements the value by the offset passed to it. If the object specified by key does @@ -62,7 +63,8 @@ MEMCACHED_EXPIRATION_NOT_ADD, the operation will fail. For all other expiration values, the operation will succeed by seeding the value for that key with a initial value to expire with the provided expiration time. The flags will be set to zero.The value is then returned via the uint32_t -value pointer you pass to it. +value pointer you pass to it. memcached_decrement_with_initial is only available +when using the binary protocol. :c:func:`memcached_increment_by_key`, :c:func:`memcached_decrement_by_key`, :c:func:`memcached_increment_with_initial_by_key`, and diff --git a/libmemcached/auto.cc b/libmemcached/auto.cc index 685528f2..04efe85d 100644 --- a/libmemcached/auto.cc +++ b/libmemcached/auto.cc @@ -54,11 +54,17 @@ static void auto_response(memcached_instance_st* instance, const bool reply, me if (memcached_fatal(rc)) { + fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, rc)); assert(memcached_last_error(instance->root) != MEMCACHED_SUCCESS); *value= UINT64_MAX; } + else if (memcached_failed(rc)) + { + *value= UINT64_MAX; + } else { + assert(memcached_last_error(instance->root) != MEMCACHED_NOTFOUND); *value= instance->root->result.numeric_value; } } diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index 2012d477..d748d39e 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -70,9 +70,11 @@ test_st tests[] ={ {"partial mget", false, (test_callback_fn*)get_test5 }, {"stats_servername", false, (test_callback_fn*)stats_servername_test }, {"increment", false, (test_callback_fn*)increment_test }, - {"increment_with_initial", true, (test_callback_fn*)increment_with_initial_test }, + {"memcached_increment_with_initial(0)", true, (test_callback_fn*)increment_with_initial_test }, + {"memcached_increment_with_initial(999)", true, (test_callback_fn*)increment_with_initial_999_test }, {"decrement", false, (test_callback_fn*)decrement_test }, - {"decrement_with_initial", true, (test_callback_fn*)decrement_with_initial_test }, + {"memcached_decrement_with_initial(3)", true, (test_callback_fn*)decrement_with_initial_test }, + {"memcached_decrement_with_initial(999)", true, (test_callback_fn*)decrement_with_initial_999_test }, {"increment_by_key", false, (test_callback_fn*)increment_by_key_test }, {"increment_with_initial_by_key", true, (test_callback_fn*)increment_with_initial_by_key_test }, {"decrement_by_key", false, (test_callback_fn*)decrement_by_key_test }, diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index e50f5794..6e6f4a7b 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -1294,26 +1294,41 @@ test_return_t increment_test(memcached_st *memc) return TEST_SUCCESS; } -test_return_t increment_with_initial_test(memcached_st *memc) +static test_return_t __increment_with_initial_test(memcached_st *memc, uint64_t initial) { - test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t new_number; - uint64_t initial= 0; test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); - test_compare(new_number, (initial +1)); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + test_compare(new_number, (initial +1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_increment_with_initial(memc, test_literal_param("number"), 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } +test_return_t increment_with_initial_test(memcached_st *memc) +{ + return __increment_with_initial_test(memc, 0); +} + +test_return_t increment_with_initial_999_test(memcached_st *memc) +{ + return __increment_with_initial_test(memc, 999); +} + test_return_t decrement_test(memcached_st *memc) { test_compare(return_value_based_on_buffering(memc), @@ -1341,12 +1356,10 @@ test_return_t decrement_test(memcached_st *memc) return TEST_SUCCESS; } -test_return_t decrement_with_initial_test(memcached_st *memc) +static test_return_t __decrement_with_initial_test(memcached_st *memc, uint64_t initial) { test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t initial= 3; - test_compare(MEMCACHED_SUCCESS, memcached_flush_buffers(memc)); uint64_t new_number; @@ -1367,6 +1380,16 @@ test_return_t decrement_with_initial_test(memcached_st *memc) return TEST_SUCCESS; } +test_return_t decrement_with_initial_test(memcached_st *memc) +{ + return __decrement_with_initial_test(memc, 3); +} + +test_return_t decrement_with_initial_999_test(memcached_st *memc) +{ + return __decrement_with_initial_test(memc, 999); +} + test_return_t increment_by_key_test(memcached_st *memc) { const char *master_key= "foo"; @@ -1398,24 +1421,32 @@ test_return_t increment_by_key_test(memcached_st *memc) test_return_t increment_with_initial_by_key_test(memcached_st *memc) { - test_skip(true, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)); - uint64_t new_number; const char *master_key= "foo"; const char *key= "number"; uint64_t initial= 0; - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), - key, strlen(key), - 1, initial, 0, &new_number)); - test_compare(new_number, (initial +1)); + test_compare(MEMCACHED_SUCCESS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + test_compare(new_number, (initial +1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_increment_with_initial_by_key(memc, master_key, strlen(master_key), + key, strlen(key), + 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } @@ -1456,19 +1487,30 @@ test_return_t decrement_with_initial_by_key_test(memcached_st *memc) uint64_t new_number; uint64_t initial= 3; - test_compare(MEMCACHED_SUCCESS, - memcached_decrement_with_initial_by_key(memc, - test_literal_param("foo"), - test_literal_param("number"), - 1, initial, 0, &new_number)); - test_compare(new_number, initial); + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL)) + { + test_compare(MEMCACHED_SUCCESS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + test_compare(new_number, initial); - test_compare(MEMCACHED_SUCCESS, - memcached_decrement_with_initial_by_key(memc, - test_literal_param("foo"), - test_literal_param("number"), - 1, initial, 0, &new_number)); - test_compare(new_number, (initial - 1)); + test_compare(MEMCACHED_SUCCESS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + test_compare(new_number, (initial - 1)); + } + else + { + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_decrement_with_initial_by_key(memc, + test_literal_param("foo"), + test_literal_param("number"), + 1, initial, 0, &new_number)); + } return TEST_SUCCESS; } diff --git a/tests/libmemcached-1.0/mem_functions.h b/tests/libmemcached-1.0/mem_functions.h index 9edc820e..75736931 100644 --- a/tests/libmemcached-1.0/mem_functions.h +++ b/tests/libmemcached-1.0/mem_functions.h @@ -67,6 +67,7 @@ test_return_t decrement_by_key_test(memcached_st *memc); test_return_t decrement_test(memcached_st *memc); test_return_t decrement_with_initial_by_key_test(memcached_st *memc); test_return_t decrement_with_initial_test(memcached_st *memc); +test_return_t decrement_with_initial_999_test(memcached_st *memc); test_return_t delete_test(memcached_st *memc); test_return_t deprecated_set_memory_alloc(memcached_st *memc); test_return_t enable_cas(memcached_st *memc); @@ -88,6 +89,7 @@ test_return_t increment_by_key_test(memcached_st *memc); test_return_t increment_test(memcached_st *memc); test_return_t increment_with_initial_by_key_test(memcached_st *memc); test_return_t increment_with_initial_test(memcached_st *memc); +test_return_t increment_with_initial_999_test(memcached_st *memc); test_return_t init_test(memcached_st *not_used); test_return_t jenkins_run (memcached_st *); test_return_t key_setup(memcached_st *memc);