Search in sources :

Example 56 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class AbstractBounceProxyServerTest method testSendAndReceiveMessagesConcurrently.

@Test(timeout = 1000000)
@Ignore
public // results in duplicate messages in the long poll.
void testSendAndReceiveMessagesConcurrently() throws Exception {
    final int maxRuns = 1000;
    bpMock.createChannel(channelId);
    // createChannel(channelIdProvider);
    RestAssured.baseURI = getBounceProxyBaseUri();
    List<byte[]> expectedPayloads = new ArrayList<byte[]>();
    for (int i = 0; i < maxRuns; i++) {
        expectedPayloads.clear();
        ScheduledFuture<Response> longPollConsumer = bpMock.longPollInOwnThread(channelId, 30000);
        byte[] postPayload = (payload + i + "-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
        expectedPayloads.add(postPayload);
        ScheduledFuture<Response> postMessage = bpMock.postMessageInOwnThread(channelId, 5000, postPayload);
        // wait until the long poll returns
        Response responseLongPoll = longPollConsumer.get();
        byte[] responseBody = responseLongPoll.getBody().asByteArray();
        List<ImmutableMessage> receivedMessages = Utilities.splitSMRF(responseBody);
        // wait until the POSTs are finished.
        postMessage.get();
        ArrayList<byte[]> payloads = new ArrayList<byte[]>();
        for (ImmutableMessage message : receivedMessages) {
            payloads.add(message.getUnencryptedBody());
        }
        // assertFalse("Unresolved bug that causes duplicate messages to be sent", payloads.size() == 2);
        // assertEquals(1, payloads.size());
        assertThat(payloads, hasItems(postPayload));
    }
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 57 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class DispatcherImplTest method testPropagateCompressFlagFromRequestToRepliesImpl.

private void testPropagateCompressFlagFromRequestToRepliesImpl(final boolean compress) throws Exception {
    MessagingQos messagingQos = new MessagingQos(1000L);
    messagingQos.setCompress(compress);
    String requestReplyId = UUID.randomUUID().toString();
    Request request = new Request("methodName", new Object[] {}, new String[] {}, requestReplyId);
    final String providerParticipantId = "toParticipantId";
    MutableMessage joynrMessage = messageFactory.createRequest("fromParticipantId", providerParticipantId, request, messagingQos);
    ImmutableMessage outgoingMessage = joynrMessage.getImmutableMessage();
    fixture.messageArrived(outgoingMessage);
    verify(requestReplyManagerMock).handleRequest(providerCallbackReply.capture(), eq(providerParticipantId), eq(request), eq(joynrMessage.getTtlMs()));
    providerCallbackReply.getValue().onSuccess(new Reply(requestReplyId));
    verify(messageSenderMock).sendMessage(argThat(new MessageIsCompressedMatcher(compress)));
}
Also used : MessagingQos(io.joynr.messaging.MessagingQos) MutableMessage(joynr.MutableMessage) ImmutableMessage(joynr.ImmutableMessage) OneWayRequest(joynr.OneWayRequest) SubscriptionRequest(joynr.SubscriptionRequest) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) Request(joynr.Request) Reply(joynr.Reply) Matchers.anyString(org.mockito.Matchers.anyString)

Example 58 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class MutableMessageFactoryTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    Injector injector = Guice.createInjector(new JoynrPropertiesModule(new Properties()), new JsonMessageSerializerModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(NO_TTL_UPLIFT);
            requestStaticInjection(Request.class);
            Multibinder<JoynrMessageProcessor> joynrMessageProcessorMultibinder = Multibinder.newSetBinder(binder(), new TypeLiteral<JoynrMessageProcessor>() {
            });
            joynrMessageProcessorMultibinder.addBinding().toInstance(new JoynrMessageProcessor() {

                @Override
                public MutableMessage processOutgoing(MutableMessage joynrMessage) {
                    joynrMessage.getCustomHeaders().put("test", "test");
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
        }
    });
    objectMapper = injector.getInstance(ObjectMapper.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    String requestReplyId = request.getRequestReplyId();
    reply = new Reply(requestReplyId, objectMapper.<JsonNode>valueToTree(payload));
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
    String subscriptionId = "subscription";
    String attributeName = "attribute";
    PeriodicSubscriptionQos subscriptionqos = new PeriodicSubscriptionQos();
    subscriptionqos.setPeriodMs(1000).setValidityMs(10).setAlertAfterIntervalMs(1500).setPublicationTtlMs(1000);
    subscriptionRequest = new SubscriptionRequest(subscriptionId, attributeName, subscriptionqos);
    String response = "response";
    publication = new SubscriptionPublication(Arrays.asList(response), subscriptionId);
    mutableMessageFactory = injector.getInstance(MutableMessageFactory.class);
}
Also used : Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) Request(joynr.Request) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) JsonNode(com.fasterxml.jackson.databind.JsonNode) Method(java.lang.reflect.Method) Properties(java.util.Properties) AbstractModule(com.google.inject.AbstractModule) PeriodicSubscriptionQos(joynr.PeriodicSubscriptionQos) MessagingQos(io.joynr.messaging.MessagingQos) MulticastSubscriptionRequest(joynr.MulticastSubscriptionRequest) SubscriptionRequest(joynr.SubscriptionRequest) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) Injector(com.google.inject.Injector) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) SubscriptionPublication(joynr.SubscriptionPublication) ImmutableMessage(joynr.ImmutableMessage) Reply(joynr.Reply) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 59 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testNoRetryForMulticastWithoutAddress.

