void DbusCapabilitiesUtil::copyDbusDiscoveryQosToJoynr(const joynr::messaging::types::Types::DiscoveryQos& dbusDiscoveryQos, DiscoveryQos& joynrDiscoveryQos) { // copy arbitration strategy switch (dbusDiscoveryQos.arbitrationStrategy) { case joynr::messaging::types::Types::ArbitrationStrategy::FIXED_CHANNEL: joynrDiscoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::FIXED_PARTICIPANT); break; case joynr::messaging::types::Types::ArbitrationStrategy::HIGHEST_PRIORITY: joynrDiscoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); break; case joynr::messaging::types::Types::ArbitrationStrategy::KEYWORD: joynrDiscoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::KEYWORD); break; case joynr::messaging::types::Types::ArbitrationStrategy::LOCAL_ONLY: joynrDiscoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::LOCAL_ONLY); break; case joynr::messaging::types::Types::ArbitrationStrategy::NOT_SET: joynrDiscoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::NOT_SET); break; default: assert(false); } switch(dbusDiscoveryQos.discoveryScope) { case joynr::messaging::types::Types::DiscoveryScope::GLOBAL_ONLY: joynrDiscoveryQos.setDiscoveryScope(DiscoveryQos::DiscoveryScope::GLOBAL_ONLY); break; case joynr::messaging::types::Types::DiscoveryScope::LOCAL_ONLY: joynrDiscoveryQos.setDiscoveryScope(DiscoveryQos::DiscoveryScope::LOCAL_ONLY); break; case joynr::messaging::types::Types::DiscoveryScope::LOCAL_THEN_GLOBAL: joynrDiscoveryQos.setDiscoveryScope(DiscoveryQos::DiscoveryScope::LOCAL_THEN_GLOBAL); break; case joynr::messaging::types::Types::DiscoveryScope::LOCAL_AND_GLOBAL: joynrDiscoveryQos.setDiscoveryScope(DiscoveryQos::DiscoveryScope::LOCAL_AND_GLOBAL); break; default: assert(false); } joynrDiscoveryQos.setCacheMaxAge(dbusDiscoveryQos.cacheMaxAge); joynrDiscoveryQos.setDiscoveryTimeout(dbusDiscoveryQos.discoveryTimeout); joynrDiscoveryQos.setProviderMustSupportOnChange(dbusDiscoveryQos.providerMustSupportOnChange); joynrDiscoveryQos.setRetryInterval(dbusDiscoveryQos.retryInterval); // copy the custom parameters auto parameterMap = dbusDiscoveryQos.customParameters; for(auto it = parameterMap.begin(); it != parameterMap.end(); it++) { joynr::messaging::types::Types::CustomParameter parameter = it->second; // initialize the joynr parameter joynrDiscoveryQos.addCustomParameter(QString::fromStdString(parameter.name), QString::fromStdString(parameter.value)); } }
void testOneShotAttributeSubscription(const T& expectedValue, SubscribeTo subscribeTo, ChangeAttribute setAttribute, const std::string& attributeName) { MockSubscriptionListenerOneType<T>* mockListener = new MockSubscriptionListenerOneType<T>(); // Use a semaphore to count and wait on calls to the mock listener ON_CALL(*mockListener, onReceive(Eq(expectedValue))) .WillByDefault(ReleaseSemaphore(&semaphore)); std::shared_ptr<ISubscriptionListener<T>> subscriptionListener( mockListener); std::shared_ptr<tests::DefaulttestProvider> testProvider(new tests::DefaulttestProvider()); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. std::this_thread::sleep_for(std::chrono::milliseconds(registerProviderWait)); (*testProvider.*setAttribute)(expectedValue, [](){}, [](const joynr::exceptions::ProviderRuntimeException&) {}); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); std::int64_t qosRoundTripTTL = 500; // Send a message and expect to get a result tests::testProxy* testProxy = testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build(); std::int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms subscribeTo(testProxy, subscriptionListener, subscriptionQos); waitForAttributeSubscriptionArrivedAtProvider(testProvider, attributeName); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.waitFor(std::chrono::seconds(3))); delete testProxyBuilder; delete testProxy; }
TEST_F(End2EndBroadcastTest, subscribeToBroadcastWithEnumOutput) { tests::testTypes::TestEnum::Enum expectedTestEnum = tests::testTypes::TestEnum::TWO; MockSubscriptionListenerOneType<tests::testTypes::TestEnum::Enum>* mockListener = new MockSubscriptionListenerOneType<tests::testTypes::TestEnum::Enum>(); // Use a semaphore to count and wait on calls to the mock listener ON_CALL(*mockListener, onReceive(Eq(expectedTestEnum))) .WillByDefault(ReleaseSemaphore(&semaphore)); std::shared_ptr<ISubscriptionListener<tests::testTypes::TestEnum::Enum>> subscriptionListener( mockListener); std::shared_ptr<MyTestProvider> testProvider(new MyTestProvider()); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. QThreadSleep::msleep(registerProviderWait); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); qlonglong qosRoundTripTTL = 500; // Send a message and expect to get a result tests::testProxy* testProxy = testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build(); int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms testProxy->subscribeToBroadcastWithEnumOutputBroadcast(subscriptionListener, subscriptionQos); waitForBroadcastSubscriptionArrivedAtProvider(testProvider, "broadcastWithEnumOutput"); testProvider->fireBroadcastWithEnumOutput(expectedTestEnum); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.tryAcquire(1, 3000)); delete testProxyBuilder; delete testProxy; }
TEST_F(End2EndBroadcastTest, subscribeToBroadcastWithSameNameAsAttribute) { MockGpsSubscriptionListener* mockListenerAttribute = new MockGpsSubscriptionListener(); MockGpsSubscriptionListener* mockListenerBroadcast = new MockGpsSubscriptionListener(); // Use a semaphore to count and wait on calls to the mock listener // Expect initial attribute publication with default value EXPECT_CALL(*mockListenerAttribute, onReceive(Eq(gpsLocation))). WillRepeatedly(ReleaseSemaphore(&semaphore)); EXPECT_CALL(*mockListenerAttribute, onReceive(Eq(gpsLocation2))). WillRepeatedly(ReleaseSemaphore(&semaphore)); EXPECT_CALL(*mockListenerBroadcast, onReceive(Eq(gpsLocation3))). WillRepeatedly(ReleaseSemaphore(&semaphore)); std::shared_ptr<ISubscriptionListener<types::Localisation::GpsLocation> > subscriptionListenerAttribute( mockListenerAttribute); std::shared_ptr<ISubscriptionListener<types::Localisation::GpsLocation> > subscriptionListenerBroadcast( mockListenerBroadcast); std::shared_ptr<MyTestProvider> testProvider(new MyTestProvider()); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. QThreadSleep::msleep(registerProviderWait); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); qlonglong qosRoundTripTTL = 500; // Send a message and expect to get a result QSharedPointer<tests::testProxy> testProxy(testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build()); int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms testProxy->subscribeToLocation( subscriptionListenerAttribute, subscriptionQos); testProxy->subscribeToLocationBroadcast( subscriptionListenerBroadcast, subscriptionQos); waitForAttributeSubscriptionArrivedAtProvider(testProvider, "location"); waitForBroadcastSubscriptionArrivedAtProvider(testProvider, "location"); // Initial attribute publication ASSERT_TRUE(semaphore.tryAcquire(1, 500)); QThreadSleep::msleep(minInterval_ms); //ensure to wait for the minInterval_ms before changing location // Change attribute testProvider->locationChanged(gpsLocation2); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.tryAcquire(1, 500)); // Emit broadcast testProvider->fireLocation(gpsLocation3); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.tryAcquire(1, 500)); delete testProxyBuilder; }
TEST_F(End2EndBroadcastTest, subscribeToSelectiveBroadcast_FilterFail) { MockGpsSubscriptionListener* mockListener = new MockGpsSubscriptionListener(); // Use a semaphore to count and wait on calls to the mock listener EXPECT_CALL(*mockListener, onReceive(A<const types::Localisation::GpsLocation&>())). WillRepeatedly(ReleaseSemaphore(&semaphore)); std::shared_ptr<ISubscriptionListener<types::Localisation::GpsLocation> > subscriptionListener( mockListener); ON_CALL(*filter, filter(_, Eq(filterParameters))).WillByDefault(Return(false)); std::shared_ptr<MyTestProvider> testProvider(new MyTestProvider()); testProvider->addBroadcastFilter(filter); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. QThreadSleep::msleep(registerProviderWait); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); qlonglong qosRoundTripTTL = 500; // Send a message and expect to get a result QSharedPointer<tests::testProxy> testProxy(testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build()); int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms testProxy->subscribeToLocationUpdateSelectiveBroadcast( filterParameters, subscriptionListener, subscriptionQos); waitForBroadcastSubscriptionArrivedAtProvider(testProvider, "locationUpdateSelective"); // Change the location 3 times testProvider->fireLocationUpdate(gpsLocation2); // Wait for a subscription message to arrive ASSERT_FALSE(semaphore.tryAcquire(1, 500)); // Waiting between broadcast occurences for at least the minInterval is neccessary because // otherwise the publications could be omitted. QThreadSleep::msleep(minInterval_ms); testProvider->fireLocationUpdateSelective(gpsLocation3); // Wait for a subscription message to arrive ASSERT_FALSE(semaphore.tryAcquire(1, 500)); // Waiting between broadcast occurences for at least the minInterval is neccessary because // otherwise the publications could be omitted. QThreadSleep::msleep(minInterval_ms); testProvider->fireLocationUpdateSelective(gpsLocation4); // Wait for a subscription message to arrive ASSERT_FALSE(semaphore.tryAcquire(1, 500)); delete testProxyBuilder; }
TEST_F(End2EndBroadcastTest, subscribeAndUnsubscribeFromBroadcast_OneOutput) { MockGpsSubscriptionListener* mockListener = new MockGpsSubscriptionListener(); // Use a semaphore to count and wait on calls to the mock listener EXPECT_CALL(*mockListener, onReceive(Eq(gpsLocation2))) .WillOnce(ReleaseSemaphore(&semaphore)); EXPECT_CALL(*mockListener, onReceive(Eq(gpsLocation3))) .Times(0); std::shared_ptr<ISubscriptionListener<types::Localisation::GpsLocation> > subscriptionListener( mockListener); std::shared_ptr<MyTestProvider> testProvider(new MyTestProvider()); runtime1->registerProvider<tests::testProvider>(domainName, testProvider); //This wait is necessary, because registerProvider is async, and a lookup could occur // before the register has finished. QThreadSleep::msleep(registerProviderWait); ProxyBuilder<tests::testProxy>* testProxyBuilder = runtime2->createProxyBuilder<tests::testProxy>(domainName); DiscoveryQos discoveryQos; discoveryQos.setArbitrationStrategy(DiscoveryQos::ArbitrationStrategy::HIGHEST_PRIORITY); discoveryQos.setDiscoveryTimeout(1000); discoveryQos.setRetryInterval(250); qlonglong qosRoundTripTTL = 500; // Send a message and expect to get a result QSharedPointer<tests::testProxy> testProxy(testProxyBuilder ->setMessagingQos(MessagingQos(qosRoundTripTTL)) ->setCached(false) ->setDiscoveryQos(discoveryQos) ->build()); int64_t minInterval_ms = 50; OnChangeSubscriptionQos subscriptionQos( 500000, // validity_ms minInterval_ms); // minInterval_ms std::string subscriptionId = testProxy->subscribeToLocationUpdateBroadcast(subscriptionListener, subscriptionQos); // This wait is necessary, because subcriptions are async, and a broadcast could occur // before the subscription has started. QThreadSleep::msleep(subscribeToBroadcastWait); testProvider->fireLocationUpdate(gpsLocation2); // Wait for a subscription message to arrive ASSERT_TRUE(semaphore.tryAcquire(1, 3000)); // Waiting between broadcast occurences for at least the minInterval is neccessary because // otherwise the publications could be omitted. QThreadSleep::msleep(minInterval_ms); testProxy->unsubscribeFromLocationUpdateBroadcast(subscriptionId); testProvider->fireLocationUpdate(gpsLocation3); // Wait for a subscription message to arrive ASSERT_FALSE(semaphore.tryAcquire(1, 2000)); }