Search in sources :

Example 26 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class Utilities method splitSMRF.

public static List<ImmutableMessage> splitSMRF(byte[] combinedSMRFMessages) throws EncodingException, UnsuppportedVersionException {
    List<ImmutableMessage> result = Lists.newArrayList();
    byte[] remainingData = combinedSMRFMessages;
    while (remainingData.length > 0) {
        ImmutableMessage currentMessage = new ImmutableMessage(remainingData);
        int currentMessageSize = currentMessage.getMessageSize();
        // A message size of 0 may lead to an infinite loop
        if (currentMessageSize <= 0) {
            logger.error("One message in a SMRF message sequence had a size <= 0. Dropping remaining messages.");
            break;
        }
        remainingData = Arrays.copyOfRange(remainingData, currentMessageSize, remainingData.length);
        result.add(currentMessage);
    }
    return result;
}
Also used : ImmutableMessage(joynr.ImmutableMessage)

Example 27 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class AbstractMessageSender method routeMutableMessage.

private void routeMutableMessage(MutableMessage mutableMessage) {
    ImmutableMessage immutableMessage;
    try {
        immutableMessage = mutableMessage.getImmutableMessage();
    } catch (SecurityException | EncodingException | UnsuppportedVersionException exception) {
        throw new JoynrRuntimeException(exception.getMessage());
    }
    messageRouter.route(immutableMessage);
}
Also used : EncodingException(io.joynr.smrf.EncodingException) ImmutableMessage(joynr.ImmutableMessage) JoynrRuntimeException(io.joynr.exceptions.JoynrRuntimeException) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException)

Example 28 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class AttachmentTest method testSendAndDownload.

@Test
public void testSendAndDownload() throws Exception {
    String channelId = "AttachmentTest_" + UUID.randomUUID().toString();
    bpMock.createChannel(channelId);
    Response senMsgResponse = sendAttachmentMessage(channelId);
    String msgId = senMsgResponse.getHeader("msgId");
    Future<Response> response = bpMock.longPollInOwnThread(channelId, 1000000, 200);
    Response longPoll = response.get();
    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(longPoll);
    assertEquals(1, messages.size());
    ImmutableMessage message = messages.get(0);
    assertTrue(message.getUnencryptedBody() != null);
    Response attachment = getAttachment(channelId, msgId);
    logger.debug("received attachment: " + convertStreamToString(attachment.getBody().asInputStream()));
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 29 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class TtlUpliftTest method setUp.

@Before
public void setUp() throws NoSuchMethodException, SecurityException {
    fromParticipantId = "sender";
    toParticipantId = "receiver";
    cleanupScheduler = new ScheduledThreadPoolExecutor(1);
    cleanupSchedulerSpy = Mockito.spy(cleanupScheduler);
    Module defaultModule = Modules.override(new JoynrPropertiesModule(new Properties())).with(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) {
                    return joynrMessage;
                }

                @Override
                public ImmutableMessage processIncoming(ImmutableMessage joynrMessage) {
                    return joynrMessage;
                }
            });
            bind(PublicationManager.class).to(PublicationManagerImpl.class);
            bind(SubscriptionRequestStorage.class).toInstance(Mockito.mock(FileSubscriptionRequestStorage.class));
            bind(AttributePollInterpreter.class).toInstance(attributePollInterpreter);
            bind(Dispatcher.class).toInstance(dispatcher);
            bind(ProviderDirectory.class).toInstance(providerDirectory);
            bind(ScheduledExecutorService.class).annotatedWith(Names.named(JoynrInjectionConstants.JOYNR_SCHEDULER_CLEANUP)).toInstance(cleanupSchedulerSpy);
        }
    });
    Injector injector = Guice.createInjector(defaultModule);
    messageFactory = injector.getInstance(MutableMessageFactory.class);
    Module ttlUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(TTL_UPLIFT_MS);
        }
    });
    Injector injectorWithTtlUplift = Guice.createInjector(ttlUpliftModule);
    messageFactoryWithTtlUplift = injectorWithTtlUplift.getInstance(MutableMessageFactory.class);
    requestCaller = new RequestCallerFactory().create(provider);
    when(providerContainer.getProviderProxy()).thenReturn(requestCaller.getProxy());
    when(providerContainer.getSubscriptionPublisher()).thenReturn(subscriptionPublisher);
    Deferred<String> valueToPublishDeferred = new Deferred<String>();
    valueToPublishDeferred.resolve(valueToPublish);
    Promise<Deferred<String>> valueToPublishPromise = new Promise<Deferred<String>>(valueToPublishDeferred);
    doReturn(valueToPublishPromise).when(attributePollInterpreter).execute(any(ProviderContainer.class), any(Method.class));
    Module subcriptionUpliftModule = Modules.override(defaultModule).with(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Long.class).annotatedWith(Names.named(ConfigurableMessagingSettings.PROPERTY_TTL_UPLIFT_MS)).toInstance(SUBSCRIPTION_UPLIFT_MS);
        }
    });
    Injector injectorWithPublicationUplift = Guice.createInjector(subcriptionUpliftModule);
    publicationManager = (PublicationManagerImpl) injector.getInstance(PublicationManager.class);
    publicationManagerWithTtlUplift = (PublicationManagerImpl) injectorWithPublicationUplift.getInstance(PublicationManager.class);
    payload = "payload";
    Method method = TestProvider.class.getMethod("methodWithStrings", new Class[] { String.class });
    request = new Request(method.getName(), new String[] { payload }, method.getParameterTypes());
    messagingQos = new MessagingQos(TTL);
    expiryDate = DispatcherUtils.convertTtlToExpirationDate(messagingQos.getRoundTripTtl_ms());
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Deferred(io.joynr.provider.Deferred) JoynrMessageProcessor(io.joynr.messaging.JoynrMessageProcessor) Properties(java.util.Properties) MessagingQos(io.joynr.messaging.MessagingQos) TypeLiteral(com.google.inject.TypeLiteral) MutableMessage(joynr.MutableMessage) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) Injector(com.google.inject.Injector) PublicationManagerImpl(io.joynr.dispatching.subscription.PublicationManagerImpl) ProviderContainer(io.joynr.provider.ProviderContainer) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Multibinder(com.google.inject.multibindings.Multibinder) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) SubscriptionRequest(joynr.SubscriptionRequest) BroadcastSubscriptionRequest(joynr.BroadcastSubscriptionRequest) Request(joynr.Request) Method(java.lang.reflect.Method) AbstractModule(com.google.inject.AbstractModule) Promise(io.joynr.provider.Promise) ImmutableMessage(joynr.ImmutableMessage) Matchers.anyLong(org.mockito.Matchers.anyLong) Module(com.google.inject.Module) JsonMessageSerializerModule(io.joynr.messaging.JsonMessageSerializerModule) JoynrPropertiesModule(io.joynr.common.JoynrPropertiesModule) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 30 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class AbstractBounceProxyServerTest method testSendAndReceiveMessagesOnAtmosphereServer.

