Search in sources :

Example 21 with BufferObjectDataInput

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

Example 22 with BufferObjectDataInput

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();
    }
}
Also used : IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 23 with BufferObjectDataInput

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);
}
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 24 with BufferObjectDataInput

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());
}
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 25 with BufferObjectDataInput

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

Aggregations

BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)28 QuickTest (com.hazelcast.test.annotation.QuickTest)12 Test (org.junit.Test)12 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)11 Data (com.hazelcast.internal.serialization.Data)10 BufferObjectDataOutput (com.hazelcast.internal.nio.BufferObjectDataOutput)6 HeapData (com.hazelcast.internal.serialization.impl.HeapData)5 IOException (java.io.IOException)5 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)2 SerializationUtil.isNullData (com.hazelcast.internal.serialization.impl.SerializationUtil.isNullData)2 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)2 CompactStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactStreamSerializerAdapter)2 CompactWithSchemaStreamSerializerAdapter (com.hazelcast.internal.serialization.impl.compact.CompactWithSchemaStreamSerializerAdapter)2 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 HazelcastException (com.hazelcast.core.HazelcastException)1 IOUtil.readData (com.hazelcast.internal.nio.IOUtil.readData)1 IOUtil.writeData (com.hazelcast.internal.nio.IOUtil.writeData)1