/** * Trigger: The dispatcher receives a SubscriptionRequest. * Expected: The PublicationManager creates a PublisherRunnable and polls * the MockCaller for the attribute. */ TEST_F(SubscriptionTest, receive_subscriptionRequestAndPollAttribute) { qRegisterMetaType<OnChangeWithKeepAliveSubscriptionQos>("OnChangeWithKeepAliveSubscriptionQos"); qRegisterMetaType<SubscriptionRequest>("SubscriptionRequest"); // Use a semaphore to count and wait on calls to the mockRequestCaller QSemaphore semaphore(0); EXPECT_CALL(*mockRequestCaller, getLocation(_, _)) .WillRepeatedly(ReleaseSemaphore(&semaphore)); QString attributeName = "Location"; auto subscriptionQos = QSharedPointer<SubscriptionQos>(new OnChangeWithKeepAliveSubscriptionQos( 80, // validity_ms 100, // minInterval_ms 200, // maxInterval_ms 80 // alertInterval_ms )); QString subscriptionId = "SubscriptionID"; SubscriptionRequest subscriptionRequest; subscriptionRequest.setSubscriptionId(subscriptionId); subscriptionRequest.setAttributeName(attributeName); subscriptionRequest.setQos(subscriptionQos); JoynrMessage msg = messageFactory.createSubscriptionRequest( proxyParticipantId, providerParticipantId, qos, subscriptionRequest); dispatcher.addRequestCaller(providerParticipantId, mockRequestCaller); dispatcher.receive(msg, qos); // Wait for a call to be made to the mockRequestCaller ASSERT_TRUE(semaphore.tryAcquire(1,1000)); }
TEST_F(JoynrMessageFactoryTest, createSubscriptionRequest){ auto subscriptionQos = QSharedPointer<SubscriptionQos>(new OnChangeSubscriptionQos()); SubscriptionRequest subscriptionRequest; subscriptionRequest.setSubscriptionId(QString("subscriptionId")); subscriptionRequest.setAttributeName(QString("attributeName")); subscriptionRequest.setQos(subscriptionQos); JoynrMessage joynrMessage = messageFactory.createSubscriptionRequest( senderID, receiverID, qos, subscriptionRequest ); checkParticipantIDs(joynrMessage); EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST, joynrMessage.getType()); }
/** * Precondition: A provider is registered and there is at least one subscription for it. * Trigger: A subscription stop message is received * Expected: The PublicationManager stops the publications for this provider */ TEST_F(SubscriptionTest, stopMessage_stopsPublications) { qRegisterMetaType<OnChangeWithKeepAliveSubscriptionQos>("OnChangeWithKeepAliveSubscriptionQos"); qRegisterMetaType<SubscriptionRequest>("SubscriptionRequest"); // Use a semaphore to count and wait on calls to the mockRequestCaller QSemaphore semaphore(0); EXPECT_CALL(*mockRequestCaller, getLocation(_, _)) .WillRepeatedly(ReleaseSemaphore(&semaphore)); dispatcher.addRequestCaller(providerParticipantId, mockRequestCaller); QString attributeName = "Location"; auto subscriptionQos = QSharedPointer<SubscriptionQos>(new OnChangeWithKeepAliveSubscriptionQos( 1200, // validity_ms 10, // minInterval_ms 100, // maxInterval_ms 1100 // alertInterval_ms )); QString subscriptionId = "SubscriptionID"; SubscriptionRequest subscriptionRequest; subscriptionRequest.setSubscriptionId(subscriptionId); subscriptionRequest.setAttributeName(attributeName); subscriptionRequest.setQos(subscriptionQos); JoynrMessage msg = messageFactory.createSubscriptionRequest( proxyParticipantId, providerParticipantId, qos, subscriptionRequest); // first received message with subscription request dispatcher.receive(msg, qos); // wait for two requests from the subscription ASSERT_TRUE(semaphore.tryAcquire(2, 1000)); SubscriptionStop subscriptionStop; subscriptionStop.setSubscriptionId(subscriptionRequest.getSubscriptionId()); // receive a subscription stop message msg = messageFactory.createSubscriptionStop( proxyParticipantId, providerParticipantId, qos, subscriptionStop); dispatcher.receive(msg, qos); // assert that less than 2 requests happen in the next 300 milliseconds ASSERT_FALSE(semaphore.tryAcquire(2, 300)); }
/** * Precondition: Dispatcher receives a SubscriptionRequest for a not(yet) existing Provider. * Trigger: The provider is registered. * Expected: The PublicationManager registers the provider and notifies the PublicationManager * to restore waiting Subscriptions */ TEST_F(SubscriptionTest, receive_RestoresSubscription) { qRegisterMetaType<OnChangeWithKeepAliveSubscriptionQos>("OnChangeWithKeepAliveSubscriptionQos"); qRegisterMetaType<SubscriptionRequest>("SubscriptionRequest"); // Use a semaphore to count and wait on calls to the mockRequestCaller QSemaphore semaphore(0); EXPECT_CALL(*mockRequestCaller, getLocation(A<RequestStatus&>(), A<types::GpsLocation&>())) .WillOnce(DoAll( SetArgReferee<1>(gpsLocation1), ReleaseSemaphore(&semaphore)) ); QString attributeName = "Location"; auto subscriptionQos = QSharedPointer<SubscriptionQos>(new OnChangeWithKeepAliveSubscriptionQos( 80, // validity_ms 100, // minInterval_ms 200, // maxInterval_ms 80 // alertInterval_ms )); QString subscriptionId = "SubscriptionID"; SubscriptionRequest subscriptionRequest; subscriptionRequest.setSubscriptionId(subscriptionId); subscriptionRequest.setAttributeName(attributeName); subscriptionRequest.setQos(subscriptionQos); JoynrMessage msg = messageFactory.createSubscriptionRequest( proxyParticipantId, providerParticipantId, qos, subscriptionRequest); // first received message with subscription request dispatcher.receive(msg, qos); dispatcher.addRequestCaller(providerParticipantId, mockRequestCaller); ASSERT_TRUE(semaphore.tryAcquire(1,15000)); //Try to acquire a semaphore for up to 5 seconds. Acquireing the semaphore will only work, if the mockRequestCaller has been called //and will be much faster than waiting for 500ms to make sure it has been called }