use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AutoSerializableJUnitTest method testExternalizable.
@Test
public void testExternalizable() throws Exception {
setupSerializer("org.apache.geode.pdx.AutoSerializableJUnitTest.MyExternalizable");
MyExternalizable o = new MyExternalizable(79);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(o, out);
Object dObj = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
assertEquals(o, dObj);
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AutoSerializableJUnitTest method testSanity.
/*
* Test basic functionality.
*/
@Test
public void testSanity() throws Exception {
setupSerializer("org.apache.geode.pdx.DomainObjectPdxAuto");
DomainObject objOut = new DomainObjectPdxAuto(4);
objOut.set("string_0", "test string value");
objOut.set("long_0", 99L);
objOut.set("string_immediate", "right now");
objOut.set("anEnum", DomainObjectPdxAuto.Day.FRIDAY);
List<String> list = new ArrayList<String>(4);
list.add("string one");
list.add("string two");
list.add("string three");
list.add("string four");
objOut.set("string_list", list);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(objOut, out);
PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
assertEquals(99L, pdxIn.getField("long_0"));
assertEquals("test string value", pdxIn.getField("string_0"));
assertEquals("right now", pdxIn.getField("string_immediate"));
{
PdxInstance epi = (PdxInstance) pdxIn.getField("anEnum");
assertEquals(true, epi.isEnum());
assertEquals(true, epi.hasField("name"));
assertEquals(true, epi.hasField("ordinal"));
assertEquals("org.apache.geode.pdx.DomainObjectPdxAuto$Day", epi.getClassName());
assertEquals("FRIDAY", epi.getField("name"));
assertEquals(DomainObjectPdxAuto.Day.FRIDAY.ordinal(), epi.getField("ordinal"));
assertEquals(DomainObjectPdxAuto.Day.FRIDAY, epi.getObject());
}
assertEquals(4, ((List) pdxIn.getField("string_list")).size());
{
DomainObjectPdxAuto result = (DomainObjectPdxAuto) pdxIn.getObject();
assertEquals(99L, result.get("long_0"));
assertEquals("test string value", result.get("string_0"));
assertEquals("right now", result.get("string_immediate"));
assertEquals(DomainObjectPdxAuto.Day.FRIDAY, result.get("anEnum"));
assertEquals(4, ((List) result.get("string_list")).size());
}
// disable pdx instances to make sure we can deserialize without calling PdxInstance.getObject
PdxInstanceImpl.setPdxReadSerialized(false);
try {
DomainObjectPdxAuto result = (DomainObjectPdxAuto) DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
assertEquals(99L, result.get("long_0"));
assertEquals("test string value", result.get("string_0"));
assertEquals("right now", result.get("string_immediate"));
assertEquals(DomainObjectPdxAuto.Day.FRIDAY, result.get("anEnum"));
assertEquals(4, ((List) result.get("string_list")).size());
} finally {
PdxInstanceImpl.setPdxReadSerialized(true);
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AutoSerializableJUnitTest method testException.
/*
* Check that an exception is appropriately thrown for a 'bad' object. In this case the bad class
* masks a field from a superclass and defines it as a different type.
*/
@Test
public void testException() throws Exception {
setupSerializer(stdSerializableClasses);
DomainObject objOut = new DomainObjectBad();
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
try {
DataSerializer.writeObject(objOut, out);
} catch (SerializationException ex) {
// Pass
} catch (Exception ex) {
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AutoSerializableJUnitTest method testNoZeroArgConstructor.
/*
* Test what happens with a class without a zero-arg constructor
*/
@Test
public void testNoZeroArgConstructor() throws Exception {
setupSerializer(stdSerializableClasses);
DomainObject objOut = new DomainObjectPdxAutoNoDefaultConstructor(4);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
try {
DataSerializer.writeObject(objOut, out);
} catch (NotSerializableException ex) {
// This passes the test
} catch (Exception ex) {
throw new RuntimeException("Expected NotSerializableException here but got " + ex);
}
}
use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.
the class AutoSerializableJUnitTest method testGetFieldName.
@Test
public void testGetFieldName() throws IOException, ClassNotFoundException {
setupSerializer(new ExplicitFieldNameAutoSerializer(false, "org.apache.geode.pdx.DomainObjectPdxAuto"), true);
DomainObject objOut = new DomainObjectPdxAuto(4);
HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
DataSerializer.writeObject(objOut, out);
PdxInstance pi = (PdxInstance) DataSerializer.readObject(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
System.out.println("fieldNames=" + pi.getFieldNames());
assertEquals(false, pi.hasField("long_0"));
assertEquals(true, pi.hasField("_long_0"));
assertEquals(true, pi.hasField("string_0"));
assertEquals(objOut, pi.getObject());
}
Aggregations