uint32_t flags;
memcached_st *clone;
unsigned int set= 1;
+ size_t max_keylen= 0xffff;
clone= memcached_clone(NULL, memc);
assert(clone);
rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
assert(rc == MEMCACHED_SUCCESS);
- string= memcached_get(clone, key, strlen(key),
- &string_length, &flags, &rc);
- assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
- assert(string_length == 0);
- assert(!string);
+ /* All keys are valid in the binary protocol (except for length) */
+ if (memcached_behavior_get(clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 0)
+ {
+ string= memcached_get(clone, key, strlen(key),
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+ assert(string_length == 0);
+ assert(!string);
- set= 0;
- rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
- assert(rc == MEMCACHED_SUCCESS);
- string= memcached_get(clone, key, strlen(key),
- &string_length, &flags, &rc);
- assert(rc == MEMCACHED_NOTFOUND);
- assert(string_length == 0);
- assert(!string);
+ set= 0;
+ rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
+ assert(rc == MEMCACHED_SUCCESS);
+ string= memcached_get(clone, key, strlen(key),
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_NOTFOUND);
+ assert(string_length == 0);
+ assert(!string);
- /* Test multi key for bad keys */
- {
+ /* Test multi key for bad keys */
char *keys[] = { "GoodKey", "Bad Key", "NotMine" };
size_t key_lengths[] = { 7, 7, 7 };
set= 1;
rc= memcached_mget_by_key(clone, "foo daddy", 9, keys, key_lengths, 1);
assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+
+ max_keylen= 250;
+
+ /* The following test should be moved to the end of this function when the
+ memcached server is updated to allow max size length of the keys in the
+ binary protocol
+ */
+ rc= memcached_callback_set(clone, MEMCACHED_CALLBACK_PREFIX_KEY, NULL);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ char *longkey= malloc(max_keylen + 1);
+ if (longkey != NULL)
+ {
+ memset(longkey, 'a', max_keylen + 1);
+ string= memcached_get(clone, longkey, max_keylen,
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_NOTFOUND);
+ assert(string_length == 0);
+ assert(!string);
+
+ string= memcached_get(clone, longkey, max_keylen + 1,
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+ assert(string_length == 0);
+ assert(!string);
+
+ free(longkey);
+ }
}
/* Make sure zero length keys are marked as bad */
return MEMCACHED_SUCCESS;
}
+static memcached_return noreply_test(memcached_st *memc)
+{
+ memcached_return ret;
+ ret= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
+ assert(ret == MEMCACHED_SUCCESS);
+ ret= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
+ assert(ret == MEMCACHED_SUCCESS);
+ assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY) == 1);
+ assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS) == 1);
+
+ for (int x= 0; x < 100; ++x) {
+ char key[10];
+ size_t len= sprintf(key, "%d", x);
+ ret= memcached_set(memc, key, len, key, len, 0, 0);
+ assert(ret == MEMCACHED_SUCCESS || ret == MEMCACHED_BUFFERED);
+ }
+
+ /*
+ ** NOTE: Don't ever do this in your code! this is not a supported use of the
+ ** API and is _ONLY_ done this way to verify that the library works the
+ ** way it is supposed to do!!!!
+ */
+ int no_msg= 0;
+ for (int x= 0; x < memc->number_of_hosts; ++x) {
+ no_msg+= memc->hosts[x].cursor_active;
+ }
+
+ /*
+ ** The binary protocol does not implement quiet commands yet. Fix this
+ ** test they are implemented!
+ */
+ if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1)
+ assert(no_msg == 100);
+ else
+ assert(no_msg == 0);
+
+ return MEMCACHED_SUCCESS;
+}
/* Clean the server before beginning testing */
test_st tests[] ={
{"memcached_server_cursor", 1, memcached_server_cursor_test },
{"read_through", 1, read_through },
{"delete_through", 1, delete_through },
+ {"noreply", 1, noreply_test},
{0, 0, 0}
};