Search in sources :

Example 36 with ClientMessage

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

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword.

@Test
public void testAuthenticateWithUsernameAndPassword() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, InternalSerializationService.VERSION_1, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertTrue(clientMessage.isComplete());
    ClientMessage cmResult = ClientMessage.createForDecode(clientMessage.buffer(), 0);
    ClientAuthenticationCodec.ResponseParameters resultParameters = ClientAuthenticationCodec.decodeResponse(cmResult);
    assertEquals(cmResult.getCorrelationId(), 1);
    assertEquals(resultParameters.status, 0);
    assertEquals(resultParameters.serializationVersion, 1);
    assertEquals(resultParameters.ownerUuid, server.getCluster().getLocalMember().getUuid());
    assertNotNull(UUID.fromString(resultParameters.uuid));
    assertEquals(server.getCluster().getLocalMember().getAddress(), resultParameters.address);
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 37 with ClientMessage

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

the class RawProtocolAuthenticationTest method readMessageFromChannel.

private ClientMessage readMessageFromChannel() throws IOException {
    final ByteBuffer socketBuffer = ByteBuffer.allocate(4096);
    ClientMessage clientMessage = ClientMessage.create();
    do {
        int read = channel.read(socketBuffer);
        if (read <= 0) {
            if (read == -1) {
                break;
            }
            continue;
        }
        socketBuffer.flip();
        clientMessage.readFrom(socketBuffer);
        if (socketBuffer.hasRemaining()) {
            socketBuffer.compact();
        } else {
            socketBuffer.clear();
        }
    } while (!clientMessage.isComplete());
    return clientMessage;
}
Also used : ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer)

Example 38 with ClientMessage

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

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword_with_Invalid_SerializationVersion.

@Test
public void testAuthenticateWithUsernameAndPassword_with_Invalid_SerializationVersion() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, (byte) 0, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertTrue(clientMessage.isComplete());
    ClientMessage cmResult = ClientMessage.createForDecode(clientMessage.buffer(), 0);
    ClientAuthenticationCodec.ResponseParameters resultParameters = ClientAuthenticationCodec.decodeResponse(cmResult);
    assertEquals(cmResult.getCorrelationId(), 1);
    assertEquals(resultParameters.status, 2);
    assertEquals(resultParameters.serializationVersion, 1);
    assertNull(resultParameters.ownerUuid);
    assertNull(resultParameters.uuid);
    assertNull(resultParameters.address);
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with ClientMessage

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

the class RawProtocolAuthenticationTest method testAuthenticateWithUsernameAndPassword_with_Invalid_MessageSize.

@Test
public void testAuthenticateWithUsernameAndPassword_with_Invalid_MessageSize() throws IOException, InterruptedException {
    final ByteBuffer initData = ByteBuffer.wrap("CB2".getBytes());
    channel.write(initData);
    String username = GroupConfig.DEFAULT_GROUP_NAME;
    String pass = GroupConfig.DEFAULT_GROUP_PASSWORD;
    final ClientMessage authMessage = ClientAuthenticationCodec.encodeRequest(username, pass, null, null, true, ClientTypes.JAVA, (byte) 0, BuildInfoProvider.BUILD_INFO.getVersion());
    authMessage.setCorrelationId(1).addFlag(ClientMessage.BEGIN_AND_END_FLAGS);
    //set invalid message size
    authMessage.setFrameLength(ClientMessage.HEADER_SIZE - 1);
    final ClientProtocolBuffer byteBuffer = authMessage.buffer();
    channel.write(ByteBuffer.wrap(byteBuffer.byteArray(), 0, authMessage.getFrameLength()));
    ClientMessage clientMessage = readMessageFromChannel();
    assertFalse(clientMessage.isComplete());
}
Also used : ClientProtocolBuffer(com.hazelcast.client.impl.protocol.util.ClientProtocolBuffer) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 40 with ClientMessage

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

the class ClientMessageAccumulatorTest method shouldNotAccumulateInCompleteFrameSize.

@Test
public void shouldNotAccumulateInCompleteFrameSize() {
    ClientMessage accumulator = ClientMessage.create();
    final byte[] array = new byte[] { 1, 2, 3 };
    final ByteBuffer inBuffer = ByteBuffer.wrap(array);
    assertFalse(accumulator.readFrom(inBuffer));
    assertFalse(accumulator.isComplete());
}
Also used : ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) 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