use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerTest method persistedSubscriptionRequestsAreQueued.
@SuppressWarnings("unchecked")
@Test(timeout = 3000000)
public void persistedSubscriptionRequestsAreQueued() throws Exception {
String persistenceFileName = "target/" + PublicationManagerTest.class.getCanonicalName() + ".test_persistenceSubscriptionRequests";
String providerParticipantId = "providerParticipantId";
String proxyParticipantId = "proxyParticipantId";
int period = 200;
int times = 5;
int validityMs = (period * times) + period;
long publicationTtl = validityMs;
SubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
SubscriptionRequest subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
new File(persistenceFileName).delete();
// pre-fill the persistence file
FileSubscriptionRequestStorage fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
assertEquals(0, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
// no providers are currently registered
ProviderDirectory myProviderDirectory = new ProviderDirectory();
publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
publicationManager.addSubscriptionRequest(proxyParticipantId, providerParticipantId, subscriptionRequest);
assertEquals(1, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
publicationManager.shutdown();
// open the persistence file that should now contain one element
fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
assertEquals(1, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
// when the provider is registered, persisted subscription requests should be activated
myProviderDirectory.add(providerParticipantId, providerContainer);
verify(dispatcher, timeout(validityMs).atLeast(times)).sendSubscriptionPublication(any(String.class), any(Set.class), any(SubscriptionPublication.class), any(MessagingQos.class));
;
Thread.sleep(validityMs + 1000);
publicationManager.shutdown();
// Start again with the same file, that should now be empty as all persisted subscriptions were already queued
reset(dispatcher);
fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, myProviderDirectory, cleanupScheduler, fileSubscriptionRequestStorage, shutdownNotifier);
verifyNoMoreInteractions(dispatcher);
fileSubscriptionRequestStorage = new FileSubscriptionRequestStorage(persistenceFileName);
assertEquals(0, fileSubscriptionRequestStorage.getSavedSubscriptionRequests().size());
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerTest method modifySubscriptionTypeForExistingSubscription.
@SuppressWarnings("unchecked")
@Test(timeout = 3000)
public void modifySubscriptionTypeForExistingSubscription() throws Exception {
publicationManager = new PublicationManagerImpl(attributePollInterpreter, dispatcher, providerDirectory, cleanupScheduler, Mockito.mock(SubscriptionRequestStorage.class), shutdownNotifier);
int period = 200;
int testLengthMax = 3000;
long validityMs = testLengthMax;
long publicationTtl = testLengthMax;
SubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
SubscriptionRequest subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
verify(dispatcher, timeout(period * 5).times(6)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
qos = new OnChangeSubscriptionQos().setMinIntervalMs(0).setValidityMs(validityMs).setPublicationTtlMs(publicationTtl);
subscriptionRequest = new SubscriptionRequest(SUBSCRIPTION_ID, "location", qos);
when(providerDirectory.get(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(providerContainer);
when(providerDirectory.contains(eq(PROVIDER_PARTICIPANT_ID))).thenReturn(true);
publicationManager.addSubscriptionRequest(PROXY_PARTICIPANT_ID, PROVIDER_PARTICIPANT_ID, subscriptionRequest);
reset(dispatcher);
publicationManager.attributeValueChanged(SUBSCRIPTION_ID, valueToPublish);
verify(dispatcher, timeout(testLengthMax).times(1)).sendSubscriptionPublication(eq(PROVIDER_PARTICIPANT_ID), (Set<String>) argThat(contains(PROXY_PARTICIPANT_ID)), any(SubscriptionPublication.class), any(MessagingQos.class));
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class SubscriptionQosTest method createOnChangeSubscriptionQosWithValidity.
@Test
public void createOnChangeSubscriptionQosWithValidity() throws Exception {
long validityMs = 100000;
long lowerBound = System.currentTimeMillis() + validityMs;
SubscriptionQos onChangeSubscriptionQos = new OnChangeSubscriptionQos().setValidityMs(validityMs);
long upperBound = System.currentTimeMillis() + validityMs;
assertTrue(onChangeSubscriptionQos.getExpiryDateMs() >= lowerBound);
assertTrue(onChangeSubscriptionQos.getExpiryDateMs() <= upperBound);
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerImpl method handleSubscriptionRequest.
private void handleSubscriptionRequest(PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest, ProviderContainer providerContainer) {
final String subscriptionId = subscriptionRequest.getSubscriptionId();
SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
MessagingQos messagingQos = createMessagingQos(subscriptionQos);
try {
Method method = findGetterForAttributeName(providerContainer.getProviderProxy().getClass(), subscriptionRequest.getSubscribedToName());
triggerPublication(publicationInformation, providerContainer, method);
boolean hasSubscriptionHeartBeat = subscriptionQos instanceof HeartbeatSubscriptionInformation;
boolean isOnChangeSubscription = subscriptionQos instanceof OnChangeSubscriptionQos;
if (hasSubscriptionHeartBeat || isOnChangeSubscription) {
// TODO: send error subscription reply is periodMs < MIN_PERIOD_MS or periodMs > MAX_PERIOD_MS?
final PublicationTimer timer = new PublicationTimer(publicationInformation, method, providerContainer, this, attributePollInterpreter);
timer.startTimer();
publicationTimers.put(subscriptionId, timer);
}
if (subscriptionQos instanceof OnChangeSubscriptionQos) {
handleOnChangeSubscription(subscriptionRequest, providerContainer, subscriptionId);
}
dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, new SubscriptionReply(subscriptionId), messagingQos);
} catch (NoSuchMethodException e) {
cancelPublicationCreation(subscriptionId);
logger.error("Error subscribing: {}. The provider does not have the requested attribute", subscriptionRequest);
sendSubscriptionReplyWithError(publicationInformation, subscriptionId, e, messagingQos);
}
}
use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.
the class PublicationManagerImpl method sendSubscriptionReplyWithError.
private void sendSubscriptionReplyWithError(SubscriptionException e, PublicationInformation publicationInformation, SubscriptionRequest subscriptionRequest) {
SubscriptionQos subscriptionQos = subscriptionRequest.getQos();
MessagingQos messagingQos = new MessagingQos();
if (subscriptionQos.getExpiryDateMs() == SubscriptionQos.NO_EXPIRY_DATE) {
messagingQos.setTtl_ms(SubscriptionQos.INFINITE_SUBSCRIPTION);
} else {
// TTL uplift will be done in JoynrMessageFactory
messagingQos.setTtl_ms(subscriptionQos.getExpiryDateMs() - System.currentTimeMillis());
}
SubscriptionReply subscriptionReply = new SubscriptionReply(publicationInformation.getSubscriptionId(), e);
dispatcher.sendSubscriptionReply(publicationInformation.providerParticipantId, publicationInformation.proxyParticipantId, subscriptionReply, messagingQos);
}
Aggregations