Skip to content

Commit

Permalink
Merge pull request #588 from apache/feature/585-celix-conditions
Browse files Browse the repository at this point in the history
Feature/585 celix conditions
  • Loading branch information
pnoltes authored Jul 31, 2023
2 parents d40cada + 43a9131 commit 1ff71f6
Show file tree
Hide file tree
Showing 57 changed files with 1,835 additions and 220 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ jobs:
-o celix:enable_code_coverage=True
-o celix:enable_testing_for_cxx14=True
-o celix:enable_testing_dependency_manager_for_cxx11=True
-o celix:enable_testing_on_ci=True
run: |
#force reequire libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
#force require libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
conan install . celix/ci -pr:b default -pr:h default -if build ${CONAN_BUILD_OPTIONS} -b missing -b cpputest --require-override=libcurl/7.64.1 --require-override=openssl/1.1.1s
- name: Build
run: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:

build-conan:
macos-build-conan:
runs-on: macOS-11
timeout-minutes: 120
steps:
Expand All @@ -30,8 +30,9 @@ jobs:
-o celix:build_all=True
-o celix:enable_testing_for_cxx14=True
-o celix:enable_testing_dependency_manager_for_cxx11=True
-o celix:enable_testing_on_ci=True
run: |
#force reequire libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
#force require libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
conan install . celix/ci -pr:b default -pr:h default -if build ${CONAN_BUILD_OPTIONS} -b missing -b cpputest --require-override=libcurl/7.64.1 --require-override=openssl/1.1.1s
- name: Build
run: |
Expand All @@ -45,8 +46,8 @@ jobs:
ctest --output-on-failure
source deactivate_run.sh
build-brew:
runs-on: macOS-11
macos-build-brew:
runs-on: macOS-latest
timeout-minutes: 120
steps:
- name: Checkout source code
Expand All @@ -62,6 +63,7 @@ jobs:
-DENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11=ON
-DENABLE_TESTING_FOR_CXX14=ON
-DENABLE_ADDRESS_SANITIZER=ON
-DENABLE_TESTING_ON_CI=ON
-DCMAKE_BUILD_TYPE=Release
run: |
mkdir build install
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:

build-conan:
linux-build-conan:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
Expand Down Expand Up @@ -50,6 +50,7 @@ jobs:
-o celix:build_all=True
-o celix:enable_testing_for_cxx14=True
-o celix:enable_testing_dependency_manager_for_cxx11=True
-o celix:enable_testing_on_ci=True
run: |
#force require libcurl 7.64.1, due to a sha256 verify issue in libcurl/7.87.0
conan install . celix/ci -pr:b release -pr:h default -if build ${CONAN_BUILD_OPTIONS} -b missing -b cpputest --require-override=libcurl/7.64.1 --require-override=openssl/1.1.1s
Expand All @@ -68,7 +69,7 @@ jobs:
ctest --output-on-failure
source deactivate_run.sh
build-apt:
linux-build-apt:
runs-on: ubuntu-22.04
timeout-minutes: 120
steps:
Expand Down Expand Up @@ -105,6 +106,7 @@ jobs:
-DRSA_SHM=ON
-DRSA_REMOTE_SERVICE_ADMIN_SHM_V2=ON
-DSHELL_BONJOUR=ON
-DENABLE_TESTING_ON_CI=ON
-DCMAKE_BUILD_TYPE=Debug
run: |
mkdir build install
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ endif ()
option(ENABLE_TESTING_DEPENDENCY_MANAGER_FOR_CXX11 "Test the Dependency Manager for C++11 support" OFF)
option(ENABLE_TESTING_FOR_CXX14 "Test celix utils and framework C++ header for C++14 support" OFF)

option(ENABLE_TESTING_ON_CI "Whether to enable testing on CI. This influence allowed timing errors during unit tests" OFF)

if (CELIX_INSTALL_DEPRECATED_API)
#ignore deprecated warnings
set(CMAKE_C_FLAGS "-Wno-deprecated-declarations ${CMAKE_C_FLAGS}")
Expand Down
1 change: 1 addition & 0 deletions bundles/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ add_subdirectory(deployment_admin)
add_subdirectory(remote_services)
add_subdirectory(pubsub)
add_subdirectory(cxx_remote_services)
add_subdirectory(components_ready_check)
50 changes: 50 additions & 0 deletions bundles/components_ready_check/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

celix_subproject(COMPONENTS_READY_CHECK "Bundle that checks if all components becomes active and reports this using a condition service" ON)
if (COMPONENTS_READY_CHECK)

add_library(components_ready_api INTERFACE)
target_include_directories(components_ready_api INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/api>)
add_library(Celix::components_ready_api ALIAS components_ready_api)
install(TARGETS components_ready_api EXPORT celix DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT components_ready
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix_components_ready_api)
install(DIRECTORY api/ DESTINATION include/celix_components_ready_api COMPONENT components_ready)


