diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3d030c0b19..84721264c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,7 @@ endif() add_subdirectory(core) add_subdirectory(aio) add_subdirectory(dist) +add_subdirectory(zookeeper) add_subdirectory(perf_counter) add_subdirectory(failure_detector) add_subdirectory(remote_cmd) diff --git a/src/dist/replication/CMakeLists.txt b/src/dist/replication/CMakeLists.txt index 9b640cb31d..2c29c31a29 100644 --- a/src/dist/replication/CMakeLists.txt +++ b/src/dist/replication/CMakeLists.txt @@ -2,6 +2,5 @@ add_subdirectory(common) add_subdirectory(tool_lib) add_subdirectory(meta_server) add_subdirectory(lib) -add_subdirectory(zookeeper) add_subdirectory(test) add_subdirectory(storage_engine) diff --git a/src/dist/replication/meta_server/meta_service_app.cpp b/src/dist/replication/meta_server/meta_service_app.cpp index f9f4b94c41..ae50f7af8a 100644 --- a/src/dist/replication/meta_server/meta_service_app.cpp +++ b/src/dist/replication/meta_server/meta_service_app.cpp @@ -33,8 +33,8 @@ #include "meta_state_service_simple.h" #include "http/server_info_http_services.h" -#include "dist/replication/zookeeper/distributed_lock_service_zookeeper.h" -#include "dist/replication/zookeeper/meta_state_service_zookeeper.h" +#include "zookeeper/distributed_lock_service_zookeeper.h" +#include "meta_state_service_zookeeper.h" #include "server_load_balancer.h" #include "greedy_load_balancer.h" diff --git a/src/dist/replication/zookeeper/meta_state_service_zookeeper.cpp b/src/dist/replication/meta_server/meta_state_service_zookeeper.cpp similarity index 99% rename from src/dist/replication/zookeeper/meta_state_service_zookeeper.cpp rename to src/dist/replication/meta_server/meta_state_service_zookeeper.cpp index c02b4e895e..5090a709e4 100644 --- a/src/dist/replication/zookeeper/meta_state_service_zookeeper.cpp +++ b/src/dist/replication/meta_server/meta_state_service_zookeeper.cpp @@ -38,9 +38,9 @@ #include #include "meta_state_service_zookeeper.h" -#include "zookeeper_session_mgr.h" -#include "zookeeper_session.h" -#include "zookeeper_error.h" +#include "zookeeper/zookeeper_session_mgr.h" +#include "zookeeper/zookeeper_session.h" +#include "zookeeper/zookeeper_error.h" namespace dsn { namespace dist { diff --git a/src/dist/replication/zookeeper/meta_state_service_zookeeper.h b/src/dist/replication/meta_server/meta_state_service_zookeeper.h similarity index 100% rename from src/dist/replication/zookeeper/meta_state_service_zookeeper.h rename to src/dist/replication/meta_server/meta_state_service_zookeeper.h diff --git a/src/tests/dsn/CMakeLists.txt b/src/tests/dsn/CMakeLists.txt index efe11077a3..790eba7851 100644 --- a/src/tests/dsn/CMakeLists.txt +++ b/src/tests/dsn/CMakeLists.txt @@ -13,9 +13,7 @@ set(MY_PROJ_LIBS dsn_meta_server dsn_replica_server dsn_replication_common - dsn.replication.zookeeper_provider dsn_runtime - zookeeper_mt gtest ) @@ -24,7 +22,6 @@ set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex) # Extra files that will be installed set(MY_BINPLACES "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" - "${CMAKE_CURRENT_SOURCE_DIR}/restart_zookeeper.sh" "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" "${CMAKE_CURRENT_SOURCE_DIR}/clear.cmd" "${CMAKE_CURRENT_SOURCE_DIR}/config-test.ini" diff --git a/src/tests/dsn/config-test.ini b/src/tests/dsn/config-test.ini index abac2c1b7c..b692830588 100644 --- a/src/tests/dsn/config-test.ini +++ b/src/tests/dsn/config-test.ini @@ -22,14 +22,6 @@ run = false count = 0 pools = THREAD_POOL_DEFAULT, THREAD_POOL_REPLICATION -[apps.add_server] -type = adder -arguments = -ports = 20201 -run = true -count = 3 -pools = THREAD_POOL_DEFAULT, THREAD_POOL_DLOCK - [core] ;tool = simulator tool = nativerun diff --git a/src/tests/dsn/gtest.filter b/src/tests/dsn/gtest.filter index 9d145cdc7c..abbe502446 100644 --- a/src/tests/dsn/gtest.filter +++ b/src/tests/dsn/gtest.filter @@ -1,2 +1 @@ -config-test.ini distributed_lock_service_zookeeper.simple_lock_unlock -config-test.ini -distributed_lock_service_zookeeper.simple_lock_unlock +config-test.ini * diff --git a/src/tests/dsn/main.cpp b/src/tests/dsn/main.cpp index 82470d876b..0c6995c5a5 100644 --- a/src/tests/dsn/main.cpp +++ b/src/tests/dsn/main.cpp @@ -46,8 +46,6 @@ int g_test_count = 0; int g_test_ret = 0; -extern void lock_test_init(); - class test_client : public ::dsn::service_app { public: @@ -83,7 +81,6 @@ GTEST_API_ int main(int argc, char **argv) // register all possible services dsn::service_app::register_factory("test"); - lock_test_init(); // specify what services and tools will run in config file, then run if (argc < 2) diff --git a/src/tests/dsn/meta_state_service.cpp b/src/tests/dsn/meta_state_service.cpp index 1fdb0e0694..accdf5f765 100644 --- a/src/tests/dsn/meta_state_service.cpp +++ b/src/tests/dsn/meta_state_service.cpp @@ -6,7 +6,7 @@ #include #include "dist/replication/meta_server/meta_state_service_simple.h" -#include "dist/replication/zookeeper/meta_state_service_zookeeper.h" +#include "dist/replication/meta_server/meta_state_service_zookeeper.h" using namespace dsn; using namespace dsn::dist; diff --git a/src/tests/dsn/restart_zookeeper.sh b/src/tests/dsn/restart_zookeeper.sh deleted file mode 100755 index 147046af74..0000000000 --- a/src/tests/dsn/restart_zookeeper.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -pushd ../../../ -while [ 0 -lt 1 ]; do - ./run.sh stop_zk - ./run.sh start_zk - sleep 3 -done -popd diff --git a/src/tests/dsn/run.sh b/src/tests/dsn/run.sh index 00e4d51465..ba179ec724 100755 --- a/src/tests/dsn/run.sh +++ b/src/tests/dsn/run.sh @@ -1,23 +1,5 @@ #!/bin/bash -function prepare_environment() -{ - if [ $1 == "distributed_lock_service_zookeeper.simple_lock_unlock" ]; then - echo "test $1, try to restart to zookeeper service periodically" - ./restart_zookeeper.sh >output.log 2>&1 & - fi -} - -function destroy_environment() -{ - if [ $1 == "distributed_lock_service_zookeeper.simple_lock_unlock" ]; then - echo "stop restart-zookeeper process" - ps aux | grep restart_zookeeper | grep -v "grep" | awk '{print $2}' | xargs kill -9 - echo "make sure the zookeeper is started" - pushd ../../../ && ./run.sh start_zk && popd - fi -} - if [ -z "${REPORT_DIR}" ]; then REPORT_DIR="." fi diff --git a/src/dist/replication/zookeeper/CMakeLists.txt b/src/zookeeper/CMakeLists.txt similarity index 95% rename from src/dist/replication/zookeeper/CMakeLists.txt rename to src/zookeeper/CMakeLists.txt index c10cfc8df2..3f3b927e37 100644 --- a/src/dist/replication/zookeeper/CMakeLists.txt +++ b/src/zookeeper/CMakeLists.txt @@ -16,3 +16,5 @@ set(MY_PROJ_LIBS "") set(MY_BINPLACES "") dsn_add_static_library() + +add_subdirectory(tests) diff --git a/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp b/src/zookeeper/distributed_lock_service_zookeeper.cpp similarity index 100% rename from src/dist/replication/zookeeper/distributed_lock_service_zookeeper.cpp rename to src/zookeeper/distributed_lock_service_zookeeper.cpp diff --git a/src/dist/replication/zookeeper/distributed_lock_service_zookeeper.h b/src/zookeeper/distributed_lock_service_zookeeper.h similarity index 100% rename from src/dist/replication/zookeeper/distributed_lock_service_zookeeper.h rename to src/zookeeper/distributed_lock_service_zookeeper.h diff --git a/src/dist/replication/zookeeper/lock_struct.cpp b/src/zookeeper/lock_struct.cpp similarity index 100% rename from src/dist/replication/zookeeper/lock_struct.cpp rename to src/zookeeper/lock_struct.cpp diff --git a/src/dist/replication/zookeeper/lock_struct.h b/src/zookeeper/lock_struct.h similarity index 100% rename from src/dist/replication/zookeeper/lock_struct.h rename to src/zookeeper/lock_struct.h diff --git a/src/dist/replication/zookeeper/lock_types.h b/src/zookeeper/lock_types.h similarity index 100% rename from src/dist/replication/zookeeper/lock_types.h rename to src/zookeeper/lock_types.h diff --git a/src/zookeeper/tests/CMakeLists.txt b/src/zookeeper/tests/CMakeLists.txt new file mode 100644 index 0000000000..35c2591bda --- /dev/null +++ b/src/zookeeper/tests/CMakeLists.txt @@ -0,0 +1,29 @@ +set(MY_PROJ_NAME dsn.zookeeper.tests) + +# Source files under CURRENT project directory will be automatically included. +# You can manually set MY_PROJ_SRC to include source files under other directories. +set(MY_PROJ_SRC "") + +# Search mode for source files under CURRENT project directory? +# "GLOB_RECURSE" for recursive search +# "GLOB" for non-recursive search +set(MY_SRC_SEARCH_MODE "GLOB") + +set(MY_PROJ_LIBS + dsn.replication.zookeeper_provider + dsn_runtime + zookeeper_mt + gtest + ) + +set(MY_BOOST_LIBS Boost::system Boost::filesystem Boost::regex) + +# Extra files that will be installed +set(MY_BINPLACES + "${CMAKE_CURRENT_SOURCE_DIR}/run.sh" + "${CMAKE_CURRENT_SOURCE_DIR}/clear.sh" + "${CMAKE_CURRENT_SOURCE_DIR}/config-test.ini" + "${CMAKE_CURRENT_SOURCE_DIR}/gtest.filter" +) + +dsn_add_test() diff --git a/src/zookeeper/tests/clear.sh b/src/zookeeper/tests/clear.sh new file mode 100755 index 0000000000..3e8cb2e749 --- /dev/null +++ b/src/zookeeper/tests/clear.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +rm -rf client core* log.* *.log data diff --git a/src/zookeeper/tests/config-test.ini b/src/zookeeper/tests/config-test.ini new file mode 100644 index 0000000000..9da37aa60e --- /dev/null +++ b/src/zookeeper/tests/config-test.ini @@ -0,0 +1,97 @@ +[apps..default] +run = true +count = 1 +;network.client.RPC_CHANNEL_TCP = dsn::tools::sim_network_provider, 65536 +;network.client.RPC_CHANNEL_UDP = dsn::tools::sim_network_provider, 65536 +;network.server.0.RPC_CHANNEL_TCP = dsn::tools::sim_network_provider, 65536 + +[apps.client] +type = test +arguments = localhost 20101 +run = true +ports = +count = 1 +delay_seconds = 1 +pools = THREAD_POOL_DEFAULT, THREAD_POOL_DLOCK, THREAD_POOL_REPLICATION, THREAD_POOL_REPLICATION_LONG + +[apps.server] +type = test +arguments = +ports = 20101 +run = false +count = 0 +pools = THREAD_POOL_DEFAULT, THREAD_POOL_REPLICATION + +[apps.add_server] +type = adder +arguments = +ports = 20201 +run = true +count = 3 +pools = THREAD_POOL_DEFAULT, THREAD_POOL_DLOCK + +[core] +;tool = simulator +tool = nativerun + +;toollets = tracer, profiler +;fault_injector +pause_on_start = false + +logging_start_level = LOG_LEVEL_INFORMATION +logging_factory_name = dsn::tools::simple_logger + + +[tools.simple_logger] +fast_flush = true +short_header = false +stderr_start_level = LOG_LEVEL_WARNING + +[tools.simulator] +random_seed = 0 + +[tools.screen_logger] +short_header = false + +[network] +; how many network threads for network library (used by asio) +io_service_worker_count = 2 + +[task..default] +is_trace = true +is_profile = true +allow_inline = false +rpc_call_channel = RPC_CHANNEL_TCP +rpc_message_header_format = dsn +rpc_timeout_milliseconds = 5000 + +[task.LPC_AIO_IMMEDIATE_CALLBACK] +is_trace = false +is_profile = false +allow_inline = false + +[task.LPC_RPC_TIMEOUT] +is_trace = false +is_profile = false + +; specification for each thread pool +[threadpool..default] +worker_count = 2 + +[threadpool.THREAD_POOL_DEFAULT] +partitioned = false +worker_priority = THREAD_xPRIORITY_NORMAL + +[threadpool.THREAD_POOL_TEST_SERVER] +partitioned = false + +[threadpool.THREAD_POOL_FDS_SERVICE] +worker_count = 8 + +[threadpool.THREAD_POOL_DLOCK] +partitioned = true + +[zookeeper] +hosts_list = localhost:12181 +timeout_ms = 30000 +logfile = zoolog.log diff --git a/src/tests/dsn/distributed_lock_zookeeper.cpp b/src/zookeeper/tests/distributed_lock_zookeeper.cpp similarity index 98% rename from src/tests/dsn/distributed_lock_zookeeper.cpp rename to src/zookeeper/tests/distributed_lock_zookeeper.cpp index 121d1a05d4..b09b8eae9e 100644 --- a/src/tests/dsn/distributed_lock_zookeeper.cpp +++ b/src/zookeeper/tests/distributed_lock_zookeeper.cpp @@ -8,8 +8,8 @@ #include -#include "dist/replication/zookeeper/distributed_lock_service_zookeeper.h" -#include "dist/replication/zookeeper/lock_struct.h" +#include "zookeeper/distributed_lock_service_zookeeper.h" +#include "zookeeper/lock_struct.h" using namespace dsn; using namespace dsn::dist; diff --git a/src/zookeeper/tests/gtest.filter b/src/zookeeper/tests/gtest.filter new file mode 100644 index 0000000000..9d145cdc7c --- /dev/null +++ b/src/zookeeper/tests/gtest.filter @@ -0,0 +1,2 @@ +config-test.ini distributed_lock_service_zookeeper.simple_lock_unlock +config-test.ini -distributed_lock_service_zookeeper.simple_lock_unlock diff --git a/src/zookeeper/tests/main.cpp b/src/zookeeper/tests/main.cpp new file mode 100644 index 0000000000..f85554e5bc --- /dev/null +++ b/src/zookeeper/tests/main.cpp @@ -0,0 +1,85 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2015 Microsoft Corporation + * + * -=- Robust Distributed System Nucleus (rDSN) -=- + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#ifndef _WIN32 +#include +#include +#endif + +#include +#include + +int g_test_count = 0; +int g_test_ret = 0; + +extern void lock_test_init(); + +class test_client : public ::dsn::service_app +{ +public: + test_client(const dsn::service_app_info *info) : ::dsn::service_app(info) {} + + ::dsn::error_code start(const std::vector &args) + { + int argc = args.size(); + char *argv[20]; + for (int i = 0; i < argc; ++i) { + argv[i] = (char *)(args[i].c_str()); + } + testing::InitGoogleTest(&argc, argv); + g_test_ret = RUN_ALL_TESTS(); + g_test_count = 1; + return ::dsn::ERR_OK; + } + + ::dsn::error_code stop(bool cleanup = false) { return ::dsn::ERR_OK; } +}; + +GTEST_API_ int main(int argc, char **argv) +{ + testing::InitGoogleTest(&argc, argv); + + // register all possible services + dsn::service_app::register_factory("test"); + lock_test_init(); + + // specify what services and tools will run in config file, then run + if (argc < 2) + dsn_run_config("config-test.ini", false); + else + dsn_run_config(argv[1], false); + + while (g_test_count == 0) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + +#ifndef ENABLE_GCOV + dsn_exit(g_test_ret); +#endif + return g_test_ret; +} diff --git a/src/zookeeper/tests/run.sh b/src/zookeeper/tests/run.sh new file mode 100755 index 0000000000..42de723e90 --- /dev/null +++ b/src/zookeeper/tests/run.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +if [ -z "${REPORT_DIR}" ]; then + REPORT_DIR="." +fi + +while read -r -a line; do + test_case=${line[0]} + gtest_filter=${line[1]} + output_xml="${REPORT_DIR}/dsn.zookeeper.tests_${test_case/.ini/.xml}" + echo "============ run dsn.zookeeper.tests ${test_case} with gtest_filter ${gtest_filter} ============" + ./clear.sh + GTEST_OUTPUT="xml:${output_xml}" GTEST_FILTER=${gtest_filter} ./dsn.zookeeper.tests ${test_case} + + if [ $? -ne 0 ]; then + echo "run dsn.zookeeper.tests $test_case failed" + echo "---- ls ----" + ls -l + if find . -name log.1.txt; then + echo "---- tail -n 100 log.1.txt ----" + tail -n 100 `find . -name log.1.txt` + fi + if [ -f core ]; then + echo "---- gdb ./dsn.zookeeper.tests core ----" + gdb ./dsn.zookeeper.tests core -ex "thread apply all bt" -ex "set pagination 0" -batch + fi + exit 1 + fi + echo "============ done dsn.zookeeper.tests ${test_case} with gtest_filter ${gtest_filter} ============" +done