use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method test.
@Test
public void test() {
ClientMessage message = ClientMessage.createForEncode();
message.add(new Frame(new byte[100], UNFRAGMENTED_MESSAGE | IS_FINAL_FLAG));
message.setMessageType(MapPutCodec.REQUEST_MESSAGE_TYPE);
AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> reference.getAndSet(null));
ByteBuffer buffer = ByteBuffer.allocate(1000);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
}
use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method testFragmentedMessageHandling.
@Test
public void testFragmentedMessageHandling() {
ClientMessage message = createMessage(10, 9);
List<ClientMessage> fragments = getFragments(48, message);
assertEquals(3, fragments.size());
AtomicReference<Iterator<ClientMessage>> reference = new AtomicReference<>(fragments.iterator());
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> {
Iterator<ClientMessage> iterator = reference.get();
if (iterator.hasNext()) {
return iterator.next();
}
return null;
});
ByteBuffer buffer = ByteBuffer.allocate(200);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessageRef = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessageRef::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
ClientMessage resultingMessage = resultingMessageRef.get();
assertEquals(message.getFrameLength(), resultingMessage.getFrameLength());
ClientMessage.ForwardFrameIterator expectedIterator = message.frameIterator();
ClientMessage.ForwardFrameIterator resultingIterator = resultingMessage.frameIterator();
while (expectedIterator.hasNext()) {
assertArrayEquals(expectedIterator.next().content, resultingIterator.next().content);
}
}
use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method testAuthenticationResponse.
@Test
public void testAuthenticationResponse() throws UnknownHostException {
Collection<Member> members = new LinkedList<>();
Address address1 = new Address("127.0.0.1", 5702);
members.add(new MemberImpl(address1, MemberVersion.of("3.12"), false, UUID.randomUUID()));
Address address2 = new Address("127.0.0.1", 5703);
members.add(new MemberImpl(address2, MemberVersion.of("3.12"), false, UUID.randomUUID()));
UUID uuid = UUID.randomUUID();
UUID clusterId = UUID.randomUUID();
ClientMessage message = ClientAuthenticationCodec.encodeResponse((byte) 2, new Address("127.0.0.1", 5701), uuid, (byte) 1, "3.12", 271, clusterId, true);
AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> reference.getAndSet(null));
ByteBuffer buffer = ByteBuffer.allocate(1000);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
ClientAuthenticationCodec.ResponseParameters parameters = ClientAuthenticationCodec.decodeResponse(resultingMessage.get());
assertEquals(2, parameters.status);
assertEquals(new Address("127.0.0.1", 5701), parameters.address);
assertEquals(uuid, parameters.memberUuid);
assertEquals(1, parameters.serializationVersion);
assertEquals("3.12", parameters.serverHazelcastVersion);
assertEquals(271, parameters.partitionCount);
assertEquals(clusterId, parameters.clusterId);
assertEquals(true, parameters.failoverSupported);
}
use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method testPut.
@Test
public void testPut() {
ClientMessage message = MapPutCodec.encodeRequest("map", new HeapData(new byte[100]), new HeapData(new byte[100]), 5, 10);
AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> reference.getAndSet(null));
ByteBuffer buffer = ByteBuffer.allocate(1000);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
MapPutCodec.RequestParameters parameters = MapPutCodec.decodeRequest(resultingMessage.get());
assertEquals(5, parameters.threadId);
assertEquals("map", parameters.name);
}
use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method testAuthenticationRequest.
@Test
public void testAuthenticationRequest() {
Collection<String> labels = new LinkedList<>();
labels.add("Label");
UUID uuid = UUID.randomUUID();
ClientMessage message = ClientAuthenticationCodec.encodeRequest("cluster", "user", "pass", uuid, "JAVA", (byte) 1, "1.0", "name", labels);
AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> reference.getAndSet(null));
ByteBuffer buffer = ByteBuffer.allocate(1000);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
ClientAuthenticationCodec.RequestParameters parameters = ClientAuthenticationCodec.decodeRequest(resultingMessage.get());
assertEquals("cluster", parameters.clusterName);
assertEquals("user", parameters.username);
assertEquals("pass", parameters.password);
assertEquals(uuid, parameters.uuid);
assertEquals("JAVA", parameters.clientType);
assertEquals((byte) 1, parameters.serializationVersion);
assertEquals("1.0", parameters.clientHazelcastVersion);
assertEquals("name", parameters.clientName);
assertArrayEquals(labels.toArray(), parameters.labels.toArray());
}
Aggregations