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 testNoCHM() throws Exception { setupSerializer(false, false, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.*Holder"); doCHM("without autoSerializer handling ConcurrentHashMap"); } private void doCHM(String msg) throws IOException, ClassNotFoundException {
public void testNoExtensibility() throws Exception { setupSerializer(false, false, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.BigHolder"); doExtensible("using standard serialization of Big*"); }
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")); }
public void testMultipleClassLoaders() throws Exception { setupSerializer(stdSerializableClasses); ChildFirstClassLoader cfcl = new ChildFirstClassLoader(javaClassPathToUrl(), this.getClass().getClassLoader()); cfcl.addIncludedClass("com\\.gemstone.*"); new ByteArrayInputStream(out1.toByteArray()))); assertEquals(99L, pdxIn.getField("long_0")); assertEquals("test string value", pdxIn.getField("string_0")); assertFalse(obj1.getClass() == obj2.getClass()); new ByteArrayInputStream(out2.toByteArray()))); assertEquals(1009L, pdxIn.getField("long_0")); assertEquals("different string value", pdxIn.getField("string_0")); assertEquals(2, manager.getClassMap().size());
public void testReadNullPrimitives() throws Exception { setupSerializer(stdSerializableClasses); // Don't want to write any fields manager.addExcludePattern(".*DomainObjectPdxAuto", "a(Char|Boolean|Byte|Short|Int|Long|Float|Double)"); DomainObject objOut = new DomainObjectPdxAuto(4); objOut.set("aString", "aString has a value"); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); // Now we want to read all fields. manager.resetCaches(); PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); // Force the object to be de-serialized without any exceptions being thrown DomainObjectPdxAuto result = (DomainObjectPdxAuto) pdxIn.getObject(); assertEquals('\u0000', result.aChar); assertFalse(result.aBoolean); assertEquals(0, result.aByte); assertEquals(0, result.aShort); assertEquals(0, result.anInt); assertEquals(0L, result.aLong); assertEquals(0.0f, result.aFloat); assertEquals(0.0d, result.aDouble); assertEquals("aString has a value", result.get("aString")); }
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 testCheckPortablity() throws Exception { setupSerializer(true, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.BigHolder"); BigInteger bi = new BigInteger("12345678901234567890"); BigDecimal bd = new BigDecimal("1234567890.1234567890"); BigHolder bih = new BigHolder(bi, bd); HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); try { DataSerializer.writeObject(bih, out); fail("expected NonPortableClassException"); } catch (NonPortableClassException expected) { } }
public void testReadNullObjects() throws Exception { setupSerializer(stdSerializableClasses); // Don't want to write any fields DomainObjectPdxAuto objOut = new DomainObjectPdxAuto(4); objOut.anInteger = null; HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT); DataSerializer.writeObject(objOut, out); // Now we want to read all fields. manager.resetCaches(); PdxInstance pdxIn = DataSerializer.readObject(new DataInputStream( new ByteArrayInputStream(out.toByteArray()))); DomainObjectPdxAuto result = (DomainObjectPdxAuto) pdxIn.getObject(); assertNull(result.anInteger); assertNull(result.anEnum); }
private void setupSerializer(boolean checkPortability, String... classPatterns) { setupSerializer(new ReflectionBasedAutoSerializer(checkPortability, classPatterns), true); } private void setupSerializer(boolean checkPortability, boolean readSerialized, String... classPatterns) {
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 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 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) { fail("Expected SerializationException here but got " + ex); } }
private void setupSerializer(String... classPatterns) { setupSerializer(new ReflectionBasedAutoSerializer(classPatterns), true); } private void setupSerializer(boolean checkPortability, String... classPatterns) {
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 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 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 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) { fail("Expected NotSerializableException here but got " + ex); } }
public void testCHM() throws Exception { setupSerializer(new ConcurrentHashMapAutoSerializer(false, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.*Holder"), false); doCHM("with autoSerializer handling ConcurrentHashMap"); } public void testNoCHM() throws Exception {
public void testExtensibility() throws Exception { setupSerializer(new BigIntegerAutoSerializer(true, "com.gemstone.gemfire.pdx.AutoSerializableJUnitTest.BigHolder"), false); doExtensible("with autoSerializer handling Big*"); } public void testNoExtensibility() throws Exception {