@Test
public void testNoRetryForMulticastWithoutAddress() throws Exception {
    joynrMessage.setTtlMs(ExpiryDate.fromRelativeTtl(1000).getValue());
    joynrMessage.setType(Message.VALUE_MESSAGE_TYPE_MULTICAST);
    joynrMessage.setRecipient("multicastId");
    ImmutableMessage immutableMessage = joynrMessage.getImmutableMessage();
    messageRouter.route(immutableMessage);
    Thread.sleep(100);
    verify(addressManager).getAddresses(immutableMessage);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 60 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class CcMessageRouterTest method testRetryWithMaxRetryCount.

@Test
public void testRetryWithMaxRetryCount() throws Exception {
    final long routingMaxRetryCount = 3;
    MessageRouter messageRouterWithMaxRetryCount = getMessageRouterWithMaxRetryCount(routingMaxRetryCount);
    ImmutableMessage immutableMessage = retryRoutingWith1msDelay(messageRouterWithMaxRetryCount, 100000000);
    verify(messagingStubMock, times((int) routingMaxRetryCount + 1)).transmit(eq(immutableMessage), any(SuccessAction.class), any(FailureAction.class));
}
Also used : SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) CcMessageRouter(io.joynr.messaging.routing.CcMessageRouter) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Aggregations

ImmutableMessage (joynr.ImmutableMessage)63 Test (org.junit.Test)42 Response (com.jayway.restassured.response.Response)12 FailureAction (io.joynr.messaging.FailureAction)11 SuccessAction (io.joynr.messaging.SuccessAction)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)10 EncodingException (io.joynr.smrf.EncodingException)9 MutableMessage (joynr.MutableMessage)9 JoynrRuntimeException (io.joynr.exceptions.JoynrRuntimeException)8 UnsuppportedVersionException (io.joynr.smrf.UnsuppportedVersionException)8 Semaphore (java.util.concurrent.Semaphore)7 JoynrDelayMessageException (io.joynr.exceptions.JoynrDelayMessageException)6 JoynrMessageNotSentException (io.joynr.exceptions.JoynrMessageNotSentException)6 MessagingQos (io.joynr.messaging.MessagingQos)6 Ignore (org.junit.Ignore)6 AbstractModule (com.google.inject.AbstractModule)5 JoynrMessageProcessor (io.joynr.messaging.JoynrMessageProcessor)5 Injector (com.google.inject.Injector)4 Module (com.google.inject.Module)4 CcMessageRouter (io.joynr.messaging.routing.CcMessageRouter)4