Search in sources :

Example 36 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class MessagingLoadDistributionTest method testMessagePostsToCorrectInstances.

@Test
@Ignore("Ignore until servers are started in a separate JVM. Guice static problem")
public void testMessagePostsToCorrectInstances() throws Exception {
    String uuid1 = UUID.randomUUID().toString();
    String channelId1 = "channel-" + uuid1;
    String uuid2 = UUID.randomUUID().toString();
    String channelId2 = "channel-" + uuid2;
    // create channels; use extra method as we don't know which location to expect
    Response responseCreateChannel1 = createChannel(bpMock1, channelId1);
    Response responseCreateChannel2 = createChannel(bpMock2, channelId2);
    Assert.assertNotSame("Channels created on two different Bounce Proxies", responseCreateChannel1.getHeader("bp"), responseCreateChannel2.getHeader("bp"));
    String channelUrl1 = responseCreateChannel1.getHeader("Location");
    String channelUrl2 = responseCreateChannel2.getHeader("Location");
    // post messages to long polling channel before opening channel
    String[] payloads1 = { "message-1_1", "message-1_2", "message-1_3" };
    for (String payload : payloads1) {
        postMessageToBounceProxy(bpMock1, channelUrl1, channelId1, 30000l, payload.getBytes(Charsets.UTF_8));
    }
    String[] payloads2 = { "message-2_1", "message-2_2", "message-2_3" };
    for (String payload : payloads2) {
        postMessageToBounceProxy(bpMock2, channelUrl2, channelId2, 30000l, payload.getBytes(Charsets.UTF_8));
    }
    // open long polling channel
    List<ImmutableMessage> messages1 = getMessagesFromBounceProxy(bpMock1, channelUrl1, channelId1);
    assertEquals(3, messages1.size());
    assertThat(messages1, allOf(containsPayload("message-1_1"), containsPayload("message-1_2"), containsPayload("message-1_3")));
    List<ImmutableMessage> messages2 = getMessagesFromBounceProxy(bpMock2, channelUrl2, channelId2);
    assertEquals(3, messages2.size());
    assertThat(messages2, allOf(containsPayload("message-2_1"), containsPayload("message-2_2"), containsPayload("message-2_3")));
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class WebSocketTest method sendMessage.

private void sendMessage() throws Throwable {
    OneWayRequest request = new OneWayRequest("method", new Object[0], new Class<?>[0]);
    MessagingQos messagingQos = new MessagingQos(100000);
    ImmutableMessage msg = messageFactory.createOneWayRequest("fromID", "toID", request, messagingQos).getImmutableMessage();
    SuccessAction successAction = mock(SuccessAction.class);
    webSocketMessagingStub.transmit(msg, successAction, new FailureAction() {

        @Override
        public void execute(Throwable error) {
            Assert.fail(error.getMessage());
        }
    });
    Mockito.verify(messageRouterMock, Mockito.timeout(1000)).route(argThat(new SerializedDataOfImmutableMessageMatcher(msg)));
    Mockito.verify(successAction).execute();
}
Also used : OneWayRequest(joynr.OneWayRequest) MessagingQos(io.joynr.messaging.MessagingQos) SuccessAction(io.joynr.messaging.SuccessAction) FailureAction(io.joynr.messaging.FailureAction) ImmutableMessage(joynr.ImmutableMessage)

Example 38 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class JeeServletMessageReceiverTest method testReceive.

@Test
public void testReceive() {
    start();
    ImmutableMessage message = Mockito.mock(ImmutableMessage.class);
    when(message.isTtlAbsolute()).thenReturn(true);
    when(message.getTtlMs()).thenReturn(ExpiryDate.fromRelativeTtl(1000L).getValue());
    subject.receive(message);
    verify(messageArrivedListener).messageArrived(message);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 39 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class JeeServletMessageReceiverTest method testOnError.

@Test
public void testOnError() {
    start();
    ImmutableMessage message = Mockito.mock(ImmutableMessage.class);
    Throwable error = new RuntimeException();
    subject.onError(message, error);
    verify(messageArrivedListener).error(message, error);
}
Also used : ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 40 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class AttachmentSenderService method postMessageWithAttachment.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postMessageWithAttachment(@PathParam("ccid") String ccid, @FormDataParam("wrapper") String serializedMessage, @FormDataParam("attachment") InputStream attachment) {
    try {
        byte[] serializedMessageBytes = serializedMessage.getBytes(Charsets.UTF_8);
        ImmutableMessage message = new ImmutableMessage(serializedMessageBytes);
        log.debug("Message with attachment received! Expiry Date : " + message.getTtlMs());
        int bytesRead = 0;
        int bytesToRead = 1024;
        byte[] input = new byte[bytesToRead];
        while (bytesRead < bytesToRead) {
            int result = attachment.read(input, bytesRead, bytesToRead - bytesRead);
            if (result == -1)
                break;
            bytesRead += result;
        }
        attachmentStorage.put(message.getId(), input);
        log.debug("Uploaded attachment : " + new String(input, 0, Math.min(50, input.length), "UTF-8"));
        // post message
        try {
            String msgId = message.getId();
            log.debug("******POST message {} to cluster controller: {}", msgId, ccid);
            log.trace("******POST message {} to cluster controller: {} extended info: \r\n {}", ccid, message);
            // the location that can be queried to get the message
            // status
            // TODO REST URL for message status?
            String path = longPollingDelegate.postMessage(ccid, serializedMessageBytes);
            URI location = ui.getBaseUriBuilder().path(path).build();
            // return the message status location to the sender.
            return Response.created(location).header("msgId", msgId).build();
        } catch (WebApplicationException e) {
            log.error("Invalid request from host {}", request.getRemoteHost());
            throw e;
        } catch (Exception e) {
            log.error("POST message for cluster controller: error: {}", e.getMessage());
            throw new WebApplicationException(e);
        }
    } catch (IOException | EncodingException | UnsuppportedVersionException e) {
        log.error("POST message for cluster controller: error: {}", e.getMessage(), e);
        return Response.serverError().build();
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) EncodingException(io.joynr.smrf.EncodingException) ImmutableMessage(joynr.ImmutableMessage) IOException(java.io.IOException) URI(java.net.URI) EncodingException(io.joynr.smrf.EncodingException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException) UnsuppportedVersionException(io.joynr.smrf.UnsuppportedVersionException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

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