Skip to content

Commit

Permalink
refactor: move zookeeper module from src/dist/replication to src/zook…
Browse files Browse the repository at this point in the history
…eeper (#549)
  • Loading branch information
levy5307 authored Jul 10, 2020
1 parent 4d6561d commit 975a6d8
Show file tree
Hide file tree
Showing 31 changed files with 258 additions and 52 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion src/dist/replication/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/dist/replication/meta_server/meta_service_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
#include <boost/lexical_cast.hpp>

#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 {
Expand Down
3 changes: 0 additions & 3 deletions src/tests/dsn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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"
Expand Down
8 changes: 0 additions & 8 deletions src/tests/dsn/config-test.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/tests/dsn/gtest.filter
Original file line number Diff line number Diff line change
@@ -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 *
3 changes: 0 additions & 3 deletions src/tests/dsn/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -83,7 +81,6 @@ GTEST_API_ int main(int argc, char **argv)

// register all possible services
dsn::service_app::register_factory<test_client>("test");
lock_test_init();

// specify what services and tools will run in config file, then run
if (argc < 2)
Expand Down
2 changes: 1 addition & 1 deletion src/tests/dsn/meta_state_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <thread>

#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;
Expand Down
9 changes: 0 additions & 9 deletions src/tests/dsn/restart_zookeeper.sh

This file was deleted.

18 changes: 0 additions & 18 deletions src/tests/dsn/run.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ set(MY_PROJ_LIBS "")
set(MY_BINPLACES "")

dsn_add_static_library()

add_subdirectory(tests)
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 29 additions & 0 deletions src/zookeeper/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions src/zookeeper/tests/clear.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

rm -rf client core* log.* *.log data
97 changes: 97 additions & 0 deletions src/zookeeper/tests/config-test.ini
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <dsn/service_api_cpp.h>

#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;
Expand Down
2 changes: 2 additions & 0 deletions src/zookeeper/tests/gtest.filter
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
config-test.ini distributed_lock_service_zookeeper.simple_lock_unlock
config-test.ini -distributed_lock_service_zookeeper.simple_lock_unlock
85 changes: 85 additions & 0 deletions src/zookeeper/tests/main.cpp
Original file line number Diff line number Diff line change
@@ -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 <iostream>

#ifndef _WIN32
#include <sys/types.h>
#include <signal.h>
#endif

#include <gtest/gtest.h>
#include <dsn/service_api_cpp.h>

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<std::string> &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_client>("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;
}
Loading

0 comments on commit 975a6d8

Please sign in to comment.