use of io.joynr.proxy.invocation.AttributeSubscribeInvocation in project joynr by bmwcarit.
the class SubscriptionManagerTest method registerSubscription.
@SuppressWarnings("unchecked")
@Test
public void registerSubscription() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
class IntegerReference extends TypeReference<Integer> {
}
Future<String> future = mock(Future.class);
AttributeSubscribeInvocation subscriptionRequest = new AttributeSubscribeInvocation(attributeName, IntegerReference.class, attributeSubscriptionCallback, qos, future);
subscriptionManager.registerAttributeSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
subscriptionId = subscriptionRequest.getSubscriptionId();
verify(attributeSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(attributeSubscriptionCallback));
verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
verify(cleanupScheduler).schedule(Mockito.any(Runnable.class), Mockito.eq(qos.getExpiryDateMs()), Mockito.eq(TimeUnit.MILLISECONDS));
verify(subscriptionEndFutures, Mockito.times(1)).put(Mockito.eq(subscriptionId), Mockito.any(ScheduledFuture.class));
verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
use of io.joynr.proxy.invocation.AttributeSubscribeInvocation in project joynr by bmwcarit.
the class SubscriptionTimersTest method noMissedPublicationWarningWhenPublicationIsReceived.
@Test(timeout = 3000)
public void noMissedPublicationWarningWhenPublicationIsReceived() throws InterruptedException, JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
LOG.debug("Starting noMissedPublicationWarningWhenPublicationIsReceived test");
// there should be at least one successful publication, so (numberOfPublications-1)
int numberOfMissedPublications = (int) (Math.random() * (numberOfPublications - 1));
// int numberOfMissedPublications = 5;
int numberOfSuccessfulPublications = numberOfPublications - numberOfMissedPublications;
long validityMs = // usual length of the subscription
period * numberOfPublications + // plus time for the last possible alertAfterInterval to arrive
(alertAfterInterval - period);
PeriodicSubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(validityMs).setAlertAfterIntervalMs(alertAfterInterval).setPublicationTtlMs(1000);
// register a subscription
AttributeSubscribeInvocation subscriptionRequest = new AttributeSubscribeInvocation(attributeName, IntegerReference.class, attributeSubscriptionCallback, qos, future);
subscriptionManager.registerAttributeSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
subscriptionId = subscriptionRequest.getSubscriptionId();
boolean lastPublicationIsMissedPublication = false;
int missedPublicationsCounter = 0;
int successfulPublicationsCounter = 0;
for (int i = 0; i < numberOfPublications; i++) {
// choose randomly whether the current publication is successful or missed
if ((Math.random() < 0.5 && successfulPublicationsCounter < numberOfSuccessfulPublications) || missedPublicationsCounter == numberOfMissedPublications) {
Thread.sleep(period);
// publication successfully received
subscriptionManager.touchSubscriptionState(subscriptionId);
successfulPublicationsCounter++;
LOG.trace("\nSUCCESSFUL publication");
} else {
Thread.sleep(period);
// publication missed
missedPublicationsCounter++;
// before execution
if (i == numberOfPublications - 1) {
lastPublicationIsMissedPublication = true;
}
LOG.trace("\nMISSED publication");
}
}
LOG.trace("No more calls are expected now.");
// wait some additional time to see whether there are unwanted publications
Thread.sleep(2 * period);
int missedPublicationAlerts = (lastPublicationIsMissedPublication) ? missedPublicationsCounter - 1 : missedPublicationsCounter;
verify(attributeSubscriptionCallback, atLeast(missedPublicationAlerts)).onError(new PublicationMissedException(subscriptionId));
verify(attributeSubscriptionCallback, atMost(missedPublicationsCounter)).onError(new PublicationMissedException(subscriptionId));
// verify callback is not called
verifyNoMoreInteractions(attributeSubscriptionCallback);
LOG.trace("finishing test.");
}
use of io.joynr.proxy.invocation.AttributeSubscribeInvocation in project joynr by bmwcarit.
the class SubscriptionTimersTest method missedPublicationRunnableIsStopped.
@Test(timeout = 3000)
public void missedPublicationRunnableIsStopped() throws InterruptedException, JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
LOG.debug("Starting missedPublicationRunnableIsStopped test");
PeriodicSubscriptionQos qos = new PeriodicSubscriptionQos().setPeriodMs(period).setValidityMs(subscriptionLength).setAlertAfterIntervalMs(alertAfterInterval).setPublicationTtlMs(1000);
// register a subscription
AttributeSubscribeInvocation subscriptionRequest = new AttributeSubscribeInvocation(attributeName, IntegerReference.class, attributeSubscriptionCallback, qos, future);
subscriptionManager.registerAttributeSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
subscriptionId = subscriptionRequest.getSubscriptionId();
Thread.sleep(subscriptionLength);
verify(attributeSubscriptionCallback, times(numberOfPublications)).onError(new PublicationMissedException(subscriptionId));
// wait some additional time to see whether there are unwanted publications
Thread.sleep(2 * period);
// verify callback is not called
verifyNoMoreInteractions(attributeSubscriptionCallback);
}
use of io.joynr.proxy.invocation.AttributeSubscribeInvocation in project joynr by bmwcarit.
the class ConnectorTest method subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments.
@Test
public void subscribeToAttributeCallCallsSubscriptionManagerWithCorrectArguments() {
AttributeSubscriptionListener<String> listener = new AttributeSubscriptionAdapter<>();
SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
ConnectorInvocationHandler connector = createConnector();
assertNotNull(connector);
try {
Method method = TestSubscriptionInterface.class.getDeclaredMethod("subscribeToTestAttribute", AttributeSubscriptionListener.class, SubscriptionQos.class);
AttributeSubscribeInvocation invocation = new AttributeSubscribeInvocation(method, new Object[] { listener, subscriptionQos }, null);
connector.executeSubscriptionMethod(invocation);
verify(subscriptionManager, times(1)).registerAttributeSubscription(fromParticipantId, toDiscoveryEntries, invocation);
} catch (Exception e) {
fail("Unexpected exception from attribute subscribe call: " + e);
}
}
use of io.joynr.proxy.invocation.AttributeSubscribeInvocation in project joynr by bmwcarit.
the class ProxyTest method createProxySubscribeAndUnsubscribeFromAttribute.
@Test
public void createProxySubscribeAndUnsubscribeFromAttribute() throws Exception {
NavigationProxy proxy = getNavigationProxy();
long minInterval_ms = 0;
long expiryDate = System.currentTimeMillis() + 30000;
long publicationTtl_ms = 5000;
SubscriptionQos subscriptionQos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(expiryDate).setPublicationTtlMs(publicationTtl_ms);
abstract class BooleanSubscriptionListener implements AttributeSubscriptionListener<Boolean> {
}
Future<String> subscriptionId = proxy.subscribeToGuidanceActive(mock(BooleanSubscriptionListener.class), subscriptionQos);
ArgumentCaptor<AttributeSubscribeInvocation> subscriptionRequest = ArgumentCaptor.forClass(AttributeSubscribeInvocation.class);
verify(subscriptionManager, times(1)).registerAttributeSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), subscriptionRequest.capture());
assertEquals("guidanceActive", subscriptionRequest.getValue().getAttributeName());
assertEquals(subscriptionId.get(), subscriptionRequest.getValue().getSubscriptionId());
// now, let's remove the previous subscriptionRequest
proxy.unsubscribeFromGuidanceActive(subscriptionId.get());
verify(subscriptionManager, times(1)).unregisterSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(subscriptionId.get()), any(MessagingQos.class));
}
Aggregations