Search in sources :

Example 6 with AttributeSubscribeInvocation

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));
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Matchers.anyString(org.mockito.Matchers.anyString) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Example 7 with AttributeSubscribeInvocation

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.");
}
Also used : PublicationMissedException(joynr.exceptions.PublicationMissedException) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 8 with AttributeSubscribeInvocation

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);
}
Also used : PublicationMissedException(joynr.exceptions.PublicationMissedException) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Example 9 with AttributeSubscribeInvocation

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);
    }
}
Also used : AttributeSubscriptionAdapter(io.joynr.pubsub.subscription.AttributeSubscriptionAdapter) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) Method(java.lang.reflect.Method) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 10 with AttributeSubscribeInvocation

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));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) NavigationProxy(joynr.vehicle.NavigationProxy) Matchers.anyString(org.mockito.Matchers.anyString) AttributeSubscribeInvocation(io.joynr.proxy.invocation.AttributeSubscribeInvocation) AttributeSubscriptionListener(io.joynr.pubsub.subscription.AttributeSubscriptionListener) Test(org.junit.Test)

Aggregations

AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)10 Test (org.junit.Test)8 MessagingQos (io.joynr.messaging.MessagingQos)4 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)3 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)3 NavigationProxy (joynr.vehicle.NavigationProxy)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2 AttributeSubscriptionListener (io.joynr.pubsub.subscription.AttributeSubscriptionListener)2 Method (java.lang.reflect.Method)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)2 SubscriptionRequest (joynr.SubscriptionRequest)2 PublicationMissedException (joynr.exceptions.PublicationMissedException)2 AbstractModule (com.google.inject.AbstractModule)1