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);
}
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;
}
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);
}
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());
}
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());
}
Aggregations