@Test public void shouldEncodeDecodeCorrectly_PUT() { final int calculatedSize = MapPutCodec.RequestParameters.calculateDataSize(NAME, DATA, DATA, THE_LONG, THE_LONG); ClientMessage cmEncode = MapPutCodec.encodeRequest(NAME, DATA, DATA, THE_LONG, THE_LONG); cmEncode .setVersion((short) 3) .addFlag(ClientMessage.BEGIN_AND_END_FLAGS) .setCorrelationId(Long.MAX_VALUE) .setPartitionId(77); assertTrue(calculatedSize > cmEncode.getFrameLength()); byteBuffer = cmEncode.buffer(); ClientMessage cmDecode = ClientMessage.createForDecode(byteBuffer, 0); MapPutCodec.RequestParameters decodeParams = MapPutCodec.decodeRequest(cmDecode); assertEquals(MapPutCodec.REQUEST_TYPE.id(), cmDecode.getMessageType()); assertEquals(3, cmDecode.getVersion()); assertEquals(ClientMessage.BEGIN_AND_END_FLAGS, cmDecode.getFlags()); assertEquals(Long.MAX_VALUE, cmDecode.getCorrelationId()); assertEquals(77, cmDecode.getPartitionId()); assertEquals(NAME, decodeParams.name); assertEquals(DATA, decodeParams.key); assertEquals(DATA, decodeParams.value); assertEquals(THE_LONG, decodeParams.threadId); assertEquals(THE_LONG, decodeParams.ttl); }
protected void sendClientMessage(ClientMessage resultClientMessage) { resultClientMessage.setCorrelationId(clientMessage.getCorrelationId()); resultClientMessage.addFlag(ClientMessage.BEGIN_AND_END_FLAGS); resultClientMessage.setVersion(ClientMessage.VERSION); final Connection connection = endpoint.getConnection(); // TODO framing not implemented yet, should be split into frames before writing to connection connection.write(resultClientMessage); }
@Test public void testUnsignedFields() throws IOException { ClientProtocolBuffer buffer = new SafeBuffer(new byte[18]); ClientMessage cmEncode = ClientMessage.createForEncode(buffer, 0); cmEncode.setVersion((short) (Byte.MAX_VALUE + 10)); cmEncode.setMessageType(Short.MAX_VALUE + 10); cmEncode.setDataOffset((int) Short.MAX_VALUE + 10); cmEncode.setCorrelationId(Short.MAX_VALUE + 10); ClientMessage cmDecode = ClientMessage.createForDecode(buffer, 0); assertEquals(Byte.MAX_VALUE + 10, cmDecode.getVersion()); assertEquals(Short.MAX_VALUE + 10, cmDecode.getMessageType()); assertEquals((int) Short.MAX_VALUE + 10, cmDecode.getDataOffset()); }