Search in sources :

Example 1 with BroadcastSubscriptionListener

use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.

the class SubscriptionManagerImpl method handleBroadcastPublication.

@Override
public void handleBroadcastPublication(String subscriptionId, Object[] broadcastValues) {
    BroadcastSubscriptionListener broadcastSubscriptionListener = getBroadcastSubscriptionListener(subscriptionId);
    try {
        Class<?>[] broadcastTypes = getParameterTypesForBroadcastPublication(broadcastValues);
        Method receive = broadcastSubscriptionListener.getClass().getDeclaredMethod("onReceive", broadcastTypes);
        if (!receive.isAccessible()) {
            receive.setAccessible(true);
        }
        logger.debug("SUBSCRIPTION notify listener: subscriptionId: {}, broadcastValue: {}", subscriptionId, broadcastValues);
        receive.invoke(broadcastSubscriptionListener, broadcastValues);
    } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
        logger.error("Broadcast publication could not be processed", e);
    }
}
Also used : Method(java.lang.reflect.Method) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with BroadcastSubscriptionListener

use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithSuccessWithBroadcastListener.

@Test
public void testHandleSubscriptionReplyWithSuccessWithBroadcastListener() {
    SubscriptionReply subscriptionReply = new SubscriptionReply(subscriptionId);
    @SuppressWarnings("unchecked") Future<String> futureMock = mock(Future.class);
    subscriptionFutureMap.put(subscriptionId, futureMock);
    BroadcastSubscriptionListener broadcastListener = mock(BroadcastSubscriptionListener.class);
    broadcastSubscriptionDirectory.put(subscriptionId, broadcastListener);
    subscriptionManager.handleSubscriptionReply(subscriptionReply);
    verify(futureMock).onSuccess(eq(subscriptionId));
    verify(broadcastListener).onSubscribed(eq(subscriptionId));
}
Also used : SubscriptionReply(joynr.SubscriptionReply) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) Test(org.junit.Test)

Example 3 with BroadcastSubscriptionListener

use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.

the class SubscriptionManagerTest method registerBroadcastSubscription.

@Test
public void registerBroadcastSubscription() throws JoynrSendBufferFullException, JoynrMessageNotSentException, JsonGenerationException, JsonMappingException, IOException {
    String broadcastName = "broadcastName";
    BroadcastSubscriptionListener broadcastSubscriptionListener = mock(LocationUpdateBroadcastListener.class);
    BroadcastSubscribeInvocation subscriptionRequest = new BroadcastSubscribeInvocation(broadcastName, broadcastSubscriptionListener, onChangeQos, future);
    subscriptionManager.registerBroadcastSubscription(fromParticipantId, Sets.newHashSet(toDiscoveryEntry), subscriptionRequest);
    subscriptionId = subscriptionRequest.getSubscriptionId();
    verify(broadcastSubscriptionDirectory).put(Mockito.anyString(), Mockito.eq(broadcastSubscriptionListener));
    verify(subscriptionStates).put(Mockito.anyString(), Mockito.any(PubSubState.class));
    verify(cleanupScheduler).schedule(Mockito.any(Runnable.class), Mockito.eq(onChangeQos.getExpiryDateMs()), Mockito.eq(TimeUnit.MILLISECONDS));
    verify(subscriptionEndFutures, Mockito.times(1)).put(Mockito.eq(subscriptionId), Mockito.any(ScheduledFuture.class));
    verify(dispatcher).sendSubscriptionRequest(eq(fromParticipantId), eq(Sets.newHashSet(toDiscoveryEntry)), any(SubscriptionRequest.class), any(MessagingQos.class));
}
Also used : SubscriptionRequest(joynr.SubscriptionRequest) MessagingQos(io.joynr.messaging.MessagingQos) BroadcastSubscribeInvocation(io.joynr.proxy.invocation.BroadcastSubscribeInvocation) Matchers.anyString(org.mockito.Matchers.anyString) BroadcastSubscriptionListener(io.joynr.pubsub.subscription.BroadcastSubscriptionListener) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Example 4 with BroadcastSubscriptionListener

use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener in project joynr by bmwcarit.

the class SubscriptionManagerTest method testHandleSubscriptionReplyWithErrorWithBroadcastListener.

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

Example 5 with BroadcastSubscriptionListener

use of io.joynr.pubsub.subscription.BroadcastSubscriptionListener 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

BroadcastSubscriptionListener (io.joynr.pubsub.subscription.BroadcastSubscriptionListener)5 Matchers.anyString (org.mockito.Matchers.anyString)4 Test (org.junit.Test)3 SubscriptionException (io.joynr.exceptions.SubscriptionException)2 MessagingQos (io.joynr.messaging.MessagingQos)2 Method (java.lang.reflect.Method)2 SubscriptionReply (joynr.SubscriptionReply)2 SubscriptionRequest (joynr.SubscriptionRequest)2 BroadcastSubscribeInvocation (io.joynr.proxy.invocation.BroadcastSubscribeInvocation)1 MulticastSubscribeInvocation (io.joynr.proxy.invocation.MulticastSubscribeInvocation)1 SubscriptionQos (io.joynr.pubsub.SubscriptionQos)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 Pattern (java.util.regex.Pattern)1 MulticastSubscriptionQos (joynr.MulticastSubscriptionQos)1 OnChangeSubscriptionQos (joynr.OnChangeSubscriptionQos)1 PeriodicSubscriptionQos (joynr.PeriodicSubscriptionQos)1 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)1