Search in sources :

Example 16 with HeapData

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);
}
Also used : Random(java.util.Random) HeapData(com.hazelcast.internal.serialization.impl.HeapData)

Example 17 with HeapData

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);
}
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 18 with HeapData

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);
}
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 19 with HeapData

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]);
}
Also used : DefaultPartitioningStrategy(com.hazelcast.partition.strategy.DefaultPartitioningStrategy) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Person(com.hazelcast.map.impl.record.Person) Before(org.junit.Before)

Example 20 with HeapData

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);
}
Also used : Data(com.hazelcast.internal.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

HeapData (com.hazelcast.internal.serialization.impl.HeapData)28 QuickTest (com.hazelcast.test.annotation.QuickTest)18 Test (org.junit.Test)18 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)13 Matchers.anyObject (org.mockito.Matchers.anyObject)7 Data (com.hazelcast.internal.serialization.Data)6 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)2 Packet (com.hazelcast.internal.nio.Packet)2 SerializationService (com.hazelcast.spi.serialization.SerializationService)2 ByteBuffer (java.nio.ByteBuffer)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Before (org.junit.Before)2 MapPutCodec (com.hazelcast.client.impl.protocol.codec.MapPutCodec)1 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)1 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)1 MapUtil.createHashMap (com.hazelcast.internal.util.MapUtil.createHashMap)1 CustomByteArrayOutputStream (com.hazelcast.jet.impl.util.AsyncSnapshotWriterImpl.CustomByteArrayOutputStream)1 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)1