use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.
the class StreamMessageCodecTest method testCodecWithByteBufData.
@Test
public void testCodecWithByteBufData() {
ByteBuf dataBuf = copiedBuffer("{\"sessiontimerallowed\":1,\"losslimitallowed\":1}", UTF_8);
StreamMessage src = StreamMessage.builder().qualifier("q").subject("subject").data(dataBuf).build();
int ri = dataBuf.readerIndex();
ByteBuf buf = StreamMessageCodec.encode(src);
assertEquals("{\"q\":\"q\",\"subject\":\"subject\",\"data\":{\"sessiontimerallowed\":1,\"losslimitallowed\":1}}", buf.toString(UTF_8));
assertEquals(ri, dataBuf.readerIndex());
StreamMessage message = StreamMessageCodec.decode(buf.copy());
assertNotNull(message.data());
assertEquals("q", message.qualifier());
assertEquals("subject", message.subject());
assertEquals(dataBuf.toString(UTF_8), ((ByteBuf) message.data()).toString(UTF_8));
}
use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.
the class StreamMessageCodecTest method testCodecWithoutAnything.
@Test
public void testCodecWithoutAnything() {
StreamMessage src = StreamMessage.builder().build();
ByteBuf buf = StreamMessageCodec.encode(src);
assertEquals("{}", buf.toString(UTF_8));
ByteBuf buf1 = buf.copy();
int ri = buf1.readerIndex();
StreamMessage message = StreamMessageCodec.decode(buf1);
assertEquals(ri, buf1.readerIndex());
assertEquals(src, message);
}
use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.
the class StreamMessageCodecTest method testCodecWithoutData.
@Test
public void testCodecWithoutData() {
StreamMessage src = StreamMessage.builder().qualifier("q").subject("subject").build();
ByteBuf buf = StreamMessageCodec.encode(src);
assertEquals("{\"q\":\"q\",\"subject\":\"subject\"}", buf.toString(UTF_8));
ByteBuf buf1 = buf.copy();
int ri = buf1.readerIndex();
StreamMessage message = StreamMessageCodec.decode(buf1);
assertEquals(ri, buf1.readerIndex());
assertEquals(null, message.data());
}
use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.
the class StreamMessageCodecTest method testCodecWithByteBufDataNoJsonValidation.
@Test
public void testCodecWithByteBufDataNoJsonValidation() {
ByteBuf buf = copiedBuffer("{\"hello\"w{o{r{l{d", UTF_8);
int ri = buf.readerIndex();
StreamMessage msg = StreamMessage.builder().qualifier("q").subject("id0/id1/id/2").data(buf).build();
assertEquals("{\"q\":\"q\"," + "\"subject\":\"id0/id1/id/2\"," + "\"data\":{\"hello\"w{o{r{l{d}", StreamMessageCodec.encode(msg).toString(UTF_8));
assertEquals(ri, buf.readerIndex());
}
use of io.scalecube.streams.StreamMessage in project scalecube by scalecube.
the class ByteBufCodecTest method testParseEscapedHexSymbol.
@Test
public void testParseEscapedHexSymbol() {
List<String> get = ImmutableList.of("q", "subject");
List<String> match = Collections.emptyList();
ByteBufCodec.decode(copiedBuffer("{\"q\":\"\\uCEB1\\u0061\\u0063\\u006B\\uaef1\"," + "\"subject\":\"\\u0068\\u0061\\u0063\\u006b\"}", UTF_8), get, match, consumer);
StreamMessage message = messageBuilder.build();
assertEquals("Parsed string doesn't match source one", "캱ack껱", message.qualifier());
assertEquals("Parsed string doesn't match source one", "hack", message.subject());
}
Aggregations