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