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