Search in sources :

Example 11 with SubscriptionException

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

Example 12 with SubscriptionException

use of io.joynr.exceptions.SubscriptionException in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithError.

@Test
public void testHandleSubscriptionReplyWithError() {
    SubscriptionException subscriptionError = new SubscriptionException(subscriptionId);
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId, subscriptionError);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onFailure(eq(subscriptionError));
}
Also used : SubscriptionException(io.joynr.exceptions.SubscriptionException) SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

SubscriptionException (io.joynr.exceptions.SubscriptionException)12 Test (org.junit.Test)9 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)6 Semaphore (java.util.concurrent.Semaphore)4 SubscriptionReply (joynr.SubscriptionReply)4 Matchers.anyString (org.mockito.Matchers.anyString)4 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)2 BroadcastSubscriptionListener (io.joynr.pubsub.subscription.BroadcastSubscriptionListener)2 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)2 ExtendedTypeCollectionEnumerationInTypeCollection (joynr.interlanguagetest.namedTypeCollection2.ExtendedTypeCollectionEnumerationInTypeCollection)2 joynr.tests.testBroadcastInterface (joynr.tests.testBroadcastInterface)2 Ignore (org.junit.Ignore)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 MessagingQos (io.joynr.messaging.MessagingQos)1 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 Method (java.lang.reflect.Method)1 HashSet (java.util.HashSet)1