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();
}
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();
}
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();
}
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");
}
}
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());
}
Aggregations