Search in sources :

Example 41 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageSplitAndBuildTest method splitTest_checkSize.

@Test
public void splitTest_checkSize() {
    int FRAME_SIZE = 50;
    String s = UUID.randomUUID().toString();
    ClientMessage clientMessage = ClientAuthenticationCodec.encodeRequest(s, s, s, s, true, s, (byte) 1, BuildInfoProvider.BUILD_INFO.getVersion());
    clientMessage.addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    List<ClientMessage> subFrames = ClientMessageSplitter.getSubFrames(FRAME_SIZE, clientMessage);
    for (int i = 0; i < subFrames.size() - 1; i++) {
        assertEquals(FRAME_SIZE, subFrames.get(i).getFrameLength());
    }
    assertTrue(subFrames.get(subFrames.size() - 1).getFrameLength() <= FRAME_SIZE);
}
Also used : ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 42 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageTest method shouldEncodeWithNewVersionAndDecodeWithOldVersionCorrectly_withPayLoadData.

@Test
public void shouldEncodeWithNewVersionAndDecodeWithOldVersionCorrectly_withPayLoadData() throws UnsupportedEncodingException {
    SafeBuffer byteBuffer = new SafeBuffer(new byte[1024]);
    FutureClientMessage cmEncode = new FutureClientMessage();
    cmEncode.wrapForEncode(byteBuffer, 0);
    cmEncode.theNewField(999).setMessageType(7).setVersion((short) 3).addFlag(ClientMessage.BEGIN_AND_END_FLAGS).setCorrelationId(66).setPartitionId(77);
    final int calculatedFrameSize = FutureClientMessage.THE_NEW_HEADER_SIZE + ParameterUtil.calculateDataSize(BYTE_DATA);
    cmEncode.set(BYTE_DATA);
    cmEncode.updateFrameLength();
    ClientMessage cmDecode = ClientMessage.createForDecode(byteBuffer, 0);
    final byte[] cmDecodeVarData1 = cmDecode.getByteArray();
    assertEquals(7, cmDecode.getMessageType());
    assertEquals(3, cmDecode.getVersion());
    assertEquals(ClientMessage.BEGIN_AND_END_FLAGS, cmDecode.getFlags());
    assertEquals(66, cmDecode.getCorrelationId());
    assertEquals(77, cmDecode.getPartitionId());
    assertEquals(calculatedFrameSize, cmDecode.getFrameLength());
    assertArrayEquals(cmDecodeVarData1, BYTE_DATA);
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 43 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageTest method shouldEncodeWithOldVersionAndDecodeWithNewVersionCorrectly_withPayLoadData.

@Test
public void shouldEncodeWithOldVersionAndDecodeWithNewVersionCorrectly_withPayLoadData() throws UnsupportedEncodingException {
    SafeBuffer byteBuffer = new SafeBuffer(new byte[1024]);
    ClientMessage cmEncode = TestClientMessage.createForEncode(byteBuffer, 0);
    cmEncode.setMessageType(7).setVersion((short) 3).addFlag(ClientMessage.BEGIN_AND_END_FLAGS).setCorrelationId(66).setPartitionId(77);
    final int calculatedFrameSize = ClientMessage.HEADER_SIZE + ParameterUtil.calculateDataSize(BYTE_DATA);
    cmEncode.set(BYTE_DATA);
    cmEncode.updateFrameLength();
    ClientMessage cmDecode = FutureClientMessage.createForDecode(byteBuffer, 0);
    final byte[] cmDecodeVarData1 = cmDecode.getByteArray();
    assertEquals(7, cmDecode.getMessageType());
    assertEquals(3, cmDecode.getVersion());
    assertEquals(ClientMessage.BEGIN_AND_END_FLAGS, cmDecode.getFlags());
    assertEquals(66, cmDecode.getCorrelationId());
    assertEquals(77, cmDecode.getPartitionId());
    assertEquals(calculatedFrameSize, cmDecode.getFrameLength());
    assertArrayEquals(cmDecodeVarData1, BYTE_DATA);
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageTest method shouldEncodeAndDecodeClientMessageCorrectly_withPayLoadData_multipleMessages.

@Test
public void shouldEncodeAndDecodeClientMessageCorrectly_withPayLoadData_multipleMessages() throws UnsupportedEncodingException {
    SafeBuffer byteBuffer = new SafeBuffer(new byte[1024]);
    ClientMessage cmEncode = TestClientMessage.createForEncode(byteBuffer, 0);
    cmEncode.setMessageType(7).setVersion((short) 3).addFlag(ClientMessage.BEGIN_AND_END_FLAGS).setCorrelationId(1).setPartitionId(77);
    cmEncode.set(BYTE_DATA);
    cmEncode.updateFrameLength();
    final int calculatedFrame1Size = ClientMessage.HEADER_SIZE + ParameterUtil.calculateDataSize(BYTE_DATA);
    final int nexMessageOffset = cmEncode.getFrameLength();
    ClientMessage cmEncode2 = TestClientMessage.createForEncode(byteBuffer, nexMessageOffset);
    cmEncode2.setMessageType(7).setVersion((short) 3).addFlag(ClientMessage.BEGIN_AND_END_FLAGS).setCorrelationId(2).setPartitionId(77);
    cmEncode2.set(BYTE_DATA);
    cmEncode2.updateFrameLength();
    final int calculatedFrame2Size = ClientMessage.HEADER_SIZE + ParameterUtil.calculateDataSize(BYTE_DATA);
    ClientMessage cmDecode1 = ClientMessage.createForDecode(byteBuffer, 0);
    final byte[] cmDecodeVarData = cmDecode1.getByteArray();
    assertEquals(7, cmDecode1.getMessageType());
    assertEquals(3, cmDecode1.getVersion());
    assertEquals(ClientMessage.BEGIN_AND_END_FLAGS, cmDecode1.getFlags());
    assertEquals(1, cmDecode1.getCorrelationId());
    assertEquals(77, cmDecode1.getPartitionId());
    assertEquals(calculatedFrame1Size, cmDecode1.getFrameLength());
    assertArrayEquals(cmDecodeVarData, BYTE_DATA);
    ClientMessage cmDecode2 = ClientMessage.createForDecode(byteBuffer, cmDecode1.getFrameLength());
    byte[] cmDecodeVarData2 = cmDecode2.getByteArray();
    assertEquals(7, cmDecode2.getMessageType());
    assertEquals(3, cmDecode2.getVersion());
    assertEquals(ClientMessage.BEGIN_AND_END_FLAGS, cmDecode2.getFlags());
    assertEquals(2, cmDecode2.getCorrelationId());
    assertEquals(77, cmDecode2.getPartitionId());
    assertEquals(calculatedFrame2Size, cmDecode2.getFrameLength());
    assertArrayEquals(cmDecodeVarData2, BYTE_DATA);
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with ClientMessage

use of com.hazelcast.client.impl.protocol.ClientMessage in project hazelcast by hazelcast.

the class ClientMessageTest method shouldEncodeAndDecodeClientMessageCorrectly_withPayLoadData_fromOffset.

@Test
public void shouldEncodeAndDecodeClientMessageCorrectly_withPayLoadData_fromOffset() throws UnsupportedEncodingException {
    SafeBuffer byteBuffer = new SafeBuffer(new byte[150]);
    int offset = 100;
    ClientMessage cmEncode = TestClientMessage.createForEncode(byteBuffer, offset);
    cmEncode.setMessageType(7).setVersion((short) 3).addFlag(ClientMessage.BEGIN_AND_END_FLAGS).setCorrelationId(66).setPartitionId(77);
    byte[] bytes = VAR_DATA_STR_1.getBytes();
    final int calculatedFrameSize = ClientMessage.HEADER_SIZE + Bits.INT_SIZE_IN_BYTES + ParameterUtil.calculateDataSize(bytes);
    cmEncode.set(1);
    cmEncode.set(bytes);
    cmEncode.updateFrameLength();
    ClientMessage cmDecode = ClientMessage.createForDecode(byteBuffer, offset);
    assertEquals(1, cmDecode.getInt());
    assertArrayEquals(bytes, cmDecode.getByteArray());
    assertEquals(calculatedFrameSize, cmDecode.getFrameLength());
}
Also used : SafeBuffer(com.hazelcast.client.impl.protocol.util.SafeBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)377 Data (com.hazelcast.nio.serialization.Data)140 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)47 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)37 SafeBuffer (com.hazelcast.client.impl.protocol.util.SafeBuffer)29 Address (com.hazelcast.nio.Address)25 QuickTest (com.hazelcast.test.annotation.QuickTest)24 Test (org.junit.Test)24 ClientDelegatingFuture (com.hazelcast.client.util.ClientDelegatingFuture)21 DataInputStream (java.io.DataInputStream)20 InputStream (java.io.InputStream)20 CacheEventData (com.hazelcast.cache.impl.CacheEventData)19 ParallelTest (com.hazelcast.test.annotation.ParallelTest)19 Member (com.hazelcast.core.Member)18 SerializationService (com.hazelcast.spi.serialization.SerializationService)18 ExecutionException (java.util.concurrent.ExecutionException)18 UnmodifiableLazyList (com.hazelcast.spi.impl.UnmodifiableLazyList)16 ArrayList (java.util.ArrayList)16 QueryCacheEventData (com.hazelcast.map.impl.querycache.event.QueryCacheEventData)13 CacheException (javax.cache.CacheException)13