Search in sources :

Example 6 with BufferObjectDataInput

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

the class PortablePositionNavigator method createPositionForPortableArrayAccess.

private static PortablePosition createPositionForPortableArrayAccess(PortableNavigatorContext ctx, PortablePathCursor path, int index, boolean singleCellAccess) throws IOException {
    BufferObjectDataInput in = ctx.getIn();
    in.position(getStreamPositionOfTheField(ctx));
    // read and validate portable properties
    int len = in.readInt();
    int factoryId = in.readInt();
    int classId = in.readInt();
    int streamPosition = in.position();
    validateFactoryAndClass(ctx.getCurrentFieldDefinition(), factoryId, classId, path.path());
    // if single-cell access, dead-reckon cell's position that's specified by the index
    if (singleCellAccess) {
        if (index < len) {
            int offset = in.position() + index * Bits.INT_SIZE_IN_BYTES;
            in.position(offset);
            streamPosition = in.readInt();
        } else {
            // return null if index out-of-bound
            return PortablePositionFactory.nil(path.isLastToken());
        }
    }
    return PortablePositionFactory.createSinglePortablePosition(ctx.getCurrentFieldDefinition(), streamPosition, factoryId, classId, index, len, path.isLastToken());
}
Also used : BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 7 with BufferObjectDataInput

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

the class PortableContextImpl method lookupClassDefinition.

@Override
public ClassDefinition lookupClassDefinition(Data data) throws IOException {
    if (!data.isPortable()) {
        throw new IllegalArgumentException("Data is not Portable!");
    }
    BufferObjectDataInput in = serializationService.createObjectDataInput(data);
    int factoryId = in.readInt();
    int classId = in.readInt();
    int version = in.readInt();
    ClassDefinition classDefinition = lookupClassDefinition(factoryId, classId, version);
    if (classDefinition == null) {
        classDefinition = readClassDefinition(in, factoryId, classId, version);
    }
    return classDefinition;
}
Also used : ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 8 with BufferObjectDataInput

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

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

the class PortableUtilsTest method getPortableArrayCellPosition.

@Test
public void getPortableArrayCellPosition() throws Exception {
    // GIVEN
    BufferObjectDataInput in = mock(BufferObjectDataInput.class);
    int offset = 10;
    int cellIndex = 3;
    // WHEN
    PortableUtils.getPortableArrayCellPosition(in, offset, cellIndex);
    // THEN
    verify(in, times(1)).readInt(offset + cellIndex * Bits.INT_SIZE_IN_BYTES);
}
Also used : BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with BufferObjectDataInput

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

the class PortableUtilsTest method unknownFieldException.

@Test
public void unknownFieldException() {
    // GIVEN
    BufferObjectDataInput in = mock(BufferObjectDataInput.class);
    ClassDefinition cd = mock(ClassDefinition.class);
    PortableNavigatorContext ctx = new PortableNavigatorContext(in, cd, null);
    // WHEN
    HazelcastSerializationException ex = PortableUtils.createUnknownFieldException(ctx, "person.brain");
    // THEN
    assertNotNull(ex);
}
Also used : HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ClassDefinition(com.hazelcast.nio.serialization.ClassDefinition) 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