Skip to content

Commit 33317c3

Browse files
authored
Merge pull request #576 from Rahul-Sutariya/rasu_gatewayapp_registereventreceivehandlercallback_and_coverage
feat(gateway): Enable GatewayApplication::RegisterEventReceiveHandler and coverage
2 parents d1ce1e0 + 3ea654c commit 33317c3

9 files changed

Lines changed: 1133 additions & 41 deletions

File tree

score/mw/com/gateway/gateway_application/BUILD

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,26 @@ cc_unit_test(
9191
":gateway_error",
9292
"//score/mw/com/gateway/gateway_application/configuration:gateway_configuration",
9393
"//score/mw/com/gateway/transport_layer:transport_mock",
94+
"//score/mw/com/impl:find_service_handle",
95+
"//score/mw/com/impl:find_service_handler",
96+
"//score/mw/com/impl:handle_type",
97+
"//score/mw/com/impl:instance_identifier",
9498
"//score/mw/com/impl:instance_specifier",
99+
"//score/mw/com/impl:runtime_mock",
100+
"//score/mw/com/impl:scoped_event_receive_handler",
101+
"//score/mw/com/impl:service_discovery_client_mock",
102+
"//score/mw/com/impl:service_discovery_mock",
95103
"//score/mw/com/impl:service_element_type",
104+
"//score/mw/com/impl:subscription_state",
105+
"//score/mw/com/impl/bindings/mock_binding",
106+
"//score/mw/com/impl/bindings/mock_binding:generic_skeleton_event",
107+
"//score/mw/com/impl/configuration:lola_service_instance_deployment",
108+
"//score/mw/com/impl/plumbing:generic_skeleton_event_binding_factory",
109+
"//score/mw/com/impl/plumbing:generic_skeleton_event_binding_factory_mock",
110+
"//score/mw/com/impl/plumbing:skeleton_binding_factory_mock",
111+
"//score/mw/com/impl/test:binding_factory_resources",
112+
"//score/mw/com/impl/test:dummy_instance_identifier_builder",
113+
"//score/mw/com/impl/test:runtime_mock_guard",
96114
"@googletest//:gtest",
97115
"@score_baselibs//score/result",
98116
],

score/mw/com/gateway/gateway_application/gateway_application.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -223,26 +223,30 @@ void GatewayApplication::RegisterEventReceiveHandlerCallback(impl::GenericSkelet
223223
const std::string& specifier_str,
224224
const std::string& event_name)
225225
{
226-
// TODO: GenericSkeletonEvent::SetReceiveHandlerNotificationCallback is not yet available in the OSS impl.
227-
// Once available, remove the (void) suppressions below and uncomment the implementation block.
228-
(void)skeleton;
229-
(void)specifier_str;
230-
(void)event_name;
231-
232-
// using NotificationCallback = safecpp::MoveOnlyScopedFunction<void(bool)>;
233-
// auto scoped_callback = std::make_shared<NotificationCallback>(
234-
// scope_, [this, specifier = specifier_str, event = event_name](bool has_subscribers) {
235-
// OnSubscriptionStateChanged(specifier, event, has_subscribers);
236-
// });
237-
//
238-
// auto result = skeleton.SetReceiveHandlerNotificationCallback(
239-
// event_name, [scoped_callback](bool has_subscribers) { (*scoped_callback)(has_subscribers); });
240-
//
241-
// if (!result.has_value())
242-
// {
243-
// score::mw::log::LogError() << "GatewayApplication: Failed to set subscription callback for "
244-
// << event_name << " of " << specifier_str;
245-
// }
226+
using NotificationCallback = safecpp::MoveOnlyScopedFunction<void(bool)>;
227+
auto scoped_callback = std::make_shared<NotificationCallback>(
228+
scope_, [this, specifier = specifier_str, event = event_name](bool has_subscribers) {
229+
OnSubscriptionStateChanged(specifier, event, has_subscribers);
230+
});
231+
232+
auto event_map = skeleton.GetEvents();
233+
auto event_it = event_map.find(event_name);
234+
if (event_it == event_map.cend())
235+
{
236+
score::mw::log::LogError() << "GatewayApplication: Event " << event_name << " not found in skeleton for "
237+
<< specifier_str;
238+
return;
239+
}
240+
241+
auto result = event_it->second.SetReceiveHandlerRegistrationChangedHandler([scoped_callback](bool has_subscribers) {
242+
(*scoped_callback)(has_subscribers);
243+
});
244+
245+
if (!result.has_value())
246+
{
247+
score::mw::log::LogError() << "GatewayApplication: Failed to set subscription callback for " << event_name
248+
<< " of " << specifier_str;
249+
}
246250
}
247251

248252
void GatewayApplication::OnSubscriptionStateChanged(const std::string& specifier_str,

score/mw/com/gateway/gateway_application/gateway_application.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ class GatewayApplication : public GatewayCore
101101
bool has_subscribers);
102102
void ReRegisterActiveEventSubscriptions(const std::string& specifier_str);
103103

104+
// Test-only: grant unit-test fixtures access to private members and methods.
105+
friend class GatewayApplicationSubscriptionTest;
106+
friend class GatewayApplicationRegisterCallbackTest;
107+
friend class GatewayApplicationFlowTest;
108+
104109
// Intentionally putting the scope as the last member, so that it gets destroyed first and thus all callbacks get
105110
// invalidated before any other member gets destroyed.
106111
safecpp::Scope<> scope_;

0 commit comments

Comments
 (0)