Skip to content

Commit

Permalink
make it possible to build tests in STUB_ONLY mode
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Aug 22, 2024
1 parent a29756e commit d8d187c
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ if(NOT BUILD_BRIDGE_ONLY)
find_package(metadata-manager REQUIRED)
find_package(message-manager REQUIRED)
find_package(Protobuf REQUIRED)
endif()
if(NOT BUILD_STUB_ONLY)
find_package(yugawara REQUIRED)
find_package(jogasaki-${SHARKSFIN_IMPLEMENTATION} REQUIRED)
find_package(tateyama-${SHARKSFIN_IMPLEMENTATION} REQUIRED)
Expand Down
5 changes: 1 addition & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ register_tests(
TARGET stub
DEPENDS
message-manager-interface
jogasaki-${SHARKSFIN_IMPLEMENTATION}-api
tateyama-${SHARKSFIN_IMPLEMENTATION}-api
sharksfin-api
Boost::serialization
glog::glog
gflags::gflags
Expand All @@ -34,7 +31,7 @@ register_tests(
${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/common/include
${CMAKE_SOURCE_DIR}/bridge/include
${CMAKE_SOURCE_DIR}/test/include
${CMAKE_BINARY_DIR}/src
)
endif()
Expand Down
97 changes: 97 additions & 0 deletions test/include/tateyama/framework/component.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2018-2024 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <cstdint>
#include <functional>
#include <memory>
#include <type_traits>

namespace tateyama::framework {

class environment;

/**
* @brief base class for tateyama components whose life-cycle is managed by the framework
*/
class component {
public:
/**
* @brief type to identify components
* @details the id must be unique among each categories of components (e.g. resource, service)
* Users custom module should use one larger than `max_system_reserved_id`.
*/
using id_type = std::uint32_t;

/**
* @brief maximum id reserved for built-in system resources/services
*/
static constexpr id_type max_system_reserved_id = 255;

/**
* @brief construct new object
*/
component() = default;

component(component const& other) = delete;
component& operator=(component const& other) = delete;
component(component&& other) noexcept = delete;
component& operator=(component&& other) noexcept = delete;

/**
* @brief setup the component (the state will be `ready`)
* @return true when setup completed successfully
* @return false otherwise
*/
virtual bool setup(environment&) = 0;

/**
* @brief start the component (the state will be `activated`)
* @return true when start completed successfully
* @return false otherwise
*/
virtual bool start(environment&) = 0;

/**
* @brief shutdown the component (the state will be `deactivated`)
* @return true when shutdown completed successfully, or component is already deactivated
* @return false otherwise
* @note shutdown is an idempotent operation, meaning second call to the already deactivated component should be
* simply ignored and return true.
*/
virtual bool shutdown(environment&) = 0;

/**
* @brief destruct the object (the state will be `disposed`)
*/
virtual ~component() = default;

/**
* @brief list the section names in the config. file that this component is affected
* @return the list of section name
*/
// TODO implement to validate config file
//virtual std::vector<std::string> configuration_sections() = 0;

/**
* @brief fetch human readable label of this component (not necessarily unique)
* @return the label for this component
*/
[[nodiscard]] virtual std::string_view label() const noexcept = 0;
};

}

45 changes: 45 additions & 0 deletions test/include/tateyama/framework/component_ids.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2018-2023 Project Tsurugi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once

#include <tateyama/framework/component.h>

namespace tateyama::framework {

// resource
constexpr inline component::id_type resource_id_task_scheduler = 0;
constexpr inline component::id_type resource_id_transactional_kvs = 1;
constexpr inline component::id_type resource_id_sql = 2;
constexpr inline component::id_type resource_id_datastore = 3;
constexpr inline component::id_type resource_id_session = 4;
constexpr inline component::id_type resource_id_status = 5;
//constexpr inline component::id_type resource_id_mutex = 6;
constexpr inline component::id_type resource_id_diagnostic = 7;
constexpr inline component::id_type resource_id_remote_kvs = 8;
constexpr inline component::id_type resource_id_metrics = 9;

// service
constexpr inline component::id_type service_id_routing = 0;
constexpr inline component::id_type service_id_endpoint_broker = 1;
constexpr inline component::id_type service_id_datastore = 2;
constexpr inline component::id_type service_id_sql = 3;
constexpr inline component::id_type service_id_fdw = 4;
constexpr inline component::id_type service_id_remote_kvs = 5;
constexpr inline component::id_type service_id_debug = 6;
constexpr inline component::id_type service_id_session = 7;
constexpr inline component::id_type service_id_metrics = 8;

}
5 changes: 1 addition & 4 deletions test/ogawayama/stub/endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,13 @@
#include <glog/logging.h>

#include <unordered_map>
#include <jogasaki/api.h>
#include <ogawayama/stub/api.h>
#include <ogawayama/bridge/service.h>
#include <tateyama/framework/server.h>
#include <tateyama/utils/protobuf_utils.h>
#include <tateyama/framework/component_ids.h>
#include <jogasaki/proto/sql/common.pb.h>
#include <jogasaki/proto/sql/request.pb.h>
#include <jogasaki/proto/sql/response.pb.h>

#include "tateyama/framework/component_ids.h"
#include "server_wires_impl.h"
#include "endpoint_proto_utils.h"
#include "ogawayama/stub/stubImpl.h"
Expand Down
3 changes: 0 additions & 3 deletions test/ogawayama/stub/endpoint_proto_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

#include <string_view>

#include <tateyama/api/server/request.h>

#include "tateyama/framework/component_ids.h"
#include <tateyama/proto/framework/request.pb.h>
#include <tateyama/proto/framework/response.pb.h>
#include <tateyama/utils/protobuf_utils.h>
Expand Down
1 change: 0 additions & 1 deletion test/ogawayama/stub/server_wires_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <thread>

#include <glog/logging.h>
#include <tateyama/logging.h>

#include "tateyama/transport/wire.h"

Expand Down
4 changes: 0 additions & 4 deletions test/ogawayama/stub/stub_test_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@

#include <gtest/gtest.h>
#include <glog/logging.h>
#include <ogawayama/logging.h>

#include <unordered_map>
#include <jogasaki/api.h>
#include <ogawayama/stub/api.h>
#include <ogawayama/bridge/service.h>
#include <tateyama/framework/server.h>
#include <tateyama/utils/protobuf_utils.h>
#include <jogasaki/proto/sql/common.pb.h>
#include <jogasaki/proto/sql/request.pb.h>
Expand Down

0 comments on commit d8d187c

Please sign in to comment.