Search in sources :

Example 21 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos 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)

Example 22 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class SerializationTest method serializeAndDeserializeSubscriptionQosTest.

@Test
public void serializeAndDeserializeSubscriptionQosTest() throws Exception {
    OnChangeWithKeepAliveSubscriptionQos qos = new OnChangeWithKeepAliveSubscriptionQos().setMinIntervalMs(1000L).setMaxIntervalMs(30000L).setValidityMs(60000).setAlertAfterIntervalMs(0L).setPublicationTtlMs(5000);
    String valueAsString = objectMapper.writeValueAsString(qos);
    System.out.println(valueAsString);
    SubscriptionQos readValue = objectMapper.readValue(valueAsString, SubscriptionQos.class);
    assertEquals(qos, readValue);
}
Also used : OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) OnChangeWithKeepAliveSubscriptionQos(joynr.OnChangeWithKeepAliveSubscriptionQos) Test(org.junit.Test)

Example 23 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class MulticastSubscriptionRequestSerializationTest method testSerializeAndDeserialize.

@Test
public void testSerializeAndDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    String multicastId = "multicastId";
    String multicastName = "multicastName";
    String subscriptionId = "subscriptionId";
    SubscriptionQos qos = new OnChangeSubscriptionQos();
    MulticastSubscriptionRequest multicastSubscriptionRequest = new MulticastSubscriptionRequest(multicastId, subscriptionId, multicastName, qos);
    String serializedValue = objectMapper.writeValueAsString(multicastSubscriptionRequest);
    logger.trace("Serialized {} is {}", multicastSubscriptionRequest, serializedValue);
    assertNotNull(serializedValue);
    MulticastSubscriptionRequest deserializedMulticastSubscriptionRequest = objectMapper.readValue(serializedValue, MulticastSubscriptionRequest.class);
    assertNotNull(deserializedMulticastSubscriptionRequest);
    assertEquals(multicastId, deserializedMulticastSubscriptionRequest.getMulticastId());
    assertEquals(multicastName, deserializedMulticastSubscriptionRequest.getSubscribedToName());
    assertEquals(subscriptionId, deserializedMulticastSubscriptionRequest.getSubscriptionId());
    assertEquals(qos, deserializedMulticastSubscriptionRequest.getQos());
}
Also used : SubscriptionQos(io.joynr.pubsub.SubscriptionQos) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 24 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class MutableMessageFactoryTest method testCreateMulticastSubscriptionRequest.

@Test
public void testCreateMulticastSubscriptionRequest() {
    String multicastId = "multicastId";
    String subscriptionId = "subscriptionId";
    String multicastName = "multicastName";
    SubscriptionQos subscriptionQos = mock(SubscriptionQos.class);
    MulticastSubscriptionRequest multicastSubscriptionRequest = new MulticastSubscriptionRequest(multicastId, subscriptionId, multicastName, subscriptionQos);
    MutableMessage result = mutableMessageFactory.createSubscriptionRequest(fromParticipantId, toParticipantId, multicastSubscriptionRequest, messagingQos);
    assertNotNull(result);
    assertEquals(Message.VALUE_MESSAGE_TYPE_MULTICAST_SUBSCRIPTION_REQUEST, result.getType());
    assertExpiryDateEquals(expiryDate.getValue(), result);
}
Also used : MutableMessage(joynr.MutableMessage) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) Test(org.junit.Test)

Example 25 with SubscriptionQos

use of io.joynr.pubsub.SubscriptionQos in project joynr by bmwcarit.

the class SubscriptionManagerTest method testRegisterMulticastSubscription.

@SuppressWarnings("unchecked")
private void testRegisterMulticastSubscription(String subscriptionId, String... partitions) throws Exception {
    Method method = TestMulticastSubscriptionInterface.class.getMethod("subscribeToMyMulticast", new Class[0]);
    BroadcastSubscriptionListener listener = spy(new BroadcastSubscriptionListener() {

        @Override
        public void onError(SubscriptionException error) {
        }

        @Override
        public void onSubscribed(String subscriptionId) {
        }

        @SuppressWarnings("unused")
        public void onReceive() {
        }
    });
    SubscriptionQos subscriptionQos = mock(MulticastSubscriptionQos.class);
    Object[] args;
    if (subscriptionId == null) {
        args = new Object[] { listener, subscriptionQos, partitions };
    } else {
        args = new Object[] { subscriptionId, listener, subscriptionQos, partitions };
    }
    String multicastId = MulticastIdUtil.createMulticastId(toParticipantId, "myMulticast", partitions);
    Set<String> subscriptionIdSet = new HashSet<>();
    Pattern multicastIdPattern = Pattern.compile(multicastId);
    multicastSubscribersDirectory.put(multicastIdPattern, subscriptionIdSet);
    when(multicastWildcardRegexFactory.createIdPattern(multicastId)).thenReturn(multicastIdPattern);
    MulticastSubscribeInvocation invocation = new MulticastSubscribeInvocation(method, args, future);
    DiscoveryEntryWithMetaInfo toDiscoveryEntry = new DiscoveryEntryWithMetaInfo();
    toDiscoveryEntry.setParticipantId(toParticipantId);
    subscriptionManager.registerMulticastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), invocation);
    verify(multicastSubscribersDirectory).put(any(Pattern.class), anySet());
    assertEquals(1, subscriptionIdSet.size());
    if (subscriptionId != null) {
        assertEquals(subscriptionId, subscriptionIdSet.iterator().next());
    }
    verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) Pattern(java.util.regex.Pattern) MulticastSubscribeInvocation(io.joynr.proxy.invocation.MulticastSubscribeInvocation) Method(java.lang.reflect.Method) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) OnChangeSubscriptionQos(joynr.OnChangeSubscriptionQos) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MulticastSubscriptionQos(joynr.MulticastSubscriptionQos) SubscriptionQos(io.joynr.pubsub.SubscriptionQos) DiscoveryEntryWithMetaInfo(joynr.types.DiscoveryEntryWithMetaInfo) HashSet(java.util.HashSet)

Aggregations

SubscriptionQos (io.joynr.pubsub.SubscriptionQos)25 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)18 Test (org.junit.Test)17 MessagingQos (io.joynr.messaging.MessagingQos)10 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)10 SubscriptionRequest (joynr.SubscriptionRequest)8 BroadcastSubscriptionRequest (joynr.BroadcastSubscriptionRequest)7 Matchers.anyString (org.mockito.Matchers.anyString)7 OnChangeWithKeepAliveSubscriptionQos (joynr.OnChangeWithKeepAliveSubscriptionQos)5 UnicastSubscriptionQos (joynr.UnicastSubscriptionQos)5 Method (java.lang.reflect.Method)4 SubscriptionPublication (joynr.SubscriptionPublication)4 SubscriptionException (io.joynr.exceptions.SubscriptionException)3 AttributeSubscribeInvocation (io.joynr.proxy.invocation.AttributeSubscribeInvocation)3 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)3 SubscriptionReply (joynr.SubscriptionReply)3 PersistedSubscriptionRequest (io.joynr.dispatching.subscription.PersistedSubscriptionRequest)2 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)2 AttributeSubscriptionAdapter (io.joynr.pubsub.subscription.AttributeSubscriptionAdapter)2 AttributeSubscriptionListener (io.joynr.pubsub.subscription.AttributeSubscriptionListener)2