calledResolve=0;
Object domain2 = null;
for (int i=0;i<20;i++)
{
ByteArrayInputStream byteInpt = new ByteArrayInputStream(byteOut.toByteArray());
JBossObjectInputStream is = new JBossObjectInputStream(byteInpt)
{
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
try
{
calledResolve++;
return super.resolveClass(desc);
}
catch (Throwable e)
{
e.printStackTrace(System.out);
return null;
}
}
};
domain2= is.readObject();
}
assertNotSame(domain,domain2);
if (domain instanceof String[])
{
assertTrue(Arrays.equals((String[])domain, (String[])domain2));
}
else
{
assertEquals(domain,domain2);
}
assertTrue("ReadResolve wasn't called",calledResolve>0);
if (domain instanceof TestNonSerializableSDF )
{
assertTrue("ReadResolve was called too often",calledResolve<20);
}
else
{
assertTrue("ReadResolve was called too often",calledResolve<10);
}
calledResolve=0;
for (int i=0;i<20;i++)
{
ClassMetamodelFactory.clear(false);
ByteArrayInputStream byteInpt = new ByteArrayInputStream(byteOut.toByteArray());
JBossObjectInputStream is = new JBossObjectInputStream(byteInpt)
{
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
calledResolve++;
return super.resolveClass(desc);
}
};
domain2= is.readObject();
}
assertTrue("ReadResolve wasn't called as often as it should be",calledResolve>10);
calledResolve=0;
ClassMetamodelFactory.clear(false);
for (int i=0;i<20;i++)
{
ByteArrayInputStream byteInpt = new ByteArrayInputStream(byteOut.toByteArray());
JBossObjectInputStream is = new JBossObjectInputStreamSharedTree(byteInpt)
{
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
calledResolve++;
return super.resolveClass(desc);
}
};
domain2= is.readObject();
}
assertTrue("ReadResolve wasn't called for shared tree",calledResolve>0);
calledResolve=0;
for (int i=0;i<20;i++)
{
ByteArrayInputStream byteInpt = new ByteArrayInputStream(byteOut.toByteArray());
JBossObjectInputStream is = new JBossObjectInputStreamSharedTree(byteInpt)
{
protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
calledResolve++;
return super.resolveClass(desc);
}
};
domain2= is.readObject();
}
assertTrue("ReadResolve wasn't supposed to be called here",calledResolve==0);
}
catch (Throwable e)