set(COMPONENTS_READY_CHECK_SRC src/celix_components_ready_check.c)
set(COMPONENTS_READY_CHECK_DEPS Celix::framework Celix::components_ready_api)
add_celix_bundle(components_ready_check
SOURCES src/celix_components_ready_check_activator.c ${COMPONENTS_READY_CHECK_SRC}
VERSION 1.0.0
SYMBOLIC_NAME "apache_celix_components_ready_check"
GROUP "Celix/Conditions"
NAME "Apache Celix Components Ready Check"
FILENAME celix_components_ready_check
)
target_include_directories(components_ready_check PRIVATE src)
target_link_libraries(components_ready_check PRIVATE ${COMPONENTS_READY_CHECK_DEPS})
add_library(Celix::components_ready_check ALIAS components_ready_check)
install_celix_bundle(components_ready_check EXPORT celix COMPONENT components_ready)

if (ENABLE_TESTING)
add_library(components_ready_cut STATIC ${COMPONENTS_READY_CHECK_SRC})
target_include_directories(components_ready_cut PUBLIC src)
target_link_libraries(components_ready_cut PUBLIC ${COMPONENTS_READY_CHECK_DEPS})
add_subdirectory(gtest)
endif()
endif ()
50 changes: 50 additions & 0 deletions bundles/components_ready_check/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Shell
---

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->

# Apache Celix Component Ready

## Intro
The Apache Celix Component Ready provides an api and bundle which can be used to check if all components are ready.

## API library
The Apache Celix Component Ready Check provides a single api library `Celix::component_ready_api` which contains
the condition id constant used to register the "components.ready" condition service.

## Bundle
The Apache Celix Component Ready Check provides the `Celix::components_ready_check` bundle which registers the
"components.ready" condition service.

The "components.ready" condition service will be registered when the "framework.ready" service is registered,
all components have become active and the event queue is empty.

If the "components.ready" condition service is registered and some components become inactive or the event queue is
not empty, the "components.ready" condition is **not** removed. The "components.ready" condition is meant to indicate
that the components in the initial framework startup phase are ready.

## CMake options

- COMPONENTS_READY_CHECK=ON

## Using info

If the Apache Celix Component Ready is installed, `find_package(Celix)` will set:
- The `Celix::component_ready_api` interface (i.e. header only) library target
- The `Celix::components_ready_check` bundle target
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#ifndef CELIX_COMPONENTS_READY_CONSTANTS_H_
#define CELIX_COMPONENTS_READY_CONSTANTS_H_

#ifdef __cplusplus
extern "C" {
#endif

/*!
* @brief The unique identifier for the components.ready condition.
*
* The components ready condition is registered by the framework if the framework.ready condition is registered
* and all components active.
*/
#define CELIX_CONDITION_ID_COMPONENTS_READY "components.ready"

#ifdef __cplusplus
}
#endif

#endif /* CELIX_COMPONENTS_READY_CONSTANTS_H_ */
57 changes: 57 additions & 0 deletions bundles/components_ready_check/gtest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.

set(CMAKE_CXX_STANDARD 17)

#Add active/inactive test component bundles
add_celix_bundle(ActiveComponentBundle SOURCES src/ActiveComponentBundle.cc VERSION 1.0.0)
add_celix_bundle(InactiveComponentBundle SOURCES src/InactiveComponentBundle.cc VERSION 1.0.0)

add_executable(test_components_ready src/ComponentsReadyTestSuite.cc)
target_link_libraries(test_components_ready PRIVATE
Celix::framework
Celix::components_ready_api
GTest::gtest
GTest::gtest_main
)
if (ENABLE_TESTING_ON_CI)
target_compile_definitions(test_components_ready PRIVATE TESTING_ON_CI=1)
endif ()
celix_target_bundle_set_definition(test_components_ready NAME COMPONENTS_READY_CHECK_BUNDLE_SET Celix::components_ready_check)
celix_target_bundle_set_definition(test_components_ready NAME ACTIVE_CMP_TEST_BUNDLE_SET ActiveComponentBundle)
celix_target_bundle_set_definition(test_components_ready NAME INACTIVE_CMP_TEST_BUNDLE_SET InactiveComponentBundle)

add_test(NAME test_components_ready COMMAND test_components_ready)
setup_target_for_coverage(test_components_ready SCAN_DIR ..)

if (LINKER_WRAP_SUPPORTED)
add_executable(test_components_ready_with_ei src/ComponentsReadyWithErrorInjectionTestSuite.cc)
target_link_libraries(test_components_ready_with_ei PRIVATE
framework_cut
components_ready_cut
Celix::components_ready_api
Celix::malloc_ei
Celix::threads_ei
Celix::bundle_ctx_ei
Celix::properties_ei
GTest::gtest
GTest::gtest_main
)

add_test(NAME test_components_ready_with_ei COMMAND test_components_ready_with_ei)
setup_target_for_coverage(test_components_ready_with_ei SCAN_DIR ..)
endif ()
41 changes: 41 additions & 0 deletions bundles/components_ready_check/gtest/src/ActiveComponentBundle.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

#include "celix/BundleActivator.h"
#include "celix_condition.h"

/**
* @brief Empty Test Component for testing the condition service
*/
class CondComponent {
public:
CondComponent() = default;
};

class ActiveComponentBundle {
public:
explicit ActiveComponentBundle(const std::shared_ptr<celix::BundleContext>& ctx) {
ctx->getDependencyManager()->createComponent<CondComponent>().build();
}

private:
std::shared_ptr<celix::ServiceRegistration> registration{};
};

CELIX_GEN_CXX_BUNDLE_ACTIVATOR(ActiveComponentBundle)
Loading

0 comments on commit 1ff71f6

Please sign in to comment.