Code for multi delete functions.
[m6w6/libmemcached] / tests / function.c
index 5d7fbf7dc460563bd3e6dca5cd082be6e729b3f1..ae2ec0324852523bf60ab3163fbc5315e48bc062 100644 (file)
 #include "../src/generator.h"
 #include "../src/execute.h"
 
+#ifndef INT64_MAX
+#define INT64_MAX LONG_MAX
+#endif
+#ifndef INT32_MAX
+#define INT32_MAX INT_MAX
+#endif
+
+
 #include "test.h"
 
 #define GLOBAL_COUNT 100000
@@ -111,7 +119,7 @@ uint8_t set_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   return 0;
@@ -123,24 +131,24 @@ uint8_t append_test(memcached_st *memc)
   char *key= "fig";
   char *value= "we";
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
 
   rc= memcached_flush(memc, 0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_append(memc, key, strlen(key), 
                        " the", strlen(" the"),
-                       (time_t)0, (uint16_t)0);
+                       (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_append(memc, key, strlen(key), 
                        " people", strlen(" people"),
-                       (time_t)0, (uint16_t)0);
+                       (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   value= memcached_get(memc, key, strlen(key),
@@ -161,7 +169,7 @@ uint8_t append_binary_test(memcached_st *memc)
   unsigned int store_list[] = { 23, 56, 499, 98, 32847, 0 };
   char *value;
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
   unsigned int x;
 
   rc= memcached_flush(memc, 0);
@@ -170,7 +178,7 @@ uint8_t append_binary_test(memcached_st *memc)
   rc= memcached_set(memc, 
                     key, strlen(key), 
                     NULL, 0,
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   for (x= 0; store_list[x] ; x++)
@@ -178,7 +186,7 @@ uint8_t append_binary_test(memcached_st *memc)
     rc= memcached_append(memc, 
                          key, strlen(key), 
                          (char *)&store_list[x], sizeof(unsigned int),
-                         (time_t)0, (uint16_t)0);
+                         (time_t)0, (uint32_t)0);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -220,7 +228,7 @@ uint8_t cas2_test(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -261,7 +269,7 @@ uint8_t cas_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_mget(memc, &key, &key_length, 1);
@@ -288,24 +296,24 @@ uint8_t prepend_test(memcached_st *memc)
   char *key= "fig";
   char *value= "people";
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
 
   rc= memcached_flush(memc, 0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_prepend(memc, key, strlen(key), 
                        "the ", strlen("the "),
-                       (time_t)0, (uint16_t)0);
+                       (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_prepend(memc, key, strlen(key), 
                        "we ", strlen("we "),
-                       (time_t)0, (uint16_t)0);
+                       (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   value= memcached_get(memc, key, strlen(key),
@@ -330,17 +338,27 @@ uint8_t add_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
   memcached_quit(memc);
   rc= memcached_add(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_NOTSTORED);
 
   return 0;
 }
 
+uint8_t add_wrapper(memcached_st *memc)
+{
+  unsigned int x;
+
+  for (x= 0; x < 10000; x++)
+    add_test(memc);
+
+  return 0;
+}
+
 uint8_t replace_test(memcached_st *memc)
 {
   memcached_return rc;
@@ -349,7 +367,7 @@ uint8_t replace_test(memcached_st *memc)
 
   rc= memcached_replace(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   return 0;
@@ -363,7 +381,7 @@ uint8_t delete_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_delete(memc, key, strlen(key), (time_t)0);
@@ -388,7 +406,7 @@ uint8_t get_test(memcached_st *memc)
   char *key= "foo";
   char *string;
   size_t string_length;
-  uint16_t flags;
+  uint32_t flags;
 
   rc= memcached_delete(memc, key, strlen(key), (time_t)0);
   assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_NOTFOUND);
@@ -410,11 +428,11 @@ uint8_t get_test2(memcached_st *memc)
   char *value= "when we sanitize";
   char *string;
   size_t string_length;
-  uint16_t flags;
+  uint32_t flags;
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   string= memcached_get(memc, key, strlen(key),
@@ -442,7 +460,7 @@ uint8_t set_test2(memcached_st *memc)
   {
     rc= memcached_set(memc, key, strlen(key), 
                       value, value_length,
-                      (time_t)0, (uint16_t)0);
+                      (time_t)0, (uint32_t)0);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -467,7 +485,7 @@ uint8_t set_test3(memcached_st *memc)
   {
     rc= memcached_set(memc, key, strlen(key), 
                       value, value_length,
-                      (time_t)0, (uint16_t)0);
+                      (time_t)0, (uint32_t)0);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -484,7 +502,7 @@ uint8_t get_test3(memcached_st *memc)
   size_t value_length= 8191;
   char *string;
   size_t string_length;
-  uint16_t flags;
+  uint32_t flags;
   int x;
 
   value = (char*)malloc(value_length);
@@ -495,7 +513,7 @@ uint8_t get_test3(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, value_length,
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   string= memcached_get(memc, key, strlen(key),
@@ -520,7 +538,7 @@ uint8_t get_test4(memcached_st *memc)
   size_t value_length= 8191;
   char *string;
   size_t string_length;
-  uint16_t flags;
+  uint32_t flags;
   int x;
 
   value = (char*)malloc(value_length);
@@ -531,7 +549,7 @@ uint8_t get_test4(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, value_length,
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   for (x= 0; x < 10; x++)
@@ -572,7 +590,7 @@ uint8_t increment_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_increment(memc, key, strlen(key),
@@ -597,7 +615,7 @@ uint8_t decrement_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)0, (uint16_t)0);
+                    (time_t)0, (uint32_t)0);
   assert(rc == MEMCACHED_SUCCESS);
 
   rc= memcached_decrement(memc, key, strlen(key),
@@ -621,13 +639,13 @@ uint8_t quit_test(memcached_st *memc)
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)10, (uint16_t)3);
+                    (time_t)10, (uint32_t)3);
   assert(rc == MEMCACHED_SUCCESS);
   memcached_quit(memc);
 
   rc= memcached_set(memc, key, strlen(key), 
                     value, strlen(value),
-                    (time_t)50, (uint16_t)9);
+                    (time_t)50, (uint32_t)9);
   assert(rc == MEMCACHED_SUCCESS);
 
   return 0;
@@ -667,7 +685,7 @@ uint8_t mget_result_test(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -717,7 +735,7 @@ uint8_t mget_result_alloc_test(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -746,7 +764,7 @@ uint8_t mget_test(memcached_st *memc)
   char *keys[]= {"fudge", "son", "food"};
   size_t key_length[]= {5, 3, 4};
   unsigned int x;
-  uint16_t flags;
+  uint32_t flags;
 
   char return_key[MEMCACHED_MAX_KEY];
   size_t return_key_length;
@@ -773,7 +791,7 @@ uint8_t mget_test(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -994,7 +1012,7 @@ uint8_t user_supplied_bug2(memcached_st *memc)
   {
     memcached_return rc= MEMCACHED_SUCCESS;
     char buffer[SMALL_STRING_LEN];
-    uint16_t flags= 0;
+    uint32_t flags= 0;
     size_t val_len= 0;
     char *getval;
 
@@ -1063,7 +1081,7 @@ uint8_t user_supplied_bug3(memcached_st *memc)
     size_t return_key_length;
     char *return_value;
     size_t return_value_length;
-    uint16_t flags;
+    uint32_t flags;
 
     while ((return_value= memcached_fetch(memc, return_key, &return_key_length, 
                                           &return_value_length, &flags, &rc)))
@@ -1088,7 +1106,11 @@ uint8_t user_supplied_bug4(memcached_st *memc)
   char *keys[]= {"fudge", "son", "food"};
   size_t key_length[]= {5, 3, 4};
   unsigned int x;
-  uint16_t flags;
+  uint32_t flags;
+  char return_key[MEMCACHED_MAX_KEY];
+  size_t return_key_length;
+  char *return_value;
+  size_t return_value_length;
 
   /* Here we free everything before running a bunch of mget tests */
   {
@@ -1097,10 +1119,6 @@ uint8_t user_supplied_bug4(memcached_st *memc)
     memc->number_of_hosts= 0;
   }
 
-  char return_key[MEMCACHED_MAX_KEY];
-  size_t return_key_length;
-  char *return_value;
-  size_t return_value_length;
 
   /* We need to empty the server before continueing test */
   rc= memcached_flush(memc, 0);
@@ -1122,7 +1140,7 @@ uint8_t user_supplied_bug4(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_NO_SERVERS);
   }
 
@@ -1154,7 +1172,7 @@ uint8_t user_supplied_bug5(memcached_st *memc)
   size_t return_key_length;
   char *value;
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
   unsigned int count;
   unsigned int x;
   char insert_data[VALUE_SIZE_BUG5];
@@ -1178,7 +1196,7 @@ uint8_t user_supplied_bug5(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       insert_data, VALUE_SIZE_BUG5,
-                      (time_t)0, (uint16_t)0);
+                      (time_t)0, (uint32_t)0);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -1212,7 +1230,7 @@ uint8_t user_supplied_bug6(memcached_st *memc)
   size_t return_key_length;
   char *value;
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
   unsigned int count;
   unsigned int x;
   char insert_data[VALUE_SIZE_BUG5];
@@ -1239,7 +1257,7 @@ uint8_t user_supplied_bug6(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       insert_data, VALUE_SIZE_BUG5,
-                      (time_t)0, (uint16_t)0);
+                      (time_t)0, (uint32_t)0);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -1308,7 +1326,7 @@ uint8_t user_supplied_bug7(memcached_st *memc)
   size_t return_key_length;
   char *value;
   size_t value_length;
-  uint16_t flags;
+  uint32_t flags;
   unsigned int x;
   char insert_data[VALUE_SIZE_BUG5];
 
@@ -1349,7 +1367,7 @@ uint8_t user_supplied_bug9(memcached_st *memc)
   char *keys[]= {"UDATA:edevil@sapo.pt", "fudge&*@#", "for^#@&$not"};
   size_t key_length[3];
   unsigned int x;
-  uint16_t flags;
+  uint32_t flags;
   unsigned count= 0;
 
   char return_key[MEMCACHED_MAX_KEY];
@@ -1367,7 +1385,7 @@ uint8_t user_supplied_bug9(memcached_st *memc)
   {
     rc= memcached_set(memc, keys[x], key_length[x], 
                       keys[x], key_length[x],
-                      (time_t)50, (uint16_t)9);
+                      (time_t)50, (uint32_t)9);
     assert(rc == MEMCACHED_SUCCESS);
   }
 
@@ -1387,6 +1405,7 @@ uint8_t user_supplied_bug9(memcached_st *memc)
   return 0;
 }
 
+/* We are testing with aggressive timeout to get failures */
 uint8_t user_supplied_bug10(memcached_st *memc)
 {
   char *key= "foo";
@@ -1397,9 +1416,12 @@ uint8_t user_supplied_bug10(memcached_st *memc)
   memcached_return rc;
   unsigned int set= 1;
   memcached_st *mclone= memcached_clone(NULL, memc);
+  int32_t timeout;
 
   memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
   memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
+  timeout= 2;
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
 
   value = (char*)malloc(value_length * sizeof(char));
 
@@ -1422,6 +1444,49 @@ uint8_t user_supplied_bug10(memcached_st *memc)
   return 0;
 }
 
+/*
+  We are looking failures in the async protocol
+*/
+uint8_t user_supplied_bug11(memcached_st *memc)
+{
+  char *key= "foo";
+  char *value;
+  size_t value_length= 512;
+  unsigned int x;
+  int key_len= 3;
+  memcached_return rc;
+  unsigned int set= 1;
+  int32_t timeout;
+  memcached_st *mclone= memcached_clone(NULL, memc);
+
+  memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
+  memcached_behavior_set(mclone, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
+  timeout= -1;
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, &timeout);
+
+  timeout= (int32_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT);
+
+  assert(timeout == -1);
+
+  value = (char*)malloc(value_length * sizeof(char));
+
+  for (x= 0; x < value_length; x++)
+    value[x]= (char) (x % 127);
+
+  for (x= 1; x <= 100000; ++x)
+  {
+    rc= memcached_set(mclone, key, key_len,value, value_length, 0, 0);
+
+    WATCHPOINT_IFERROR(rc);
+    //assert(rc == MEMCACHED_SUCCESS);
+  }
+
+  free(value);
+  memcached_free(mclone);
+
+  return 0;
+}
+
 uint8_t result_static(memcached_st *memc)
 {
   memcached_result_st result;
@@ -1569,7 +1634,7 @@ uint8_t get_read(memcached_st *memc)
   {
     char *return_value;
     size_t return_value_length;
-    uint16_t flags;
+    uint32_t flags;
 
     for (x= 0; x < GLOBAL_COUNT; x++)
     {
@@ -1599,7 +1664,7 @@ uint8_t mget_read(memcached_st *memc)
     size_t return_key_length;
     char *return_value;
     size_t return_value_length;
-    uint16_t flags;
+    uint32_t flags;
 
     while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
                                           &return_value_length, &flags, &rc)))
@@ -1638,6 +1703,28 @@ uint8_t mget_read_result(memcached_st *memc)
   return 0;
 }
 
+uint8_t delete_generate(memcached_st *memc)
+{
+  unsigned int x;
+
+  for (x= 0; x < GLOBAL_COUNT; x++)
+  {
+    (void)memcached_delete(memc, global_keys[x], global_keys_length[x], (time_t)0);
+  }
+
+  return 0;
+}
+
+uint8_t mdelete_generate(memcached_st *memc)
+{
+  memcached_return rc;
+
+  rc= memcached_mdelete(memc, global_keys, global_keys_length, GLOBAL_COUNT, 0);
+
+  return 0;
+}
+
+
 uint8_t free_data(memcached_st *memc)
 {
   pairs_free(global_pairs);
@@ -1883,6 +1970,11 @@ test_st tests[] ={
   {0, 0, 0}
 };
 
+test_st async_tests[] ={
+  {"add", 1, add_wrapper },
+  {0, 0, 0}
+};
+
 test_st string_tests[] ={
   {"string static with null", 0, string_static_null },
   {"string alloc with null", 0, string_alloc_null },
@@ -1919,6 +2011,7 @@ test_st user_tests[] ={
   {"user_supplied_bug8", 1, user_supplied_bug8 },
   {"user_supplied_bug9", 1, user_supplied_bug9 },
   {"user_supplied_bug10", 1, user_supplied_bug10 },
+  {"user_supplied_bug11", 1, user_supplied_bug11 },
   {0, 0, 0}
 };
 
@@ -1927,6 +2020,8 @@ test_st generate_tests[] ={
   {"get_read", 0, get_read },
   {"mget_read", 0, mget_read },
   {"mget_read_result", 0, mget_read_result },
+  {"mdelete_generate", 0, mdelete_generate },
+  {"delete_generate", 0, delete_generate },
   {"cleanup", 0, cleanup_pairs },
   {0, 0, 0}
 };
@@ -1953,6 +2048,7 @@ collection_st collection[] ={
   {"version_1_2_3", check_for_1_2_3, 0, version_1_2_3},
   {"string", 0, 0, string_tests},
   {"result", 0, 0, result_tests},
+  {"async", pre_nonblock, 0, async_tests},
   {"user", 0, 0, user_tests},
   {"generate", 0, 0, generate_tests},
   {"generate_hsieh", pre_hsieh, 0, generate_tests},