Search in sources :

Example 11 with BufferObjectDataInput

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

the class PortableUtilsTest method wrongUseOfAnyOperationException.

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

Example 12 with BufferObjectDataInput

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

the class StringSerializationTest method testNullStringEncodeDecode2.

@Test
public void testNullStringEncodeDecode2() throws Exception {
    BufferObjectDataOutput objectDataOutput = serializationService.createObjectDataOutput();
    objectDataOutput.writeUTF(null);
    byte[] bytes = objectDataOutput.toByteArray();
    objectDataOutput.close();
    BufferObjectDataInput objectDataInput = serializationService.createObjectDataInput(bytes);
    String decodedStr = objectDataInput.readUTF();
    assertNull(decodedStr);
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 13 with BufferObjectDataInput

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

the class PortableClassVersionTest method testDifferentClassVersionsUsingDataWriteAndRead.

// used in EE, so needs to be package private
static void testDifferentClassVersionsUsingDataWriteAndRead(InternalSerializationService serializationService, InternalSerializationService serializationService2) throws Exception {
    NamedPortable portableV1 = new NamedPortable("portable-v1", 111);
    Data dataV1 = serializationService.toData(portableV1);
    // emulate socket write by writing data to stream
    BufferObjectDataOutput out = serializationService.createObjectDataOutput(1024);
    out.writeData(dataV1);
    byte[] bytes = out.toByteArray();
    // emulate socket read by reading data from stream
    BufferObjectDataInput in = serializationService2.createObjectDataInput(bytes);
    dataV1 = in.readData();
    // serialize new portable version
    NamedPortableV2 portableV2 = new NamedPortableV2("portable-v2", 123, 500);
    Data dataV2 = serializationService2.toData(portableV2);
    NamedPortable v1FromV2 = serializationService.toObject(dataV2);
    assertEquals(portableV2.name, v1FromV2.name);
    assertEquals(portableV2.k, v1FromV2.k);
    NamedPortableV2 v2FromV1 = serializationService2.toObject(dataV1);
    assertEquals(portableV1.name, v2FromV1.name);
    assertEquals(portableV1.k, v2FromV1.k);
    assertNull(v2FromV1.v);
}
Also used : BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput)

Example 14 with BufferObjectDataInput

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

the class CollectionTxnUtilTest method testWriteRead.

@Test
public void testWriteRead() throws IOException {
    InternalSerializationService ss = new DefaultSerializationServiceBuilder().build();
    BufferObjectDataOutput out = ss.createObjectDataOutput();
    CollectionTxnUtil.write(out, operationList);
    BufferObjectDataInput in = ss.createObjectDataInput(out.toByteArray());
    List<Operation> resultList = CollectionTxnUtil.read(in);
    assertEquals(operationList.size(), resultList.size());
    for (int i = 0; i < operationList.size(); i++) {
        assertEquals(operationList.get(i), resultList.get(i));
    }
}
Also used : DefaultSerializationServiceBuilder(com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder) BufferObjectDataOutput(com.hazelcast.nio.BufferObjectDataOutput) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) BackupAwareOperation(com.hazelcast.spi.BackupAwareOperation) Operation(com.hazelcast.spi.Operation) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with BufferObjectDataInput

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

the class AbstractSerializationServiceTest method testReadObject_ServiceInactive.

@Test
public void testReadObject_ServiceInactive() throws Exception {
    expectedException.expect(HazelcastSerializationException.class);
    expectedException.expectCause(Is.is(IsInstanceOf.<Throwable>instanceOf(HazelcastInstanceNotActiveException.class)));
    abstractSerializationService.register(StringBuffer.class, new StringBufferSerializer(false));
    Data data = abstractSerializationService.toData(new StringBuffer());
    abstractSerializationService.dispose();
    BufferObjectDataInput in = abstractSerializationService.createObjectDataInput(data);
    in.position(HeapData.TYPE_OFFSET);
    abstractSerializationService.readObject(in);
}
Also used : Data(com.hazelcast.nio.serialization.Data) BufferObjectDataInput(com.hazelcast.nio.BufferObjectDataInput) QuickTest(com.hazelcast.test.annotation.QuickTest) CustomSerializationTest(com.hazelcast.nio.serialization.CustomSerializationTest) 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