Search in sources :

Example 31 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class ChannelServicesTest method testOpenChannelWithCachedMessages.

@Test
public void testOpenChannelWithCachedMessages() throws Exception {
    // removed, was only used to view logfiles of a dependency. Not needed anymore.
    // java.util.logging.Logger.getLogger(ProviderServices.class.getName()).setLevel(Level.ALL);
    String channelId = UUID.randomUUID().toString();
    bpMock.createChannel(channelId);
    // generate a random payload
    byte[] payload1 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    byte[] payload2 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    long messageRelativeTtlMs = 1000000L;
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload1);
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload2);
    int longpollTimeout_ms = 100000;
    long timeStart = System.currentTimeMillis();
    Future<Response> responseFuture = bpMock.longPollInOwnThread(channelId, longpollTimeout_ms);
    Response response = responseFuture.get();
    int timeTotal = (int) (System.currentTimeMillis() - timeStart);
    // make sure we did not wait the timeout
    assertThat(timeTotal, lessThan(longpollTimeout_ms));
    List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(response);
    ImmutableMessage receivedPayload1 = messagesFromResponse.get(0);
    ImmutableMessage receivedPayload2 = messagesFromResponse.get(1);
    assertEquals(receivedPayload1.getUnencryptedBody(), payload1);
    assertEquals(receivedPayload2.getUnencryptedBody(), payload2);
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 32 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class ChannelServicesTest method testCreateAndDeleteChannel.

@Test
public void testCreateAndDeleteChannel() throws Exception {
    int longpollTimeout_ms = 5000;
    String channelId = UUID.randomUUID().toString();
    bpMock.createChannel(channelId);
    // start the long poll on the channel, then delete it.
    Future<Response> longPoll = bpMock.longPollInOwnThread(channelId, longpollTimeout_ms);
    Thread.sleep(100);
    bpMock.deleteChannel(channelId, 100, 200);
    // After delete, the long poll should not longer be active, should not have to wait long until it returns empty
    longPoll.get(100L, TimeUnit.MILLISECONDS);
    // generate a random payload
    byte[] payload1 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    byte[] payload2 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    long messageRelativeTtlMs = 1000000L;
    // expect the messages not to be postable since the channel does not exist (get 400 back from server)
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload1, 400);
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload2, 400);
    bpMock.createChannel(channelId);
    // now the posts should work
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload1);
    bpMock.postMessage(channelId, messageRelativeTtlMs, payload2);
    Thread.sleep(2000);
    long timeStart = System.currentTimeMillis();
    longPoll = bpMock.longPollInOwnThread(channelId, longpollTimeout_ms);
    Response response = longPoll.get();
    int timeTotal = (int) (System.currentTimeMillis() - timeStart);
    // make sure we did not wait the timeout
    assertThat(timeTotal, lessThan(longpollTimeout_ms));
    List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(response);
    ImmutableMessage receivedPayload1 = messagesFromResponse.get(0);
    ImmutableMessage receivedPayload2 = messagesFromResponse.get(1);
    assertEquals(receivedPayload1.getUnencryptedBody(), payload1);
    assertEquals(receivedPayload2.getUnencryptedBody(), payload2);
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Test(org.junit.Test)

Example 33 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class ControlledBounceProxyServerTest method testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened.

@Test(timeout = 30000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened() throws Exception {
    final String channelId = "channel-testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithMultipleMessagesPendingBeforeChannelWasOpened";
    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId).post("channels?ccid=" + channelId);
    /* @formatter:on */
    assertEquals(201, /* Created */
    responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);
    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));
    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);
    // post messages to long polling channel before opening channel
    String[] msgIds = { "message-123", "message-456", "message-789" };
    for (String msgId : msgIds) {
        byte[] serializedMessage = bpMock.createImmutableMessage(100000l, msgId.getBytes(Charsets.UTF_8)).getSerializedMessage();
        /* @formatter:off */
        Response responsePostMessage = given().when().log().all().contentType(ContentType.BINARY).body(serializedMessage).post("message/" + SESSIONID_APPENDIX + sessionId);
        /* @formatter:on */
        assertEquals(201, /* Created */
        responsePostMessage.getStatusCode());
        assertThat(responsePostMessage.getHeader(HEADER_LOCATION), isMessageUrlwithJsessionId(bpUrl, msgId, sessionId, SESSIONID_NAME));
        assertEquals(msgId, responsePostMessage.getHeader(HEADER_MSG_ID));
    }
    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when().contentType(ContentType.BINARY).header(X_ATMOSPHERE_TRACKING_ID, trackingId).get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200, /* OK */
    responseOpenChannel.getStatusCode());
    // body doesn't actually contain proper json, but each message
    // serialized as json attached. We have to split them first.
    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(3, messages.size());
    assertThat(messages, containsPayload("message-123"));
    assertThat(messages, containsPayload("message-456"));
    assertThat(messages, containsPayload("message-789"));
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class ControlledBounceProxyServerTest method testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened.

