From e82f6a9bffe896a579ae5013a9cab51180cd003d Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Tue, 28 Jun 2011 22:16:23 -0700 Subject: [PATCH] Merge in next patch for --socket --- libtest/include.am | 2 +- libtest/{server.c => memcached.cc} | 24 +++++------------------- libtest/server.h | 1 - tests/libmemcached_world.h | 23 +++++++++-------------- tests/mem_functions.cc | 27 +++++++-------------------- 5 files changed, 22 insertions(+), 55 deletions(-) rename libtest/{server.c => memcached.cc} (90%) diff --git a/libtest/include.am b/libtest/include.am index 33ed8716..a1ed6ede 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -33,7 +33,7 @@ noinst_HEADERS+= \ libtest/visibility.h noinst_LTLIBRARIES+= libtest/libserver.la -libtest_libserver_la_SOURCES= libtest/server.c +libtest_libserver_la_SOURCES= libtest/memcached.cc noinst_LTLIBRARIES+= libtest/libtest.la libtest_libtest_la_SOURCES=\ diff --git a/libtest/server.c b/libtest/memcached.cc similarity index 90% rename from libtest/server.c rename to libtest/memcached.cc index dac57c77..8c79b17d 100644 --- a/libtest/server.c +++ b/libtest/memcached.cc @@ -62,10 +62,10 @@ #include -static struct timespec global_sleep_value= { .tv_sec= 0, .tv_nsec= 50000 }; - static void global_sleep(void) { + static struct timespec global_sleep_value= { 0, 50000 }; + #ifdef WIN32 sleep(1); #else @@ -133,8 +133,6 @@ void server_startup(server_startup_st *construct) if ((construct->server_list= getenv("MEMCACHED_SERVERS"))) { printf("servers %s\n", construct->server_list); - construct->servers= memcached_servers_parse(construct->server_list); - construct->server_list= NULL; construct->count= 0; } else @@ -220,11 +218,10 @@ void server_startup(server_startup_st *construct) } } - int count; size_t remaining_length= sizeof(server_string_buffer) - (size_t)(end_ptr -server_string_buffer); - count= snprintf(end_ptr, remaining_length, "localhost:%u,", construct->port[x]); + int count= snprintf(end_ptr, remaining_length, "--server=localhost:%u ", construct->port[x]); - if ((size_t)count >= remaining_length || count < 0) + if ((size_t)count >= remaining_length or count < 0) { fprintf(stderr, "server names grew to be larger then buffer allowed\n"); abort(); @@ -318,23 +315,12 @@ void server_startup(server_startup_st *construct) } } - construct->server_list= strdup(server_string_buffer); + construct->server_list= strndup(server_string_buffer, strlen(server_string_buffer) -1); } - printf("servers %s\n", construct->server_list); - construct->servers= memcached_servers_parse(construct->server_list); } - assert(construct->servers); - srandom((unsigned int)time(NULL)); - for (uint32_t x= 0; x < memcached_server_list_count(construct->servers); x++) - { - printf("\t%s : %d\n", memcached_server_name(&construct->servers[x]), memcached_server_port(&construct->servers[x])); - assert(construct->servers[x].fd == -1); - assert(construct->servers[x].cursor_active == 0); - } - printf("\n"); } diff --git a/libtest/server.h b/libtest/server.h index 581cf859..5444821d 100644 --- a/libtest/server.h +++ b/libtest/server.h @@ -27,7 +27,6 @@ struct server_startup_st { uint8_t count; uint8_t udp; - memcached_server_st *servers; char *server_list; char pid_file[SERVERS_TO_CREATE][FILENAME_MAX]; in_port_t port[SERVERS_TO_CREATE]; diff --git a/tests/libmemcached_world.h b/tests/libmemcached_world.h index fc0b6ae8..ea08db77 100644 --- a/tests/libmemcached_world.h +++ b/tests/libmemcached_world.h @@ -52,13 +52,6 @@ libmemcached_test_container_st *world_create(test_return_t *error) global_container.construct.udp= 0; server_startup(&global_container.construct); - if (not global_container.construct.servers) - { - *error= TEST_FAILURE; - server_shutdown(&global_container.construct); - return NULL; - } - *error= TEST_SUCCESS; return &global_container; @@ -66,11 +59,15 @@ libmemcached_test_container_st *world_create(test_return_t *error) test_return_t world_container_startup(libmemcached_test_container_st *container) { - container->parent= memcached_create(NULL); - test_true((container->parent != NULL)); + char buffer[BUFSIZ]; - test_compare(MEMCACHED_SUCCESS, - memcached_server_push(container->parent, container->construct.servers)); + test_compare_got(MEMCACHED_SUCCESS, + libmemcached_check_configuration(container->construct.server_list, strlen(container->construct.server_list), + buffer, sizeof(buffer)), + buffer); + + container->parent= memcached(container->construct.server_list, strlen(container->construct.server_list)); + test_true(container->parent); return TEST_SUCCESS; } @@ -86,7 +83,7 @@ test_return_t world_container_shutdown(libmemcached_test_container_st *container test_return_t world_test_startup(libmemcached_test_container_st *container) { container->memc= memcached_clone(NULL, container->parent); - test_true((container->memc != NULL)); + test_true(container->memc); return TEST_SUCCESS; } @@ -133,8 +130,6 @@ test_return_t world_on_error(test_return_t test_state, libmemcached_test_contain test_return_t world_destroy(libmemcached_test_container_st *container) { server_startup_st *construct= &container->construct; - memcached_server_st *servers= container->construct.servers; - memcached_server_list_free(servers); server_shutdown(construct); diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index da132940..d7402dbd 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -2910,19 +2910,14 @@ static test_return_t user_supplied_bug17(memcached_st *memc) From Andrei on IRC */ -static test_return_t user_supplied_bug19(memcached_st *not_used) +static test_return_t user_supplied_bug19(memcached_st *) { - memcached_st *memc; - const memcached_server_st *server; memcached_return_t res; - (void)not_used; - - memc= memcached_create(NULL); - memcached_server_add_with_weight(memc, "localhost", 11311, 100); - memcached_server_add_with_weight(memc, "localhost", 11312, 100); + memcached_st *memc= memcached(test_literal_param("--server=localhost:11311/?100 --server=localhost:11312/?100")); - server= memcached_server_by_key(memc, "a", 1, &res); + const memcached_server_st *server= memcached_server_by_key(memc, "a", 1, &res); + test_true(server); memcached_free(memc); @@ -4875,26 +4870,18 @@ static test_return_t memcached_get_hashkit_test (memcached_st *memc) We are testing the error condition when we connect to a server via memcached_get() but find that the server is not available. */ -static test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *memc) +static test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *) { - (void)memc; - memcached_st *tl_memc_h; - const char *key= "MemcachedLives"; size_t len; uint32_t flags; memcached_return rc; - char *value; // Create a handle. - tl_memc_h= memcached_create(NULL); - memcached_server_st *servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist - test_true(servers); - memcached_server_push(tl_memc_h, servers); - memcached_server_list_free(servers); + memcached_st *tl_memc_h= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist // See if memcached is reachable. - value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc); + char *value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc); test_false(value); test_compare(0, len); -- 2.30.2