Search in sources :

Example 6 with HandlerStatus

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());
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) Frame(com.hazelcast.client.impl.protocol.ClientMessage.Frame) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with HandlerStatus

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);
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) Iterator(java.util.Iterator) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with HandlerStatus

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);
}
Also used : Address(com.hazelcast.cluster.Address) MemberImpl(com.hazelcast.cluster.impl.MemberImpl) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) UUID(java.util.UUID) Member(com.hazelcast.cluster.Member) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with HandlerStatus

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);
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) MapPutCodec(com.hazelcast.client.impl.protocol.codec.MapPutCodec) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HeapData(com.hazelcast.internal.serialization.impl.HeapData) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with HandlerStatus

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());
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ByteBuffer(java.nio.ByteBuffer) LinkedList(java.util.LinkedList) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) ClientAuthenticationCodec(com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)13 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)11 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)9 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 UUID (java.util.UUID)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 ClientAuthenticationCodec (com.hazelcast.client.impl.protocol.codec.ClientAuthenticationCodec)2 Packet (com.hazelcast.internal.nio.Packet)2 HeapData (com.hazelcast.internal.serialization.impl.HeapData)2 LinkedList (java.util.LinkedList)2 Frame (com.hazelcast.client.impl.protocol.ClientMessage.Frame)1 MapPutCodec (com.hazelcast.client.impl.protocol.codec.MapPutCodec)1 Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 MemberImpl (com.hazelcast.cluster.impl.MemberImpl)1 InboundHandler (com.hazelcast.internal.networking.InboundHandler)1 OutboundHandler (com.hazelcast.internal.networking.OutboundHandler)1