void Dispatcher::addReplyCaller(const std::string& requestReplyId, QSharedPointer<IReplyCaller> replyCaller, const MessagingQos& qosSettings) { LOG_DEBUG(logger, "addReplyCaller id= " + QString::fromStdString(requestReplyId)); // add the callback to the registry that is responsible for reply messages replyCallerDirectory.add(requestReplyId, replyCaller, qosSettings.getTtl()); }
void Dispatcher::addReplyCaller(const std::string& requestReplyId, std::shared_ptr<IReplyCaller> replyCaller, const MessagingQos& qosSettings) { JOYNR_LOG_DEBUG(logger, "addReplyCaller id= {}", requestReplyId); // add the callback to the registry that is responsible for reply messages replyCallerDirectory.add(requestReplyId, replyCaller, qosSettings.getTtl()); }
JoynrMessage JoynrMessageFactory::createOneWay(const std::string& senderId, const std::string& receiverId, const MessagingQos& qos, const Reply& payload) const { JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_ONE_WAY); initMsg(msg, senderId, receiverId, qos.getTtl(), JsonSerializer::serialize<Reply>(payload)); return msg; }
JoynrMessage JoynrMessageFactory::createRequest(const std::string& senderId, const std::string& receiverId, const MessagingQos& qos, const Request& payload) const { // create message and set type JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_REQUEST); initMsg(msg, senderId, receiverId, qos.getTtl(), JsonSerializer::serialize<Request>(payload)); return msg; }
JoynrMessage JoynrMessageFactory::createSubscriptionStop(const std::string& senderId, const std::string& receiverId, const MessagingQos& qos, const SubscriptionStop& payload) const { JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_STOP); initMsg(msg, senderId, receiverId, qos.getTtl(), JsonSerializer::serialize<SubscriptionStop>(payload)); return msg; }
JoynrMessage JoynrMessageFactory::createSubscriptionPublication( const std::string& senderId, const std::string& receiverId, const MessagingQos& qos, const SubscriptionPublication& payload) const { JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_PUBLICATION); initMsg(msg, senderId, receiverId, qos.getTtl(), JsonSerializer::serialize<SubscriptionPublication>(payload)); return msg; }
JoynrMessage JoynrMessageFactory::createBroadcastSubscriptionRequest( const std::string& senderId, const std::string& receiverId, const MessagingQos& qos, const BroadcastSubscriptionRequest& payload) const { JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST); initMsg(msg, senderId, receiverId, qos.getTtl(), JsonSerializer::serialize<BroadcastSubscriptionRequest>(payload)); return msg; }
MessagingTest() : settingsFileName("MessagingTest.settings"), settings(settingsFileName), messagingSettings(settings), senderId("senderParticipantId"), senderChannelId("senderChannelId"), receiverId("receiverParticipantId"), receiverChannelId("receiverChannelId"), request(), requestId("requestId"), qos(), inProcessMessagingSkeleton(new MockInProcessMessagingSkeleton()), semaphore(0), messageFactory(), mockMessageReceiver(new MockMessageReceiver()), mockMessageSender(new MockMessageSender()), messagingStubFactory(new MessagingStubFactory()), messageRouter(new MessageRouter(messagingStubFactory, nullptr)) { // provision global capabilities directory std::shared_ptr<joynr::system::RoutingTypes::Address> addressCapabilitiesDirectory( new system::RoutingTypes::ChannelAddress( messagingSettings.getCapabilitiesDirectoryChannelId()) ); messageRouter->addProvisionedNextHop(messagingSettings.getCapabilitiesDirectoryParticipantId(), addressCapabilitiesDirectory); // provision channel url directory std::shared_ptr<joynr::system::RoutingTypes::Address> addressChannelUrlDirectory( new system::RoutingTypes::ChannelAddress( messagingSettings.getChannelUrlDirectoryChannelId()) ); messageRouter->addProvisionedNextHop(messagingSettings.getChannelUrlDirectoryParticipantId(), addressChannelUrlDirectory); messagingStubFactory->registerStubFactory(new JoynrMessagingStubFactory(mockMessageSender, senderChannelId)); messagingStubFactory->registerStubFactory(new InProcessMessagingStubFactory()); qos.setTtl(10000); }
TEST_F(MessageNotificationTest, messageToDisconnectedProviderCausesBroadcast) { // 1. register provider auto testProvider = std::make_shared<tests::DefaulttestProvider>(); joynr::types::ProviderQos providerQos; providerQos.setScope(joynr::types::ProviderScope::LOCAL); std::string providerParticipantId = libjoynrProviderRuntime->registerProvider<tests::testProvider>( testDomain, testProvider, providerQos); // 2. create proxy DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::LAST_SEEN); discoveryQos.setDiscoveryScope(joynr::types::DiscoveryScope::LOCAL_ONLY); MessagingQos messagingQos; messagingQos.setTtl(5000); auto testProxyBuilder = libjoynrProxyRuntime->createProxyBuilder<tests::testProxy>(testDomain); auto testProxy = testProxyBuilder->setMessagingQos(messagingQos)->setDiscoveryQos(discoveryQos)->build(); Settings settings(settingsPath); SystemServicesSettings systemSettings(settings); auto messageNotificationProxyBuilder = libjoynrProxyRuntime->createProxyBuilder<joynr::system::MessageNotificationProxy>( systemSettings.getDomain()); DiscoveryQos messagingNotificationDiscoveryQos; messagingNotificationDiscoveryQos.setArbitrationStrategy( DiscoveryQos::ArbitrationStrategy::FIXED_PARTICIPANT); messagingNotificationDiscoveryQos.addCustomParameter( "fixedParticipantId", systemSettings.getCcMessageNotificationProviderParticipantId()); messagingNotificationDiscoveryQos.setDiscoveryScope(joynr::types::DiscoveryScope::LOCAL_ONLY); auto messageNotificationProxy = messageNotificationProxyBuilder->setMessagingQos(messagingQos) ->setDiscoveryQos(messagingNotificationDiscoveryQos) ->build(); // 3. subscribe to message notification broadcast auto mockListener = std::make_shared<MockSubscriptionListener>(); EXPECT_CALL(*mockListener, onSubscribed(_)).Times(1); EXPECT_CALL(*mockListener, onError(_)).Times(0); joynr::system::MessageNotificationMessageQueuedForDeliveryBroadcastFilterParameters filterParameters; filterParameters.setParticipantId(providerParticipantId); auto future = messageNotificationProxy->subscribeToMessageQueuedForDeliveryBroadcast( filterParameters, mockListener, std::make_shared<OnChangeSubscriptionQos>()); std::string subscriptionId; future->get(subscriptionId); // 4. disconnect provider runtime libjoynrProviderRuntime->shutdown(); libjoynrProviderRuntime.reset(); // 5. execute call on proxy while provider is not connected to cluster-controller auto onSuccess = [](const std::int32_t&) { FAIL(); }; auto onError = [](const joynr::exceptions::JoynrRuntimeException&) {}; EXPECT_CALL(*mockListener, onReceive(Eq(providerParticipantId), _)) .WillOnce(ReleaseSemaphore(&semaphore)); testProxy->addNumbersAsync(1, 2, 3, onSuccess, onError); // 6. wait for a broadcast message to arrive ASSERT_TRUE(semaphore.waitFor(std::chrono::seconds(3))); messageNotificationProxy->unsubscribeFromMessageQueuedForDeliveryBroadcast(subscriptionId); }