Search in sources :

Example 21 with Message

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());
}
Also used : Message(herddb.network.Message) HashMap(java.util.HashMap) DataAccessor(herddb.utils.DataAccessor) MapDataAccessor(herddb.utils.MapDataAccessor) ArrayList(java.util.ArrayList) RawString(herddb.utils.RawString) ByteBuf(io.netty.buffer.ByteBuf) MapDataAccessor(herddb.utils.MapDataAccessor) TuplesList(herddb.utils.TuplesList) Test(org.junit.Test)

Example 22 with Message

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);
}
Also used : Message(herddb.network.Message)

Aggregations

Message (herddb.network.Message)22 StatementExecutionException (herddb.model.StatementExecutionException)10 NotLeaderException (herddb.model.NotLeaderException)9 ArrayList (java.util.ArrayList)9 TuplesList (herddb.utils.TuplesList)8 HerdDBInternalException (herddb.core.HerdDBInternalException)7 DataScannerException (herddb.model.DataScannerException)7 DuplicatePrimaryKeyException (herddb.model.DuplicatePrimaryKeyException)7 List (java.util.List)7 AtomicLong (java.util.concurrent.atomic.AtomicLong)7 HashMap (java.util.HashMap)6 Table (herddb.model.Table)5 Record (herddb.model.Record)4 TransactionContext (herddb.model.TransactionContext)4 SQLPlannedOperationStatement (herddb.model.commands.SQLPlannedOperationStatement)4 ScanStatement (herddb.model.commands.ScanStatement)4 Channel (herddb.network.Channel)4 KeyValue (herddb.network.KeyValue)4 DataAccessor (herddb.utils.DataAccessor)4 Map (java.util.Map)4