Search in sources :

Example 71 with ObjectDataInput

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

the class ObjectCarryingPortable method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    ObjectDataInput input = reader.getRawDataInput();
    object = input.readObject();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 72 with ObjectDataInput

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

the class RawDataPortable method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    l = reader.readLong("l");
    c = reader.readCharArray("c");
    p = reader.readPortable("p");
    final ObjectDataInput input = reader.getRawDataInput();
    k = input.readInt();
    s = input.readString();
    sds = input.readObject();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 73 with ObjectDataInput

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

the class InvalidRawDataPortable2 method readPortable.

@Override
public void readPortable(PortableReader reader) throws IOException {
    c = reader.readCharArray("c");
    final ObjectDataInput input = reader.getRawDataInput();
    k = input.readInt();
    l = reader.readLong("l");
    s = input.readString();
    p = reader.readPortable("p");
    sds = input.readObject();
}
Also used : ObjectDataInput(com.hazelcast.nio.ObjectDataInput)

Example 74 with ObjectDataInput

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

the class DataSerializableSerializationTest method testClarifiedExceptionsForUnsupportedClassTypes.

@Test
public void testClarifiedExceptionsForUnsupportedClassTypes() {
    class LocalClass implements DataSerializable {

        @Override
        public void writeData(ObjectDataOutput out) {
        }

        @Override
        public void readData(ObjectDataInput in) {
        }
    }
    DataSerializable anonymousInstance = new DataSerializable() {

        @Override
        public void writeData(ObjectDataOutput out) {
        }

        @Override
        public void readData(ObjectDataInput in) {
        }
    };
    DataSerializable[] throwingInstances = { new LocalClass(), anonymousInstance, new NonStaticMemberClass() };
    for (DataSerializable throwingInstance : throwingInstances) {
        try {
            ss.toObject(ss.toData(throwingInstance));
        } catch (HazelcastSerializationException e) {
            assertInstanceOf(NoSuchMethodException.class, e.getCause());
            assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
            assertInstanceOf(NoSuchMethodException.class, e.getCause().getCause());
            continue;
        }
        fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
    }
    for (DataSerializable throwingInstance : throwingInstances) {
        try {
            ss.toObject(ss.toData(throwingInstance), throwingInstance.getClass());
        } catch (HazelcastSerializationException e) {
            assertInstanceOf(InstantiationException.class, e.getCause());
            assertContains(e.getCause().getMessage(), "can't conform to DataSerializable");
            assertInstanceOf(InstantiationException.class, e.getCause().getCause());
            continue;
        }
        fail("deserialization of '" + throwingInstance.getClass() + "' is expected to fail");
    }
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) HazelcastSerializationException(com.hazelcast.nio.serialization.HazelcastSerializationException) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) IdentifiedDataSerializable(com.hazelcast.nio.serialization.IdentifiedDataSerializable) DataSerializable(com.hazelcast.nio.serialization.DataSerializable) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with ObjectDataInput

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

the class SerializationIssueTest method testGlobalSerializer_withoutOverrideJavaSerializable.

@Test
public void testGlobalSerializer_withoutOverrideJavaSerializable() {
    GlobalSerializerConfig globalSerializerConfig = new GlobalSerializerConfig();
    globalSerializerConfig.setOverrideJavaSerialization(false);
    final AtomicInteger writeCounter = new AtomicInteger();
    final AtomicInteger readCounter = new AtomicInteger();
    SerializationConfig serializationConfig = new SerializationConfig().setGlobalSerializerConfig(globalSerializerConfig.setImplementation(new StreamSerializer<Object>() {

        @Override
        public void write(ObjectDataOutput out, Object v) throws IOException {
            writeCounter.incrementAndGet();
            out.writeString(((DummyValue) v).s);
            out.writeInt(((DummyValue) v).k);
        }

        @Override
        public Object read(ObjectDataInput in) throws IOException {
            readCounter.incrementAndGet();
            return new DummyValue(in.readString(), in.readInt());
        }

        public int getTypeId() {
            return 123;
        }

        public void destroy() {
        }
    }));
    SerializationService ss1 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    DummyValue value = new DummyValue("test", 111);
    Data data1 = ss1.toData(value);
    Data data2 = ss1.toData(new Foo());
    Assert.assertNotNull(data1);
    Assert.assertNotNull(data2);
    assertEquals(1, writeCounter.get());
    SerializationService ss2 = new DefaultSerializationServiceBuilder().setConfig(serializationConfig).build();
    Object o1 = ss2.toObject(data1);
    Object o2 = ss2.toObject(data2);
    Assert.assertEquals(value, o1);
    Assert.assertNotNull(o2);
    assertEquals(1, readCounter.get());
}
Also used : ObjectDataOutput(com.hazelcast.nio.ObjectDataOutput) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializationConfig(com.hazelcast.config.SerializationConfig) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) StreamSerializer(com.hazelcast.nio.serialization.StreamSerializer) ObjectDataInput(com.hazelcast.nio.ObjectDataInput) GlobalSerializerConfig(com.hazelcast.config.GlobalSerializerConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

ObjectDataInput (com.hazelcast.nio.ObjectDataInput)81 Test (org.junit.Test)35 QuickTest (com.hazelcast.test.annotation.QuickTest)32 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)24 BufferObjectDataInput (com.hazelcast.internal.nio.BufferObjectDataInput)17 FieldKind (com.hazelcast.nio.serialization.FieldKind)16 IOException (java.io.IOException)13 ObjectDataOutput (com.hazelcast.nio.ObjectDataOutput)12 Nullable (javax.annotation.Nullable)9 GlobalSerializerConfig (com.hazelcast.config.GlobalSerializerConfig)7 SerializationConfig (com.hazelcast.config.SerializationConfig)6 StreamSerializer (com.hazelcast.nio.serialization.StreamSerializer)6 Data (com.hazelcast.nio.serialization.Data)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Data (com.hazelcast.internal.serialization.Data)3 SerializationService (com.hazelcast.internal.serialization.SerializationService)3 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)3 HeapData (com.hazelcast.internal.serialization.impl.HeapData)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 SerializerConfig (com.hazelcast.config.SerializerConfig)2