Search in sources :

Example 21 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class CcMessageRouterTest method testMessageProcessedListenerOnlyCalledOnceForMulticast.

@Test
public void testMessageProcessedListenerOnlyCalledOnceForMulticast() throws Exception {
    final Semaphore semaphore = new Semaphore(-1);
    ChannelAddress receiverAddress1 = new ChannelAddress("http://testUrl", "channelId1");
    ChannelAddress receiverAddress2 = new ChannelAddress("http://testUrl", "channelId2");
    prepareMulticastForMultipleAddresses(receiverAddress1, receiverAddress2);
    final ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    final MessageProcessedListener mockMessageProcessedListener = mock(MessageProcessedListener.class);
    messageRouter.registerMessageProcessedListener(mockMessageProcessedListener);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            verify(mockMessageProcessedListener, times(0)).messageProcessed(eq(immutableMessage.getId()));
            invocation.getArgumentAt(1, SuccessAction.class).execute();
            semaphore.release();
            return null;
        }
    }).when(messagingStubMock).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    messageRouter.route(immutableMessage);
    semaphore.tryAcquire(1000, TimeUnit.MILLISECONDS);
    verify(messagingStubMock, times(2)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
    verify(mockMessageProcessedListener).messageProcessed(eq(immutableMessage.getId()));
}
Also used : SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ImmutableMessage(joynr.ImmutableMessage) ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Example 22 with ChannelAddress

use of joynr.system.RoutingTypes.ChannelAddress in project joynr by bmwcarit.

the class LongPollingHttpMulticastAddressCalculator method calculate.

@Override
public Address calculate(ImmutableMessage message) {
    if (true) {
        throw new UnsupportedOperationException("Multicasts are not yet supported for HTTP long polling.");
    }
    ChannelAddress multicastAddress = null;
    if (globalAddress != null) {
        try {
            String multicastChannelId = URLEncoder.encode(message.getSender() + "/" + message.getRecipient(), UTF_8);
            multicastAddress = new ChannelAddress(globalAddress.getMessagingEndpointUrl(), multicastChannelId);
        } catch (UnsupportedEncodingException e) {
            logger.error("Unable to encode multicast channel from message {}", message, e);
        }
    } else {
        logger.warn("Unable to calculate multicast address for message {} because no global address was found for long polling.", message);
    }
    return multicastAddress;
}
Also used : ChannelAddress(joynr.system.RoutingTypes.ChannelAddress) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

ChannelAddress (joynr.system.RoutingTypes.ChannelAddress)22 ProviderQos (joynr.types.ProviderQos)12 Version (joynr.types.Version)12 Test (org.junit.Test)12 Address (joynr.system.RoutingTypes.Address)10 DiscoveryEntryWithMetaInfo (joynr.types.DiscoveryEntryWithMetaInfo)9 DiscoveryException (io.joynr.exceptions.DiscoveryException)6 MqttAddress (joynr.system.RoutingTypes.MqttAddress)6 HashSet (java.util.HashSet)5 InvocationOnMock (org.mockito.invocation.InvocationOnMock)5 CustomParameter (joynr.types.CustomParameter)4 DiscoveryEntry (joynr.types.DiscoveryEntry)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 FailureAction (io.joynr.messaging.FailureAction)3 SuccessAction (io.joynr.messaging.SuccessAction)3 InProcessAddress (io.joynr.messaging.inprocess.InProcessAddress)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3