Search in sources :

Example 1 with HeapData

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

the class ReadManyOperationTest method whenEnoughItemsAvailableAndReturnPortable.

@Test
public void whenEnoughItemsAvailableAndReturnPortable() throws Exception {
    long startSequence = ringbuffer.tailSequence() + 1;
    ReadManyOperation op = new ReadManyOperation(ringbuffer.getName(), startSequence, 1, 3, null, true);
    op.setNodeEngine(nodeEngine);
    ringbuffer.add("item1");
    ringbuffer.add("item2");
    ringbuffer.add("item3");
    ringbuffer.add("item4");
    ringbuffer.add("item5");
    assertFalse(op.shouldWait());
    HeapData response = assertInstanceOf(HeapData.class, op.getResponse());
    PortableReadResultSet readResultSet = serializationService.toObject(response);
    assertEquals(startSequence + 3, op.sequence);
    assertEquals(3, readResultSet.readCount());
    assertEquals(3, readResultSet.getDataItems().size());
    readResultSet.setSerializationService(serializationService);
    assertIterableEquals(readResultSet, "item1", "item2", "item3");
}
Also used : PortableReadResultSet(com.hazelcast.ringbuffer.impl.client.PortableReadResultSet) HeapData(com.hazelcast.internal.serialization.impl.HeapData) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with HeapData

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

the class StringSerializationTest method testStringAllCharLetterDecode.

@Test
public void testStringAllCharLetterDecode() {
    String allStr = new String(allChars);
    byte[] expected = allStr.getBytes(Charset.forName("utf8"));
    Data data = new HeapData(toDataByte(expected, allStr.length()));
    String actualStr = serializationService.toObject(data);
    assertEquals(allStr, actualStr);
}
Also used : 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 3 with HeapData

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

the class StringSerializationTest method testStringDecode.

@Test
public void testStringDecode() {
    Data data = new HeapData(toDataByte(TEST_DATA_BYTES_ALL, TEST_DATA_ALL.length()));
    String actualStr = serializationService.toObject(data);
    assertEquals(TEST_DATA_ALL, actualStr);
}
Also used : 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 4 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<Object, ?> adapter) throws IOException {
    int loadedKeys = 0;
    Builder<Object> 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;
        }
        Data key = new HeapData(payload);
        builder.add(serializationService.toObject(key));
        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.internal.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData)

Example 5 with HeapData

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

the class QueueStoreWrapper method loadAll.

@Override
public Map<Long, Data> loadAll(Collection<Long> keys) {
    if (!enabled) {
        return null;
    }
    Map<Long, ?> map = store.loadAll(keys);
    if (map == null) {
        return Collections.emptyMap();
    }
    Map<Long, Data> dataMap = createHashMap(map.size());
    if (binary) {
        for (Map.Entry<Long, ?> entry : map.entrySet()) {
            byte[] dataBuffer = (byte[]) entry.getValue();
            Data data = new HeapData(Arrays.copyOf(dataBuffer, dataBuffer.length));
            dataMap.put(entry.getKey(), data);
        }
    } else {
        for (Map.Entry<Long, ?> entry : map.entrySet()) {
            dataMap.put(entry.getKey(), serializationService.toData(entry.getValue()));
        }
    }
    return dataMap;
}
Also used : Data(com.hazelcast.internal.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map)

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