use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class AsyncSnapshotWriterImplTest method when_singleLargeEntry_then_flushedImmediatelyAndDeserializesCorrectly.
@Test
public void when_singleLargeEntry_then_flushedImmediatelyAndDeserializesCorrectly() throws IOException {
// When
String key = "k";
String value = generate(() -> "a").limit(128).collect(joining());
Entry<Data, Data> entry = entry(serialize(key), serialize(value));
assertTrue("entry not longer than usable chunk size", serializedLength(entry) > writer.usableChunkCapacity);
assertTrue(writer.offer(entry));
// Then
assertTargetMapEntry(key, 0, serializedLength(entry));
assertEquals(1, writer.getTotalChunks());
assertEquals(1, writer.getTotalKeys());
// Then2 - try to deserialize the entry
int partitionKey = writer.partitionKey(partitionService.getPartitionId(key));
byte[] data = map.get(new SnapshotDataKey(partitionKey, 1, "vertex", 0));
assertEquals(data.length + Bits.INT_SIZE_IN_BYTES, writer.getTotalPayloadBytes());
BufferObjectDataInput in = serializationService.createObjectDataInput(data);
assertEquals(key, in.readObject());
assertEquals(value, in.readObject());
assertEquals(SnapshotDataValueTerminator.INSTANCE, in.readObject());
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class DataInputNavigableJsonAdapterTest method testCreateAndUseConcurrently.
@Test
public void testCreateAndUseConcurrently() throws InterruptedException {
// UTF8Reader is not thread safe; the purpose of the test
// is to ensure there is no interference across UTF8Reader instances
int concurrency = 8;
CountDownLatch latch = new CountDownLatch(1);
Thread[] threads = new Thread[concurrency];
for (int i = 0; i < concurrency; i++) {
threads[i] = new Thread(() -> {
try {
latch.await();
for (byte[] sample : SAMPLE_BYTES) {
BufferObjectDataInput input = new ByteArrayObjectDataInput(sample, serializationService, DEFAULT_BYTE_ORDER);
DataInputNavigableJsonAdapter.UTF8Reader reader = new DataInputNavigableJsonAdapter.UTF8Reader(input);
assertReadFully(reader, sample);
}
} catch (InterruptedException e) {
ignore(e);
} catch (IOException e) {
ExceptionUtil.rethrow(e);
}
});
threads[i].start();
}
latch.countDown();
for (int i = 0; i < concurrency; i++) {
threads[i].join();
}
}
use of com.hazelcast.internal.nio.BufferObjectDataInput 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);
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method takeInputBuffer_whenPooledInstanceWithVersionSetIsReturned.
@Test
public void takeInputBuffer_whenPooledInstanceWithVersionSetIsReturned() {
Data data = new HeapData(new byte[] {});
BufferObjectDataInput found1 = bufferPool.takeInputBuffer(data);
assertEquals(Version.UNKNOWN, found1.getVersion());
found1.setVersion(Versions.CURRENT_CLUSTER_VERSION);
bufferPool.returnInputBuffer(found1);
BufferObjectDataInput found2 = bufferPool.takeInputBuffer(data);
assertEquals(Version.UNKNOWN, found2.getVersion());
}
use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.
the class BufferPoolTest method returnInputBuffer.
@Test
public void returnInputBuffer() {
BufferObjectDataInput in = mock(BufferObjectDataInput.class);
bufferPool.returnInputBuffer(in);
// lets see if the item was pushed on the queue
assertEquals(1, bufferPool.inputQueue.size());
// we need to make sure clear was called
verify(in, times(1)).clear();
}
Aggregations