Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a mock server for test #257

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ option(BUILD_TESTS "Build test programs" ON)
option(BUILD_EXAMPLES "Build example programs" ON)
option(BUILD_BENCHMARK "Build benchmark programs" ON)
option(BUILD_DOCUMENTS "build documents" ON)
option(BUILD_MOCK "Build mock server" OFF)
option(INSTALL_EXAMPLES "install examples" OFF)
option(BUILD_SHARED_LIBS "build shared libraries instead of static" ON)
option(ENABLE_CACHE_ALIGN "enable optional cache align requirement" OFF)
Expand Down Expand Up @@ -133,4 +134,7 @@ endif ()
if (BUILD_DOCUMENTS)
add_subdirectory(doxygen)
endif()
if(BUILD_MOCK)
add_subdirectory(mock)
endif()

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ available options:
* `-DCMAKE_IGNORE_PATH="/usr/local/include;/usr/local/lib/"` - specify the libraries search paths to ignore. This is convenient if the environment has conflicting version installed on system default search paths. (e.g. gflags in /usr/local)
* `-DBUILD_SHARED_LIBS=OFF` - create static libraries instead of shared libraries
* `-DBUILD_TESTS=OFF` - don't build test programs
* `-DBUILD_EXAMPLES=OFF` - don't build example programs
* `-DBUILD_BENCHMARK=OFF` - don't build benchmark programs
* `-DBUILD_DOCUMENTS=OFF` - don't build documents by doxygen
* `-DINSTALL_EXAMPLES=ON` - install example applications
* `-DBUILD_BENCHMARK=ON` - build benchmark programs
* `-DSHARKSFIN_IMPLEMENTATION=<implementation name>` - switch sharksfin implementation. Available options are `memory` and `shirakami` (default: `memory`)
* `-DENABLE_ALTIMETER=ON` - turn on the `altimeter logging`.
* `-DMC_QUEUE=ON` - use moody camel queue instead of tbb queue to store tasks in tateyama task scheduler.
Expand All @@ -72,6 +73,8 @@ available options:
* `-DENABLE_UB_SANITIZER=ON` - enable undefined behavior sanitizer (requires `-DENABLE_SANITIZER=ON`)
* `-DENABLE_COVERAGE=ON` - enable code coverage analysis (requires `-DCMAKE_BUILD_TYPE=Debug`)
* `-DTRACY_ENABLE=ON` - enable tracy profiler for multi-thread debugging. See section below.
* for developper only
* `-DBUILD_MOCK=ON` - build a mock server

### install

Expand Down
18 changes: 7 additions & 11 deletions include/tateyama/api/configuration.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 Project Tsurugi.
* Copyright 2018-2025 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -183,7 +183,7 @@ class whole {
}
}
// this constructor works as if property file exists and its content is provided as istream
whole(std::istream& content, std::string_view default_property) : property_file_exist_(true) {
whole(std::istream& content, std::string_view default_property) {
initialize(content, default_property);
}
// default_property can be empty only for test purpose
Expand Down Expand Up @@ -335,15 +335,11 @@ class whole {
BOOST_FOREACH(const boost::property_tree::ptree::value_type &v, default_tree_) {
auto& dt = default_tree_.get_child(v.first);
bool default_required = (v.first != "glog");
if (property_file_exist_) {
try {
auto& pt = property_tree_.get_child(v.first);
map_.emplace(v.first, std::make_unique<section>(pt, dt, this, default_required));
} catch (boost::property_tree::ptree_error &e) {
vlog_info_ << "cannot find " << v.first << " section in the input, thus we use default property only." << std::endl;
map_.emplace(v.first, std::make_unique<section>(dt, this, default_required));
}
} else {
try {
auto& pt = property_tree_.get_child(v.first);
map_.emplace(v.first, std::make_unique<section>(pt, dt, this, default_required));
} catch (boost::property_tree::ptree_error &e) {
vlog_info_ << "cannot find " << v.first << " section in the input, thus we use default property only." << std::endl;
map_.emplace(v.first, std::make_unique<section>(dt, this, default_required));
}
}
Expand Down
68 changes: 68 additions & 0 deletions mock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
if(NOT TARGET sharksfin-${SHARKSFIN_IMPLEMENTATION})
message(FATAL_ERROR "sharksfin implementation \"sharksfin-${SHARKSFIN_IMPLEMENTATION}\" not found")
endif()

file(GLOB_RECURSE ProtoFiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.proto")

# By default, PROTOBUF_GENERATE_CPP generates file path for .pb.cc as if they are in the same directory.
# Work-around this with PROTOBUF_GENERATE_CPP_APPEND_PATH
set(PROTOBUF_GENERATE_CPP_APPEND_PATH OFF)
PROTOBUF_GENERATE_CPP(GENERATED_PROTO_SRCS GENERATED_PROTO_HDRS ${ProtoFiles})
add_custom_target(build_protos_for_mock DEPENDS ${GENERATED_PROTO_SRCS})

file(GLOB SOURCES
"tateyama/server/*.cpp"
"tateyama/service/*.cpp"
"jogasaki/api/impl/*.cpp"
"jogasaki/serializer/*.cpp"
)

set_source_files_properties(
${GENERATED_SQL_PROTO_SRCS}
PROPERTIES
GENERATED TRUE
COMPILE_FLAGS "-Wno-unused-parameter -Wno-array-bounds"
)

add_executable(mock_server
${SOURCES}
${GENERATED_PROTO_SRCS}
)

add_dependencies(mock_server
build_protos_for_mock
)

set_target_properties(mock_server
PROPERTIES
INSTALL_RPATH "\$ORIGIN"
RUNTIME_OUTPUT_NAME "mock_server"
)

target_include_directories(mock_server
PRIVATE ${CMAKE_BINARY_DIR}/src
PRIVATE ${CMAKE_BINARY_DIR}/mock
PRIVATE ${CMAKE_SOURCE_DIR}/src
PRIVATE .
)

target_link_libraries(mock_server
PUBLIC api
PRIVATE tateyama-impl
PRIVATE takatori
PRIVATE Boost::boost
PRIVATE Boost::filesystem
PRIVATE Boost::thread
PRIVATE Boost::container
PRIVATE glog::glog
PRIVATE protobuf::libprotobuf
)

# Boost.Thread doesn't seem to allow multiple versions to coexist.
# This version definition should be shared with caller at least.
target_compile_definitions(mock_server PUBLIC BOOST_THREAD_VERSION=4)

set_compile_options(mock_server)

# target_name = mock_server, export_name = mock_server
install_custom(mock_server mock_server)
Loading