Search in sources :

Example 11 with BufferObjectDataOutput

use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class RingbufferContainerSerializationTest method clone.

private RingbufferContainer clone(RingbufferContainer original) {
    BufferObjectDataOutput out = serializationService.createObjectDataOutput(100000);
    BufferObjectDataInput in = null;
    try {
        out.writeObject(original);
        byte[] bytes = out.toByteArray();
        sleepMillis(CLOCK_DIFFERENCE_MS);
        in = serializationService.createObjectDataInput(bytes);
        RingbufferContainer clone = in.readObject();
        return clone;
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        closeResource(out);
        closeResource(in);
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) IOException(java.io.IOException) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 12 with BufferObjectDataOutput

use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class PartitionTableViewTest method test_writeAndReadData.

@Test
public void test_writeAndReadData() throws Exception {
    InternalSerializationService serializationService = new DefaultSerializationServiceBuilder().build();
    PartitionTableView table1 = createRandomPartitionTable();
    BufferObjectDataOutput out = serializationService.createObjectDataOutput();
    PartitionTableView.writeData(table1, out);
    BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
    PartitionTableView table2 = PartitionTableView.readData(in);
    assertEquals(table1, table2);
    assertEquals(table1.hashCode(), table2.hashCode());
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with BufferObjectDataOutput

use of com.hazelcast.nio.BufferObjectDataOutput in project hazelcast by hazelcast.

the class OperationSerializationTest method copy.

private Operation copy(Operation op) {
    try {
        BufferObjectDataOutput out = serializationService.createObjectDataOutput(1000);
        op.writeData(out);
        BufferObjectDataInput in = serializationService.createObjectDataInput(out.toByteArray());
        Constructor constructor = op.getClass().getConstructor();
        constructor.setAccessible(true);
        Operation copiedOperation = (Operation) constructor.newInstance();
        copiedOperation.readData(in);
        return copiedOperation;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) Constructor(java.lang.reflect.Constructor) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) IOException(java.io.IOException)

Aggregations

BufferObjectDataOutput (com.hazelcast.nio.BufferObjectDataOutput)13 QuickTest (com.hazelcast.test.annotation.QuickTest)8 Test (org.junit.Test)8 ParallelTest (com.hazelcast.test.annotation.ParallelTest)7 BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)6 IOException (java.io.IOException)3 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 SerializationUtil.createSerializerAdapter (com.hazelcast.internal.serialization.impl.SerializationUtil.createSerializerAdapter)1 BufferPool (com.hazelcast.internal.serialization.impl.bufferpool.BufferPool)1 CustomSerializationTest (com.hazelcast.nio.serialization.CustomSerializationTest)1 BackupAwareOperation (com.hazelcast.spi.BackupAwareOperation)1 Operation (com.hazelcast.spi.Operation)1 Constructor (java.lang.reflect.Constructor)1