Search in sources :

Example 11 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos 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 12 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos 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 13 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method registerSubscriptionAndReceiveUpdates.

@Test
@Ignore
@SuppressWarnings("unchecked")
public void registerSubscriptionAndReceiveUpdates() throws InterruptedException, ApplicationException {
    AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
    int subscriptionDuration = (PERIOD_MS * 4);
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(500);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToTestAttribute(integerListener, subscriptionQos);
    Thread.sleep(subscriptionDuration);
    verify(integerListener, times(0)).onError(null);
    // TODO verify publications shipped correct data
    verify(integerListener, times(1)).onReceive(eq(42));
    verify(integerListener, times(1)).onReceive(eq(43));
    verify(integerListener, times(1)).onReceive(eq(44));
    verify(integerListener, times(1)).onReceive(eq(45));
    proxy.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method subscribeToByteBufferAttribute.

@SuppressWarnings("unchecked")
@Test
public void subscribeToByteBufferAttribute() throws InterruptedException, ApplicationException {
    final Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<Byte[]> testByteBufferListener = mock(AttributeSubscriptionListener.class);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            onReceiveSemaphore.release();
            return null;
        }
    }).when(testByteBufferListener).onReceive(any(Byte[].class));
    Byte[] expectedByteBuffer = { 1, 2, 3 };
    provider.setByteBufferAttribute(expectedByteBuffer);
    int periods = 2;
    long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(500);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToByteBufferAttribute(testByteBufferListener, subscriptionQos);
    assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
    verify(testByteBufferListener, times(0)).onError(null);
    proxy.unsubscribeFromByteBufferAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
Also used : Semaphore(java.util.concurrent.Semaphore) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 15 with PeriodicSubscriptionQos

use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method registerAndStopSubscription.

@SuppressWarnings("unchecked")
@Test
public void registerAndStopSubscription() throws InterruptedException, ApplicationException {
    AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
    int subscriptionDuration = (PERIOD_MS * 2);
    PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
    subscriptionQos.setPeriodMs(PERIOD_MS);
    subscriptionQos.setValidityMs(subscriptionDuration);
    subscriptionQos.setAlertAfterIntervalMs(0);
    subscriptionQos.setPublicationTtlMs(0);
    Future<String> subscriptionId = proxy.subscribeToTestAttribute(integerListener, subscriptionQos);
    Thread.sleep(subscriptionDuration);
    verify(integerListener, times(0)).onError(null);
    verify(integerListener, atLeast(2)).onReceive(anyInt());
    reset(integerListener);
    Thread.sleep(subscriptionDuration);
    verifyNoMoreInteractions(integerListener);
    proxy.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) Test(org.junit.Test)

Aggregations

PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)23 Test (org.junit.Test)20 MessagingQos (io.joynr.messaging.MessagingQos)10 SubscriptionPublication (joynr.SubscriptionPublication)8 SubscriptionRequest (joynr.SubscriptionRequest)8 Matchers.anyString (org.mockito.Matchers.anyString)7 Semaphore (java.util.concurrent.Semaphore)6 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)6 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)5 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)3 Ignore (org.junit.Ignore)3 ProviderDirectory (io.joynr.dispatching.ProviderDirectory)2 JoynrIllegalStateException (io.joynr.exceptions.JoynrIllegalStateException)2 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)2 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2 Method (java.lang.reflect.Method)2 ProviderRuntimeException (joynr.exceptions.ProviderRuntimeException)2 PublicationMissedException (joynr.exceptions.PublicationMissedException)2