use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method registerSubscriptionForListAndReceiveUpdates.
@SuppressWarnings("unchecked")
@Test
public void registerSubscriptionForListAndReceiveUpdates() throws InterruptedException, ApplicationException {
final Semaphore onReceiveSemaphore = new Semaphore(0);
AttributeSubscriptionListener<Integer[]> integersListener = mock(AttributeSubscriptionListener.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) {
onReceiveSemaphore.release();
return null;
}
}).when(integersListener).onReceive(any(Integer[].class));
provider.setTestAttribute(42);
int periods = 2;
long subscriptionDuration = (PERIOD_MS * periods) + EXPECTED_LATENCY_MS;
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(subscriptionDuration);
subscriptionQos.setAlertAfterIntervalMs(0);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxy.subscribeToListOfInts(integersListener, subscriptionQos);
assertTrue(onReceiveSemaphore.tryAcquire(periods, subscriptionDuration + 1000, TimeUnit.MILLISECONDS));
verify(integersListener, times(0)).onError(null);
verify(integersListener, times(1)).onReceive(eq(new Integer[] { 42 }));
verify(integersListener, times(1)).onReceive(eq(new Integer[] { 42, 43 }));
proxy.unsubscribeFromListOfInts(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method testSubscribeToNonExistentDomain.
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "NP_NULL_ON_SOME_PATH_EXCEPTION", justification = "NPE in test would fail test")
@SuppressWarnings("unchecked")
@Ignore
@Test
public void testSubscribeToNonExistentDomain() throws InterruptedException {
AttributeSubscriptionListener<Integer> integerListener = mock(AttributeSubscriptionListener.class);
testProxy proxyToNonexistentDomain = null;
try {
ProxyBuilder<testProxy> proxyBuilder;
String nonExistentDomain = UUID.randomUUID().toString() + "-domaindoesnotexist-end2end";
MessagingQos messagingQos = new MessagingQos(20000);
DiscoveryQos discoveryQos = new DiscoveryQos(50000, ArbitrationStrategy.HighestPriority, Long.MAX_VALUE);
proxyBuilder = consumerRuntime.getProxyBuilder(nonExistentDomain, testProxy.class);
proxyToNonexistentDomain = proxyBuilder.setMessagingQos(messagingQos).setDiscoveryQos(discoveryQos).build();
} catch (DiscoveryException e) {
logger.error(e.getMessage(), e);
} catch (JoynrIllegalStateException e) {
logger.error(e.getMessage(), e);
}
// This should not cause an exception
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(30000);
subscriptionQos.setAlertAfterIntervalMs(0);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxyToNonexistentDomain.subscribeToTestAttribute(integerListener, subscriptionQos);
Thread.sleep(4000);
try {
proxyToNonexistentDomain.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
} catch (JoynrRuntimeException | ApplicationException e) {
assertTrue(e.getMessage(), e != null);
}
getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method subscribeToAttributeWithProviderRuntimeException.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToAttributeWithProviderRuntimeException() throws InterruptedException, ApplicationException {
Semaphore onErrorSemaphore = new Semaphore(0);
ProviderRuntimeException expectedException = new ProviderRuntimeException(SubscriptionTestsProviderImpl.MESSAGE_PROVIDERRUNTIMEEXCEPTION);
AttributeSubscriptionListener<Integer> listener = prepareOnErrorListenerMock(onErrorSemaphore, expectedException);
int periods = 2;
int subscriptionDuration = (PERIOD_MS * periods);
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(subscriptionDuration);
subscriptionQos.setAlertAfterIntervalMs(1000);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxy.subscribeToAttributeWithProviderRuntimeException(listener, subscriptionQos);
long timeBeforeTest = System.currentTimeMillis();
long timeout = subscriptionDuration + EXPECTED_LATENCY_MS;
// expect at least #periods errors
assertTrue(onErrorSemaphore.tryAcquire(periods, timeout, TimeUnit.MILLISECONDS));
// expect at most #periods+1 errors
timeout = Math.max(timeout - (System.currentTimeMillis() - timeBeforeTest), 100);
assertFalse(onErrorSemaphore.tryAcquire(2, timeout, TimeUnit.MILLISECONDS));
// expect no successful subscription callback
verify(listener, times(0)).onReceive(anyInt());
proxy.unsubscribeFromAttributeWithProviderRuntimeException(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class AbstractSubscriptionEnd2EndTest method subscribeToAttributeWithThrownException.
@Test(timeout = CONST_DEFAULT_TEST_TIMEOUT)
public void subscribeToAttributeWithThrownException() throws InterruptedException, ApplicationException {
Semaphore onErrorSemaphore = new Semaphore(0);
ProviderRuntimeException expectedException = new ProviderRuntimeException(new IllegalArgumentException(SubscriptionTestsProviderImpl.MESSAGE_THROWN_PROVIDERRUNTIMEEXCEPTION).toString());
AttributeSubscriptionListener<Integer> listener = prepareOnErrorListenerMock(onErrorSemaphore, expectedException);
int periods = 2;
int subscriptionDuration = (PERIOD_MS * periods);
PeriodicSubscriptionQos subscriptionQos = new PeriodicSubscriptionQos();
subscriptionQos.setPeriodMs(PERIOD_MS);
subscriptionQos.setValidityMs(subscriptionDuration);
subscriptionQos.setAlertAfterIntervalMs(1000);
subscriptionQos.setPublicationTtlMs(0);
Future<String> subscriptionId = proxy.subscribeToAttributeWithThrownException(listener, subscriptionQos);
long timeBeforeTest = System.currentTimeMillis();
long timeout = subscriptionDuration + EXPECTED_LATENCY_MS;
// expect at least #periods errors
assertTrue(onErrorSemaphore.tryAcquire(periods, timeout, TimeUnit.MILLISECONDS));
// expect at most #periods+1 errors
timeout = Math.max(timeout - (System.currentTimeMillis() - timeBeforeTest), 100);
assertFalse(onErrorSemaphore.tryAcquire(2, timeout, TimeUnit.MILLISECONDS));
// expect no successful subscription callback
verify(listener, times(0)).onReceive(anyInt());
proxy.unsubscribeFromAttributeWithThrownException(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
}
use of joynr.PeriodicSubscriptionQos in project joynr by bmwcarit.
the class MutableMessageFactoryTest method setUp.
@Before
public void setUp() throws NoSuchMethodException, SecurityException {
fromParticipantId = "sender";
toParticipantId = "receiver";
Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), new JsonMessageSerializerModule(), new AbstractModule() {
@Override
protected void configure() {
bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
requestStaticInjection(Request.class);
Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
});
joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {
@Override
public MutableMessage processOutgoing(MutableMessage joynrMessage) {
joynrMessage.getCustomHeaders().put("test", "test");
return joynrMessage;
}
@Override
public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
return joynrMessage;
}
});
}
});
objectMapper = injector.getInstance(ObjectMapper.class);
payload = "payload";
Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
String requestReplyId = request.getRequestReplyId();
reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
messagingQos = new MessagingQos(TTL);
expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
String subscriptionId = "subscription";
String attributeName = "attribute";
PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
String response = "response";
publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Aggregations