use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method randomData.
private HeapData randomData() {
Random random = new Random();
byte[] key = new byte[100];
random.nextBytes(key);
return new HeapData(key);
}
use of com.hazelcast.internal.serialization.impl.HeapData 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.serialization.impl.HeapData 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.serialization.impl.HeapData in project hazelcast by hazelcast.
the class AbstractValueComparatorTest method init.
@Before
public final void init() {
serializationService = createSerializationService();
partitioningStrategy = new DefaultPartitioningStrategy();
object1 = new Person("Alice");
object2 = new Person("Bob");
data1 = serializationService.toData(object1);
data2 = serializationService.toData(object2);
nullData = new HeapData(new byte[0]);
}
use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.
the class BufferPoolTest method takeInputBuffer_whenNestedInstance.
@Test
public void takeInputBuffer_whenNestedInstance() {
Data data = new HeapData(new byte[] {});
BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
assertNotSame(found1, found2);
}
Aggregations