Search in sources :

Example 11 with HandlerStatus

use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.

the class ClientMessageEncoderDecoderTest method testEvent.

@Test
public void testEvent() {
    HeapData keyData = randomData();
    HeapData valueData = randomData();
    UUID uuid = UUID.randomUUID();
    ClientMessage message = MapAddEntryListenerCodec.encodeEntryEvent(keyData, valueData, null, null, 1, uuid, 1);
    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());
    EventHandler eventHandler = new EventHandler();
    eventHandler.handle(resultingMessage.get());
    assertEquals(keyData, eventHandler.key);
    assertEquals(valueData, eventHandler.value);
    assertEquals(1, eventHandler.eventType);
    assertEquals(uuid, eventHandler.uuid);
    assertEquals(1, eventHandler.numberOfAffectedEntries);
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) HeapData(com.hazelcast.internal.serialization.impl.HeapData) UUID(java.util.UUID) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with HandlerStatus

use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.

the class ClientMessageSplitAndBuildTest method splitAndBuild_whenMessageIsAlreadySmallerThanFrameSize.

@Test
public void splitAndBuild_whenMessageIsAlreadySmallerThanFrameSize() {
    Queue<ClientMessage> outputQueue = new ConcurrentLinkedQueue<>();
    List<ClientMessage> fragments = getFragments(100000, clientMessage1);
    for (ClientMessage fragment : fragments) {
        outputQueue.offer(fragment);
    }
    ClientMessageEncoder encoder = new ClientMessageEncoder();
    encoder.src(outputQueue::poll);
    ByteBuffer buffer = ByteBuffer.allocate(100000);
    upcast(buffer).flip();
    encoder.dst(buffer);
    HandlerStatus result = encoder.onWrite();
    Assert.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(clientMessage1.getFrameLength(), resultingMessage.get().getFrameLength());
    assertEquals(0, decoder.builderBySessionIdMap.size());
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with HandlerStatus

use of com.hazelcast.internal.networking.HandlerStatus in project hazelcast by hazelcast.

the class ClientMessageSplitAndBuildTest method splitAndBuild.

@Test
public void splitAndBuild() {
    Queue<ClientMessage> outputQueue = new ConcurrentLinkedQueue<>();
    List<ClientMessage> fragments = getFragments(128, clientMessage1);
    for (ClientMessage fragment : fragments) {
        outputQueue.offer(fragment);
    }
    ClientMessageEncoder encoder = new ClientMessageEncoder();
    encoder.src(outputQueue::poll);
    ByteBuffer buffer = ByteBuffer.allocate(100000);
    upcast(buffer).flip();
    encoder.dst(buffer);
    HandlerStatus result = encoder.onWrite();
    Assert.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(getNumberOfFrames(clientMessage1), getNumberOfFrames(resultingMessage.get()));
    assertEquals(clientMessage1.getFrameLength(), resultingMessage.get().getFrameLength());
    assertEquals(0, decoder.builderBySessionIdMap.size());
}
Also used : HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ByteBuffer(java.nio.ByteBuffer) 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