@Test(timeout = 20000)
@Ignore
public // the server will hang 20 secs
void testSendAndReceiveMessagesOnAtmosphereServer() throws Exception {
    final long maxTimePerRun = 5000;
    final int maxRuns = 100;
    bpMock.createChannel(channelId);
    // createChannel(channelIdProvider);
    RestAssured.baseURI = getBounceProxyBaseUri();
    int index = 1;
    List<byte[]> expectedPayloads = new ArrayList<byte[]>();
    for (int i = 0; i < maxRuns; i++) {
        expectedPayloads.clear();
        long startTime_ms = System.currentTimeMillis();
        ScheduledFuture<Response> longPollConsumer = bpMock.longPollInOwnThread(channelId, 30000);
        byte[] postPayload = (payload + index++ + "-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
        expectedPayloads.add(postPayload);
        ScheduledFuture<Response> postMessage = bpMock.postMessageInOwnThread(channelId, 5000, postPayload);
        byte[] postPayload2 = (payload + index++ + "-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
        expectedPayloads.add(postPayload2);
        ScheduledFuture<Response> postMessage2 = bpMock.postMessageInOwnThread(channelId, 5000, postPayload2);
        // 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();
        postMessage2.get();
        long elapsedTime_ms = System.currentTimeMillis() - startTime_ms;
        if (receivedMessages.size() < 2 && elapsedTime_ms < maxTimePerRun) {
            // Thread.sleep(100);
            Response responseLongPoll2 = bpMock.longPollInOwnThread(channelId, 30000).get();
            byte[] responseBody2 = responseLongPoll2.getBody().asByteArray();
            List<ImmutableMessage> receivedMessages2 = Utilities.splitSMRF(responseBody2);
            receivedMessages.addAll(receivedMessages2);
        }
        ArrayList<byte[]> payloads = new ArrayList<byte[]>();
        for (ImmutableMessage message : receivedMessages) {
            payloads.add(message.getUnencryptedBody());
        }
        elapsedTime_ms = System.currentTimeMillis() - startTime_ms;
        log.info(i + ": time elapsed to send messages and return long poll:" + elapsedTime_ms);
        assertThat("the long poll did not receive the messages in time", elapsedTime_ms, lessThan(maxTimePerRun));
        if (payloads.size() == 2) {
            assertFalse("Unresolved bug that causes duplicate messages to be sent", payloads.get(0).equals(payloads.get(1)));
        }
        assertThat(payloads, hasItems(postPayload, postPayload2));
    }
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) ArrayList(java.util.ArrayList) Ignore(org.junit.Ignore) 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