public void testJNIWeakReferenceFlushQueue() throws InterruptedException
{
assertEquals("should be no objects for collection",
0, JNIReference.getMgr().getNumPinnedObjects());
RefCountedTester obj1 = RefCountedTester.make();
assertEquals("should be no objects for collection",
1, JNIReference.getMgr().getNumPinnedObjects());
RefCountedTester obj2 = obj1.copyReference();
assertEquals("should be no objects for collection",
2, JNIReference.getMgr().getNumPinnedObjects());
assertTrue("should look like different objects", obj1 != obj2);
assertTrue("should be equal though", obj1.equals(obj2));
assertEquals("should have same ref count",
obj1.getCurrentRefCount(), obj2.getCurrentRefCount());
assertEquals("should have ref count of 2", 2, obj2.getCurrentRefCount());
assertEquals("should be no objects for collection",
2, JNIReference.getMgr().getNumPinnedObjects());
//obj1.delete();
obj1 = null;
// obj1 should now be unreachable, so if we try a Garbage collection it should get caught.
while(obj2.getCurrentRefCount() > 1)
{
byte[] bytes = new byte[1024*1024];
bytes[0] = 0;
JNIReference.getMgr().gc();
}
assertEquals("should now have a ref refcount of 1", 1, obj2.getCurrentRefCount());
assertEquals("should be only the first object for collection",
1, JNIReference.getMgr().getNumPinnedObjects());
obj2.delete();
assertEquals("should be no objects for collection",
0, JNIReference.getMgr().getNumPinnedObjects());
}