From: Brian Aker Date: Mon, 3 Oct 2011 04:46:09 +0000 (-0400) Subject: Add test case for situation where callback shouldn't be set because of behavior settings. X-Git-Tag: 1.0.2~9^2~2^2~5 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6c4917af4d1f4da7fa48550843bcbfb2a36c3761;p=awesomized%2Flibmemcached Add test case for situation where callback shouldn't be set because of behavior settings. --- diff --git a/libmemcached/callback.cc b/libmemcached/callback.cc index 32d85dcd..83d8ce8f 100644 --- a/libmemcached/callback.cc +++ b/libmemcached/callback.cc @@ -60,22 +60,26 @@ memcached_return_t memcached_callback_set(memcached_st *ptr, case MEMCACHED_CALLBACK_DELETE_TRIGGER: { - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) + if (data) // NULL would mean we are disabling. { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if buffering is enabled")); - } - - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_NOREPLY)) - { - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if MEMCACHED_BEHAVIOR_NOREPLY is set")); + if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if buffering is enabled")); + } + + if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_NOREPLY)) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Delete triggers cannot be used if MEMCACHED_BEHAVIOR_NOREPLY is set")); + } } memcached_trigger_delete_key_fn func= *(memcached_trigger_delete_key_fn *)&data; ptr->delete_trigger= func; break; } + case MEMCACHED_CALLBACK_MAX: - return MEMCACHED_FAILURE; + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid callback supplied")); } return MEMCACHED_SUCCESS; diff --git a/libmemcached/callback.h b/libmemcached/callback.h new file mode 100644 index 00000000..3949ea3d --- /dev/null +++ b/libmemcached/callback.h @@ -0,0 +1,42 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER(memcached_st *); + +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY(memcached_st *); diff --git a/tests/callbacks.cc b/tests/callbacks.cc new file mode 100644 index 00000000..c490e002 --- /dev/null +++ b/tests/callbacks.cc @@ -0,0 +1,83 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include + +#include + +using namespace libtest; + +static memcached_return_t delete_trigger(memcached_st *, + const char *key, + size_t key_length) +{ + assert(key); + assert(key_length); + + return MEMCACHED_SUCCESS; +} + + +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY(memcached_st *) +{ + memcached_st *memc= memcached(test_literal_param("--NOREPLY")); + test_true(memc); + + memcached_trigger_delete_key_fn callback; + + callback= (memcached_trigger_delete_key_fn)delete_trigger; + + test_compare(MEMCACHED_INVALID_ARGUMENTS, + memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback)); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER(memcached_st *memc) +{ + memcached_trigger_delete_key_fn callback; + + callback= (memcached_trigger_delete_key_fn)delete_trigger; + + test_compare(MEMCACHED_SUCCESS, + memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback)); + + return TEST_SUCCESS; +} diff --git a/tests/callbacks.h b/tests/callbacks.h new file mode 100644 index 00000000..070670ce --- /dev/null +++ b/tests/callbacks.h @@ -0,0 +1,41 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY(memcached_st *); +test_return_t test_MEMCACHED_CALLBACK_DELETE_TRIGGER(memcached_st *); diff --git a/tests/include.am b/tests/include.am index 8e173d88..a4cf4c6a 100644 --- a/tests/include.am +++ b/tests/include.am @@ -23,6 +23,7 @@ EXTRA_DIST+= \ noinst_HEADERS+= \ tests/basic.h \ + tests/callbacks.h \ tests/debug.h \ tests/error_conditions.h \ tests/exist.h \ @@ -77,6 +78,7 @@ tests_testapp_SOURCES= \ tests/mem_functions.cc \ tests/namespace.cc \ tests/parser.cc \ + tests/callbacks.cc \ tests/pool.cc \ tests/print.cc \ tests/replication.cc \ diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index c0e76be9..d0a59fdc 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -78,6 +78,7 @@ #include "tests/ketama.h" #include "tests/namespace.h" #include "tests/parser.h" +#include "tests/callbacks.h" #include "tests/pool.h" #include "tests/print.h" #include "tests/replication.h" @@ -981,28 +982,6 @@ static test_return_t read_through(memcached_st *memc) return TEST_SUCCESS; } -static memcached_return_t delete_trigger(memcached_st *, - const char *key, - size_t key_length) -{ - assert(key); - assert(key_length); - - return MEMCACHED_SUCCESS; -} - -static test_return_t delete_through(memcached_st *memc) -{ - memcached_trigger_delete_key_fn callback; - - callback= (memcached_trigger_delete_key_fn)delete_trigger; - - test_compare(MEMCACHED_SUCCESS, - memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback)); - - return TEST_SUCCESS; -} - static test_return_t get_test(memcached_st *memc) { memcached_return_t rc; @@ -3733,7 +3712,7 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc) /* Make sure be default none exists */ value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); test_null(value); - test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc)); + test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); /* Test a clean set */ test_compare(MEMCACHED_SUCCESS, @@ -3749,8 +3728,8 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc) memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL)); value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); - test_false(value); - test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc)); + test_null(value); + test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); /* Now setup for main test */ test_compare(MEMCACHED_SUCCESS, @@ -3770,9 +3749,8 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc) memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL)); value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc); - test_false(value); - test_true(rc == MEMCACHED_FAILURE); - test_true(value == NULL); + test_null(value); + test_compare(MEMCACHED_SUCCESS, rc); /* Test a long key for failure */ /* TODO, extend test to determine based on setting, what result should be */ @@ -5960,7 +5938,7 @@ test_st tests[] ={ {"bad_key", true, (test_callback_fn*)bad_key_test }, {"memcached_server_cursor", true, (test_callback_fn*)memcached_server_cursor_test }, {"read_through", true, (test_callback_fn*)read_through }, - {"delete_through", true, (test_callback_fn*)delete_through }, + {"delete_through", true, (test_callback_fn*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER }, {"noreply", true, (test_callback_fn*)noreply_test}, {"analyzer", true, (test_callback_fn*)analyzer_test}, {"memcached_pool_st", true, (test_callback_fn*)connection_pool_test }, @@ -5985,6 +5963,7 @@ test_st behavior_tests[] ={ {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test}, {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test}, {"MEMCACHED_BEHAVIOR_POLL_TIMEOUT", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test}, + {"MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY", false, (test_callback_fn*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY}, {0, 0, 0} }; diff --git a/tests/parser.cc b/tests/parser.cc index 9e0c0c95..bfcb0816 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -647,11 +647,7 @@ test_return_t regression_bug_71231153_poll(memcached_st *) char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc); test_false(value); test_zero(value_len); -#ifdef __APPLE__ - test_compare_got(MEMCACHED_CONNECTION_FAILURE, rc, memcached_last_error_message(memc)); -#else test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc)); -#endif memcached_free(memc); }