public void testConfigWithExclude2() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObject#exclude=string.* ,"); serializer.init(props); assertEquals(1, manager.getFields(DomainObject.class).size()); }
public void testConfigWithExclude1() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObject#exclude=long.*"); serializer.init(props); assertEquals(3, manager.getFields(DomainObject.class).size()); }
public void testBasicConfig() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObject"); serializer.init(props); assertEquals(4, manager.getFields(DomainObject.class).size()); }
public void testConfigWithIdentityAndExclude4() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#exclude=string.*, " + "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#exclude=long.*"); serializer.init(props); assertEquals(26, manager.getFields(DomainObjectPdxAuto.class).size()); }
public void testConcurrentHashMap() throws Exception { setupSerializer("java.util.concurrent..*"); ConcurrentHashMap<String, String> m = new ConcurrentHashMap<String, String>(); m.put("k1", "v1"); m.put("k2", "v2"); m.put("k3", "v3"); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(m, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(m, dObj); }
public void testGetConfig() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "Pdx#exclude=string.*#exclude=badField, Pdx#identity=id.*, PdxAuto#exclude=long.*#identity=id.*"); serializer.init(props); Properties result = serializer.getConfig(); assertEquals("Pdx, PdxAuto, Pdx#identity=id.*, PdxAuto#identity=id.*, Pdx#exclude=string.*, Pdx#exclude=badField, PdxAuto#exclude=long.*", result.getProperty("classes")); manager.resetCaches(); serializer.init(result); result = serializer.getConfig(); assertEquals("Pdx, PdxAuto, Pdx#identity=id.*, PdxAuto#identity=id.*, Pdx#exclude=string.*, Pdx#exclude=badField, PdxAuto#exclude=long.*", result.getProperty("classes")); }
private void doExtensible(String msg) throws IOException, ClassNotFoundException { BigInteger bi = new BigInteger("12345678901234567890"); BigDecimal bd = new BigDecimal("1234567890.1234567890"); BigHolder bih = new BigHolder(bi, bd); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(bih, out); System.out.println(msg + " out.size="+ out.size()); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(bih, dObj); }
public void testGetFieldName() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitFieldNameAutoSerializer(false, "com.gemstone.gemfire.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()); }
private void doCHM(String msg) throws IOException, ClassNotFoundException { ConcurrentHashMap<String, BigHolder> chm = new ConcurrentHashMap<String, BigHolder>(); for (int i=1; i < 32; i++) { chm.put("key"+i, new BigHolder(i)); } CHMHolder h = new CHMHolder(chm); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(h, out); System.out.println(msg + " out.size=" + out.size()); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(h, dObj); }
public void testIsIdentityField() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitIdentityAutoSerializer(false, "com.gemstone.gemfire.pdx.DomainObjectPdxAuto"), true); DomainObject objOut = new DomainObjectPdxAuto(4); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); DataSerializer.writeObject(objOut, out); DataInputStream dis = new DataInputStream( new ByteArrayInputStream(out.toByteArray())); PdxInstance pi = (PdxInstance)DataSerializer.readObject(dis); PdxInstance pi2 = (PdxInstance)DataSerializer.readObject(dis); assertEquals(true, pi.isIdentityField("long_0")); assertEquals(false, pi.isIdentityField("string_0")); assertEquals(false, pi.isEnum()); assertEquals(objOut.getClass().getName(), pi.getClassName()); assertEquals(objOut, pi.getObject()); assertEquals(objOut, pi2.getObject()); } public static class ExplicitIncludedAutoSerializer extends ReflectionBasedAutoSerializer {
public void testMonth() throws Exception { setupSerializer(false, false, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyMonth"); MyMonth m = new MyMonth(1); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(m, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(m, dObj); }
public void testExternalizable() throws Exception { setupSerializer("com.gemstone.gemfire.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); }
/** * A serializable with a writeReplace method should use standard serialization. */ public void testComparator() throws Exception { setupSerializer("com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyComparator"); TreeSet o = new TreeSet(new MyComparator()); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(o, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(o, dObj); }
public void testIsFieldIncluded() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitIncludedAutoSerializer(false, "com.gemstone.gemfire.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()))); assertEquals(true, pi.hasField("long_0")); assertEquals(false, pi.hasField("string_0")); } public static class ExplicitFieldNameAutoSerializer extends ReflectionBasedAutoSerializer {
/** * A serializable with a writeReplace method should use standard serialization. */ public void testWriteReplace() throws Exception { setupSerializer("com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.MyWriteReplace"); MyWriteReplace o = new MyWriteReplace("79"); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(o, out); Object dObj = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals("79", dObj); }
public void testIsClassAutoSerialized() throws IOException, ClassNotFoundException { setupSerializer(new ExplicitClassNameAutoSerializer(false, ""), false); DomainObject objOut = new DomainObjectPdxAuto(4); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); DomainObject objIn = (DomainObject)DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); assertEquals(objOut, objIn); }
public void testConfigWithIdentity1() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#identity=long.*"); serializer.init(props); DomainObject objOut = new DomainObjectPdxAuto(4); objOut.set("string_0", "test string value"); objOut.set("long_0", 99L); 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")); assertTrue(pdxIn.isIdentityField("long_0")); }
public void testConfigWithIdentityAndExclude1() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#identity=long.*#exclude=string.*"); serializer.init(props); assertEquals(27, manager.getFields(DomainObjectPdxAuto.class).size()); DomainObject objOut = new DomainObjectPdxAuto(4); objOut.set("string_0", "test string value"); objOut.set("long_0", 99L); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); // This means we're not doing anything with this string assertNull(pdxIn.getField("string_0")); assertTrue(pdxIn.isIdentityField("long_0")); }
public void testConfigWithIdentityAndExclude3() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#identity=long.*#exclude=string.*, com.another.class.Foo"); serializer.init(props); assertEquals(27, manager.getFields(DomainObjectPdxAuto.class).size()); DomainObject objOut = new DomainObjectPdxAuto(4); objOut.set("string_0", "test string value"); objOut.set("long_0", 99L); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); // This means we're not doing anything with this string assertNull(pdxIn.getField("string_0")); assertTrue(pdxIn.isIdentityField("long_0")); }
public void testConfigWithIdentityAndExclude2() throws Exception { setupSerializer(); Properties props = new Properties(); props.put("classes", "com.gemstone.gemfire.pdx.DomainObjectPdxAuto#identity=long.*#exclude=string.*#, com.another.class.Foo"); serializer.init(props); assertEquals(27, manager.getFields(DomainObjectPdxAuto.class).size()); DomainObject objOut = new DomainObjectPdxAuto(4); objOut.set("string_0", "test string value"); objOut.set("long_0", 99L); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); // This means we're not doing anything with this string assertNull(pdxIn.getField("string_0")); assertTrue(pdxIn.isIdentityField("long_0")); }