use of herddb.network.Message in project herddb by diennea.
the class MessageUtilsTest method testEncodeMessage.
@Test
public void testEncodeMessage() {
final String clientId = "2331";
System.out.println("encodeMessage");
ByteBuf buffer = Unpooled.buffer();
Map<String, Object> payload = new HashMap<>();
payload.put("string", "value");
payload.put("int", 1234);
payload.put("long", 12345L);
payload.put("rawstring", RawString.of("value"));
payload.put("list", Arrays.asList("foo", "bar"));
payload.put("set", new HashSet<>(Arrays.asList("foo", "bar")));
String[] colNames = { "one", "null", "two", "notfound" };
List<DataAccessor> records = new ArrayList<>();
Map<String, Object> record1 = new HashMap<>();
record1.put("one", 1234);
record1.put("two", RawString.of("test"));
records.add(new MapDataAccessor(record1, colNames));
Map<String, Object> record2 = new HashMap<>();
record2.put("one", 2234);
record2.put("two", RawString.of("test2"));
record2.put("null", null);
records.add(new MapDataAccessor(record2, colNames));
TuplesList tl = new TuplesList(colNames, records);
payload.put("data", tl);
Message m = new Message(clientId, 1234, payload);
m.assignMessageId();
m.setReplyMessageId("2343");
MessageUtils.encodeMessage(buffer, m);
Message read = MessageUtils.decodeMessage(buffer);
assertEquals(read.clientId, m.clientId);
assertEquals(read.messageId, m.messageId);
assertEquals(read.replyMessageId, m.replyMessageId);
assertEquals(read.type, m.type);
assertEquals(read.parameters.size(), m.parameters.size());
read.parameters.forEach((String k, Object v) -> {
Object o = m.parameters.get(k);
assertEquals(o, v);
});
TuplesList tl2 = (TuplesList) read.parameters.get("data");
assertEquals(4, tl2.tuples.get(0).getValues().length);
assertArrayEquals(colNames, tl2.tuples.get(0).getFieldNames());
assertEquals(4, tl2.tuples.get(1).getValues().length);
assertArrayEquals(colNames, tl2.tuples.get(1).getFieldNames());
}
use of herddb.network.Message in project herddb by diennea.
the class InboundMessageHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
Message message = (Message) msg;
session.messageReceived(message);
}
Aggregations