Search in sources :

Example 6 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class BufferPoolImpl method takeInputBuffer.

@Override
public BufferObjectDataInput takeInputBuffer(Data data) {
    BufferObjectDataInput in = inputQueue.poll();
    if (in == null) {
        in = serializationService.createObjectDataInput((byte[]) null);
    }
    in.init(data.toByteArray(), HeapData.DATA_OFFSET);
    return in;
}
Also used : BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 7 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class ExplodeSnapshotP method traverser.

/* We can't close the BufferObjectDataInput cleanly. We close it when the returned traverser is fully iterated,
    but the caller might not fully iterate it and we have no opportunity to close it.
    On the other hand, the returned object doesn't hold any resources, so relying on the GC is sufficient.
    See #19799 */
@SuppressWarnings("squid:S2095")
private Traverser<Object> traverser(byte[] data) {
    BufferObjectDataInput in = serializationService.createObjectDataInput(data);
    return () -> uncheckCall(() -> {
        Object key = in.readObject();
        if (key == SnapshotDataValueTerminator.INSTANCE) {
            return null;
        }
        Object value = in.readObject();
        return key instanceof BroadcastKey ? new BroadcastEntry(key, value) : entry(key, value);
    });
}
Also used : BroadcastKey(com.hazelcast.jet.core.BroadcastKey) BroadcastEntry(com.hazelcast.jet.impl.execution.BroadcastEntry) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput)

Example 8 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class AsyncSnapshotWriterImplTest method test_serializeAndDeserialize.

@Test
public void test_serializeAndDeserialize() throws Exception {
    // This is the way we serialize and deserialize objects into the snapshot. We depend on some internals of IMDG:
    // - using the HeapData.toByteArray() from offset 4
    // - concatenate them into one array
    // - read that array with createObjectDataInput(byte[])
    // Purpose of this test is to check that they didn't change anything...
    Data serialized1 = serializationService.toData("foo");
    Data serialized2 = serializationService.toData("bar");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    Stream.of(serialized1, serialized2).forEach(serialized -> {
        Assert.assertTrue("unexpected class: " + serialized.getClass(), serialized instanceof HeapData);
        byte[] bytes = serialized.toByteArray();
        os.write(bytes, HeapData.TYPE_OFFSET, bytes.length - HeapData.TYPE_OFFSET);
    });
    BufferObjectDataInput in = serializationService.createObjectDataInput(os.toByteArray());
    Assert.assertEquals("foo", in.readObject());
    Assert.assertEquals("bar", in.readObject());
}
Also used : HeapData(com.hazelcast.internal.serialization.impl.HeapData) Data(com.hazelcast.internal.serialization.Data) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CustomByteArrayOutputStream(com.hazelcast.jet.impl.util.AsyncSnapshotWriterImpl.CustomByteArrayOutputStream) 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 9 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput 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 10 with BufferObjectDataInput

use of com.hazelcast.internal.nio.BufferObjectDataInput in project hazelcast by hazelcast.

the class StringSerializationTest method testNullStringEncodeDecode2.

@Test
public void testNullStringEncodeDecode2() throws Exception {
    BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
    objectDataOutput.writeString(null);
    byte[] bytes = objectDataOutput.toByteArray();
    objectDataOutput.close();
    BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
    String decodedStr = objectDataInput.readString();
    assertNull(decodedStr);
}
Also used : BufferObjectDataOutput(com.hazelcast.internal.nio.BufferObjectDataOutput) BufferObjectDataInput(com.hazelcast.internal.nio.BufferObjectDataInput) 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