Search in sources :

Example 16 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class StreamMessageCodecTest method testCodecWithOnlyData.

@Test
public void testCodecWithOnlyData() {
    ByteBuf dataBuf = copiedBuffer("{\"sessiontimerallowed\":1,\"losslimitallowed\":1}", UTF_8);
    StreamMessage src = StreamMessage.builder().qualifier((String) null).data(dataBuf).build();
    ByteBuf buf = StreamMessageCodec.encode(src);
    assertEquals("{\"data\":{\"sessiontimerallowed\":1,\"losslimitallowed\":1}}", buf.toString(UTF_8));
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 17 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseCrappyHeaders.

@Test
public void testParseCrappyHeaders() {
    List<String> get = ImmutableList.of("\"contextId\"", "\"q\"", "\"subject\"");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer(source, UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertNull(message.qualifier());
    assertNull(message.subject());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 18 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParseEscapedCharacters.

@Test
public void testParseEscapedCharacters() {
    List<String> get = ImmutableList.of("subject");
    List<String> match = Collections.emptyList();
    ByteBufCodec.decode(copiedBuffer("{\"subject\":\"\\\"quoted\\\"\"}", UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertEquals("Parsed string doesn't match source one", "\"quoted\"", message.subject());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 19 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testParse.

@Test
public void testParse() {
    List<String> get = ImmutableList.of("subject", "q");
    List<String> match = ImmutableList.of("data");
    ByteBufCodec.decode(copiedBuffer(source, UTF_8), get, match, consumer);
    StreamMessage message = messageBuilder.build();
    assertEquals("io'scalecube'services'transport'/Request/日本語", message.qualifier());
    assertEquals(SUBJECT, message.subject());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) Test(org.junit.Test)

Example 20 with StreamMessage

use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.

the class ByteBufCodecTest method testEncodeTwoFlatFieldsMessage.

@Test
public void testEncodeTwoFlatFieldsMessage() {
    StreamMessage message = StreamMessage.builder().qualifier("/cool/qalifier").subject("subject").build();
    ImmutableList<String> get = ImmutableList.of("q", "subject");
    List<String> match = Collections.emptyList();
    ByteBuf targetBuf = Unpooled.buffer();
    ByteBufCodec.encode(targetBuf, get, match, headerName -> {
        switch(headerName) {
            case QUALIFIER_NAME:
                return message.qualifier();
            case SUBJECT_NAME:
                return message.subject();
            default:
                // skip
                return null;
        }
    });
    StreamMessage.Builder builder = StreamMessage.builder();
    ByteBufCodec.decode(copiedBuffer(targetBuf), get, match, (headerName, obj) -> {
        switch(headerName) {
            case QUALIFIER_NAME:
                builder.qualifier((String) obj);
                break;
            case SUBJECT_NAME:
                builder.subject((String) obj);
                break;
            default:
        }
    });
    assertEquals(message, builder.build());
}
Also used : StreamMessage(io.scalecube.streams.StreamMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Aggregations

StreamMessage (io.scalecube.streams.StreamMessage)21 Test (org.junit.Test)21 ByteBuf (io.netty.buffer.ByteBuf)11