Adds additional test cases and checks for binary for increment and decrement with...
authorBrian Aker <brian@tangent.org>
Sun, 15 Sep 2013 07:19:20 +0000 (03:19 -0400)
committerBrian Aker <brian@tangent.org>
Sun, 15 Sep 2013 07:19:20 +0000 (03:19 -0400)
docs/memcached_auto.rst
libmemcached/auto.cc
tests/libmemcached-1.0/all_tests.h
tests/libmemcached-1.0/mem_functions.cc
tests/libmemcached-1.0/mem_functions.h

index c3f4c7f5b8343bfe44d6a8e54e0ff78709c37177..0f78e6e7d8d1a7610a358293d81b7d6ad8049cbe 100644 (file)
@@ -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
index 685528f2fae41adc40e8924016fdd3d8b88601c1..04efe85d7975cdcd3dd4fb55272947353e500477 100644 (file)
@@ -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;
   }
 }
index 2012d477d37901901aa69665613c576dc06207ec..d748d39e7e31e31e04df94a1c9550716b2a5097c 100644 (file)
@@ -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 },
index e50f5794318491c0e74c71161357411d7fa9932e..6e6f4a7bce9e45d638c8c486de3e78281f9b388d 100644 (file)
@@ -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;
 }
index 9edc820ec1ae197b466b4480d3d67d89427dc938..757369316fbcfafccda44d9cecfadce089ae1f55 100644 (file)
@@ -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);