Search in sources :

Example 26 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class AbstractSubscriptionEnd2EndTest method testExpiredOnChangeSubscription.

@Ignore
@Test
public void testExpiredOnChangeSubscription() throws InterruptedException, ApplicationException {
    Semaphore onReceiveSemaphore = new Semaphore(0);
    AttributeSubscriptionListener<Integer> integerListener = prepareOnReceiveListenerMock(onReceiveSemaphore);
    // Only get onChange messages
    long minInterval_ms = 0;
    // Expire quickly
    long duration = 500;
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
    subscriptionQos.setMinIntervalMs(minInterval_ms);
    subscriptionQos.setValidityMs(duration);
    subscriptionQos.setPublicationTtlMs(10000);
    Future<String> subscriptionId = proxy.subscribeToTestAttribute(integerListener, subscriptionQos);
    getSubscriptionTestsPublisher().waitForAttributeSubscription("testAttribute");
    // There should have only been one call - the automatic publication when a subscription is made
    assertTrue(onReceiveSemaphore.tryAcquire(1000, TimeUnit.MILLISECONDS));
    verifyNoMoreInteractions(integerListener);
    Thread.sleep(duration + EXPECTED_LATENCY_MS);
    // We should now have an expired onChange subscription
    provider.setTestAttribute(5);
    assertFalse(onReceiveSemaphore.tryAcquire(100, TimeUnit.MILLISECONDS));
    proxy.unsubscribeFromTestAttribute(subscriptionId.get(FUTURE_SUBSCRIPTION_ID_TIMEOUTMS));
    getSubscriptionTestsPublisher().waitForAttributeUnsubscription("testAttribute");
}
Also used : OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) Semaphore(java.util.concurrent.Semaphore) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class ConnectorTest method subscribeToBroadcastCallCallsSubscriptionManagerWithCorrectArguments.

@Test
public void subscribeToBroadcastCallCallsSubscriptionManagerWithCorrectArguments() {
    TestBroadcastListener listener = new TestBroadcastInterface.TestBroadcastAdapter();
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos();
    ConnectorInvocationHandler connector = createConnector();
    assertNotNull(connector);
    try {
        Method method = TestBroadcastInterface.class.getDeclaredMethod("subscribeToTestBroadcast", TestBroadcastListener.class, OnChangeSubscriptionQos.class, BroadcastFilterParameters.class);
        BroadcastSubscribeInvocation invocation = new BroadcastSubscribeInvocation(method, new Object[] { listener, subscriptionQos, new BroadcastFilterParameters() }, null);
        connector.executeSubscriptionMethod(invocation);
        verify(subscriptionManager, times(1)).registerBroadcastSubscription(fromParticipantId, toDiscoveryEntries, invocation);
    } catch (Exception e) {
        fail("Unexpected exception from broadcast subscribe call: " + e);
    }
}
Also used : BroadcastFilterParameters(joynr.BroadcastFilterParameters) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) TestBroadcastListener(io.joynr.proxy.ConnectorTest.TestBroadcastInterface.TestBroadcastListener) Method(java.lang.reflect.Method) SubscriptionException(io.joynr.exceptions.SubscriptionException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) JoynrIllegalStateException(io.joynr.exceptions.JoynrIllegalStateException) Test(org.junit.Test)

Example 28 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos 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 29 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos in project joynr by bmwcarit.

the class ProxyTest method createProxySubscribeAndUnsubscribeFromSelectiveBroadcast.

@Test
public void createProxySubscribeAndUnsubscribeFromSelectiveBroadcast() throws Exception {
    NavigationProxy proxy = getNavigationProxy();
    long minInterval_ms = 0;
    long expiryDate = System.currentTimeMillis() + 30000;
    long publicationTtl_ms = 5000;
    OnChangeSubscriptionQos subscriptionQos = new OnChangeSubscriptionQos().setMinIntervalMs(minInterval_ms).setExpiryDateMs(expiryDate).setPublicationTtlMs(publicationTtl_ms);
    LocationUpdateSelectiveBroadcastFilterParameters filterParameter = new LocationUpdateSelectiveBroadcastFilterParameters();
    Future<String> subscriptionId = proxy.subscribeToLocationUpdateSelectiveBroadcast(mock(LocationUpdateSelectiveBroadcastListener.class), subscriptionQos, filterParameter);
    ArgumentCaptor<BroadcastSubscribeInvocation> subscriptionRequest = ArgumentCaptor.forClass(BroadcastSubscribeInvocation.class);
    verify(subscriptionManager, times(1)).registerBroadcastSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), subscriptionRequest.capture());
    assertEquals("locationUpdateSelective", subscriptionRequest.getValue().getBroadcastName());
    // now, let's remove the previous subscriptionRequest
    proxy.unsubscribeFromGuidanceActive(subscriptionId.get(100L));
    verify(subscriptionManager, times(1)).unregisterSubscription(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), eq(subscriptionId.get()), any(MessagingQos.class));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) LocationUpdateSelectiveBroadcastListener(joynr.vehicle.NavigationBroadcastInterface.LocationUpdateSelectiveBroadcastListener) NavigationProxy(joynr.vehicle.NavigationProxy) LocationUpdateSelectiveBroadcastFilterParameters(joynr.vehicle.NavigationBroadcastInterface.LocationUpdateSelectiveBroadcastFilterParameters) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 30 with OnChangeSubscriptionQos

use of joynr.OnChangeSubscriptionQos 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

OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)40 Test (org.junit.Test)35 MessagingQos (io.joynr.messaging.MessagingQos)20 SubscriptionPublication (joynr.SubscriptionPublication)18 SubscriptionRequest (joynr.SubscriptionRequest)16 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)15 Matchers.anyString (org.mockito.Matchers.anyString)15 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)9 joynr.tests.testLocationUpdateSelectiveBroadcastFilter (joynr.tests.testLocationUpdateSelectiveBroadcastFilter)8 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)7 BroadcastFilter (io.joynr.pubsub.publication.BroadcastFilter)6 joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter (joynr.tests.testLocationUpdateWithSpeedSelectiveBroadcastFilter)6 GpsLocation (joynr.types.Localisation.GpsLocation)6 Semaphore (java.util.concurrent.Semaphore)5 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)5 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)5 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 Ignore (org.junit.Ignore)4 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)3