Search in sources :

Example 1 with PublicationMissedException

use of joynr.exceptions.PublicationMissedException 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 2 with PublicationMissedException

use of joynr.exceptions.PublicationMissedException 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)

Aggregations

AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)2 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)2 PublicationMissedException (joynr.exceptions.PublicationMissedException)2 Test (org.junit.Test)2