@Test(timeout = 20000)
@Ignore("need cleanup of other tests (i.e. implementation of delete channel")
public void testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened() throws Exception {
    final String channelId = "channel-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";
    final String trackingId = "trackingId-testNormalMessagingWithOneMessagePendingBeforeChannelWasOpened";
    // create channel on bounce proxy
    /* @formatter:off */
    Response responseCreateChannel = given().header(X_ATMOSPHERE_TRACKING_ID, trackingId).post("channels?ccid=" + channelId);
    /* @formatter:on */
    assertEquals(201, /* Created */
    responseCreateChannel.getStatusCode());
    assertNotNull(responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID));
    String channelUrl = responseCreateChannel.getHeader(HEADER_LOCATION);
    String bpId = responseCreateChannel.getHeader(HEADER_BOUNCEPROXY_ID);
    String bpUrl = configuration.getBounceProxyUrl(bpId);
    assertThat(channelUrl, isChannelUrlwithJsessionId(bpUrl, channelId, SESSIONID_NAME));
    String sessionId = Utilities.getSessionId(channelUrl, SESSIONID_NAME);
    RestAssured.baseURI = Utilities.getUrlWithoutSessionId(channelUrl, SESSIONID_NAME);
    // post messages to long polling channel before opening channel
    byte[] expectedPayload = "message-123".getBytes(Charsets.UTF_8);
    byte[] serializedMessage = bpMock.createImmutableMessage(100000l, expectedPayload).getSerializedMessage();
    /* @formatter:off */
    Response responsePostMessage = given().when().contentType(ContentType.BINARY).body(serializedMessage).post("message" + SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(201, /* Created */
    responsePostMessage.getStatusCode());
    assertThat(responsePostMessage.getHeader(HEADER_LOCATION), isMessageUrlwithJsessionId(bpUrl, "message-123", sessionId, SESSIONID_NAME));
    assertEquals("message-123", responsePostMessage.getHeader(HEADER_MSG_ID));
    // open long polling channel
    /* @formatter:off */
    Response responseOpenChannel = given().when().contentType(ContentType.BINARY).header("X-Atmosphere-tracking-id", trackingId).get(SESSIONID_APPENDIX + sessionId);
    /* @formatter:on */
    assertEquals(200, /* OK */
    responseOpenChannel.getStatusCode());
    List<ImmutableMessage> messages = bpMock.getJoynrMessagesFromResponse(responseOpenChannel);
    assertEquals(1, messages.size());
    assertEquals(expectedPayload, messages.get(0).getUnencryptedBody());
}
Also used : Response(com.jayway.restassured.response.Response) ImmutableMessage(joynr.ImmutableMessage) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with ImmutableMessage

use of joynr.ImmutableMessage in project joynr by bmwcarit.

the class MessageWithoutContentTypeTest method testMixMessagesWithAndWithoutContentType.

@Test
public void testMixMessagesWithAndWithoutContentType() throws Exception {
    String channelId = "MessageWithoutContentTypeTest_" + UUID.randomUUID().toString();
    bpMock.createChannel(channelId);
    byte[] postPayload1 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    ImmutableMessage serializedMessage1 = bpMock.createImmutableMessage(100000l, postPayload1);
    given().contentType(ContentType.BINARY).content(serializedMessage1).log().all().expect().response().statusCode(201).header("Location", RestAssured.baseURI + "messages/" + serializedMessage1.getId()).header("msgId", serializedMessage1.getId()).when().post("/channels/" + channelId + "/messageWithoutContentType");
    byte[] postPayload2 = ("payload-" + UUID.randomUUID().toString()).getBytes(Charsets.UTF_8);
    ImmutableMessage immutableMessage2 = bpMock.createImmutableMessage(100000l, postPayload2);
    given().contentType(ContentType.BINARY).content(immutableMessage2.getSerializedMessage()).contentType("application/json").log().all().expect().response().statusCode(201).header("Location", RestAssured.baseURI + "messages/" + immutableMessage2.getId()).header("msgId", immutableMessage2.getId()).when().post("/channels/" + channelId + "/message");
    ScheduledFuture<Response> longPollConsumer = bpMock.longPollInOwnThread(channelId, 30000);
    Response responseLongPoll = longPollConsumer.get();
    List<ImmutableMessage> messagesFromResponse = bpMock.getJoynrMessagesFromResponse(responseLongPoll);
    Assert.assertEquals(2, messagesFromResponse.size());
    ImmutableMessage message = messagesFromResponse.get(0);
    Assert.assertEquals(postPayload1, message.getUnencryptedBody());
}
Also used : Response(com.jayway.restassured.response.Response) 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