Search in sources :

Example 16 with BufferObjectDataInput

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

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

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

the class MorphingPortableReaderTest method before.

@Before
public void before() throws Exception {
    service1 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new MorphingBasePortable();
        }
    }).build();
    service2 = (SerializationServiceV1) new DefaultSerializationServiceBuilder().addPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new PortableFactory() {

        public Portable create(int classId) {
            return new MorphingPortable();
        }
    }).build();
    Data data = service1.toData(new MorphingBasePortable((byte) 1, true, (char) 2, (short) 3, 4, 5, 1f, 2d, "test"));
    BufferObjectDataInput in = service2.createObjectDataInput(data);
    PortableSerializer portableSerializer = service2.getPortableSerializer();
    reader = portableSerializer.createMorphingReader(in);
}
Also used : MorphingBasePortable(com.hazelcast.nio.serialization.MorphingBasePortable) MorphingPortable(com.hazelcast.nio.serialization.MorphingPortable) Data(com.hazelcast.nio.serialization.Data) PortableFactory(com.hazelcast.nio.serialization.PortableFactory) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) Before(org.junit.Before)

Example 19 with BufferObjectDataInput

use of com.hazelcast.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.nio.serialization.Data) HeapData(com.hazelcast.internal.serialization.impl.HeapData) HeapData(com.hazelcast.internal.serialization.impl.HeapData) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 20 with BufferObjectDataInput

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

the class BufferPoolTest method returnInputBuffer_whenOverflowing.

@Test
public void returnInputBuffer_whenOverflowing() throws IOException {
    for (int k = 0; k < BufferPoolImpl.MAX_POOLED_ITEMS; k++) {
        bufferPool.returnInputBuffer(mock(BufferObjectDataInput.class));
    }
    BufferObjectDataInput in = mock(BufferObjectDataInput.class);
    bufferPool.returnInputBuffer(in);
    assertEquals(BufferPoolImpl.MAX_POOLED_ITEMS, bufferPool.inputQueue.size());
    // we need to make sure that the in was closed since we are not going to pool it.
    verify(in, times(1)).close();
}
Also used : BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

BufferObjectDataInput (com.hazelcast.nio.BufferObjectDataInput)25 QuickTest (com.hazelcast.test.annotation.QuickTest)11 Test (org.junit.Test)11 ParallelTest (com.hazelcast.test.annotation.ParallelTest)10 BufferObjectDataOutput (com.hazelcast.nio.BufferObjectDataOutput)6 Data (com.hazelcast.nio.serialization.Data)6 ClassDefinition (com.hazelcast.nio.serialization.ClassDefinition)3 IOException (java.io.IOException)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)2 HeapData (com.hazelcast.internal.serialization.impl.HeapData)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 HazelcastSerializationException (com.hazelcast.nio.serialization.HazelcastSerializationException)2 CustomSerializationTest (com.hazelcast.nio.serialization.CustomSerializationTest)1 MorphingBasePortable (com.hazelcast.nio.serialization.MorphingBasePortable)1 MorphingPortable (com.hazelcast.nio.serialization.MorphingPortable)1 PortableFactory (com.hazelcast.nio.serialization.PortableFactory)1