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.");
}
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);
}
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");
}
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));
}
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");
}
Aggregations