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