Search in sources :

Example 11 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class BufferPoolTest method takeInputBuffer_whenPooledInstance.

// ======================= in ==========================================
@Test
public void takeInputBuffer_whenPooledInstance() {
    Data data = new HeapData(new byte[] {});
    BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
    bufferPool.returnInputBuffer(found1);
    BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
    assertSame(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)

Example 12 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class NearCachePreloader method loadKeySet.

private int loadKeySet(BufferingInputStream bis, DataStructureAdapter<Data, ?> adapter) throws IOException {
    int loadedKeys = 0;
    Builder<Data> builder = InflatableSet.newBuilder(LOAD_BATCH_SIZE);
    while (readFullyOrNothing(bis, tmpBytes)) {
        int dataSize = readIntB(tmpBytes, 0);
        byte[] payload = new byte[dataSize];
        if (!readFullyOrNothing(bis, payload)) {
            break;
        }
        builder.add(new HeapData(payload));
        if (builder.size() == LOAD_BATCH_SIZE) {
            adapter.getAll(builder.build());
            builder = InflatableSet.newBuilder(LOAD_BATCH_SIZE);
        }
        loadedKeys++;
    }
    if (builder.size() > 0) {
        adapter.getAll(builder.build());
    }
    return loadedKeys;
}
Also used : HeapData(com.hazelcast.internal.serialization.impl.HeapData) Data(com.hazelcast.nio.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData)

Example 13 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class StringSerializationTest method testLargeStringEncodeDecode.

@Test
public void testLargeStringEncodeDecode() {
    StringBuilder sb = new StringBuilder();
    int i = 0, j = 0;
    while (j < TEST_STR_SIZE) {
        int ch = i++ % Character.MAX_VALUE;
        if (Character.isLetter(ch)) {
            sb.append(ch);
            j++;
        }
    }
    String actualStr = sb.toString();
    byte[] strBytes = actualStr.getBytes(Charset.forName("utf8"));
    byte[] actualDataBytes = serializationService.toBytes(actualStr);
    byte[] expectedDataByte = toDataByte(strBytes, actualStr.length());
    String decodedStr = serializationService.toObject(new HeapData(expectedDataByte));
    assertArrayEquals("Deserialized byte array do not match utf-8 encoding", expectedDataByte, actualDataBytes);
    assertEquals(decodedStr, actualStr);
}
Also used : HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class SerializationTest method testNullData.

@Test
public void testNullData() {
    Data data = new HeapData();
    SerializationService ss = new DefaultSerializationServiceBuilder().build();
    assertNull(ss.toObject(data));
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with HeapData

use of com.hazelcast.internal.serialization.impl.HeapData in project hazelcast by hazelcast.

the class DataRecordFactoryTest method setUp.

@Before
public void setUp() {
    mockSerializationService = mock(SerializationService.class);
    mockPartitioningStrategy = mock(PartitioningStrategy.class);
    object = new Object();
    data = new HeapData();
    when(mockSerializationService.toData(object, mockPartitioningStrategy)).thenReturn(data);
}
Also used : PartitioningStrategy(com.hazelcast.core.PartitioningStrategy) SerializationService(com.hazelcast.spi.serialization.SerializationService) HeapData(com.hazelcast.internal.serialization.impl.HeapData) Before(org.junit.Before)

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