use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class InvalidRawDataPortable method writePortable.
@Override
public void writePortable(PortableWriter writer) throws IOException {
writer.writeLong("l", l);
final ObjectDataOutput output = writer.getRawDataOutput();
output.writeInt(k);
output.writeString(s);
writer.writeCharArray("c", c);
output.writeObject(sds);
writer.writePortable("p", p);
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class SerializationUtilTest method serialize.
private byte[] serialize(Boolean b) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectDataOutput out = createObjectDataOutputStream(bout, mockSs);
SerializationUtil.writeNullableBoolean(out, b);
return bout.toByteArray();
}
use of com.hazelcast.nio.ObjectDataOutput in project hazelcast by hazelcast.
the class CachePartitionLostListenerTest method test_cachePartitionEventData_serialization.
@Test
public void test_cachePartitionEventData_serialization() throws IOException {
CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("cacheName", 1, null);
ObjectDataOutput output = mock(ObjectDataOutput.class, withSettings().extraInterfaces(DataWriter.class));
cachePartitionEventData.writeData(output);
verify(output).writeString("cacheName");
verify(output).writeInt(1);
}
use of com.hazelcast.nio.ObjectDataOutput 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.ObjectDataOutput 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