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")));
}
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();
}
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);
}
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);
}
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();
}
}
Aggregations