Package com.xuggle.ferry

Examples of com.xuggle.ferry.RefCountedTester


  @Test
  public void testCorrectStartingRefCount()
  {
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());
    RefCountedTester obj = RefCountedTester.make();
    assertEquals("starting ref count", 1, obj.getCurrentRefCount());
    obj.delete();
  }
View Full Code Here


  @Test
  public void testJavaCopyKeepsRefcountConstant()
  {
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());
    RefCountedTester obj = RefCountedTester.make();
    assertEquals("starting ref count", 1, obj.getCurrentRefCount());
    RefCountedTester javaCopy = obj;
    assertEquals("java copy should keep ref the same", 1, javaCopy.getCurrentRefCount());
    javaCopy.delete();
    obj.delete();
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());
  }
View Full Code Here

  @Test(timeout=20*1000)
  public void testNativeCopyRefcountIncrement() throws InterruptedException
  {
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());
    RefCountedTester obj = RefCountedTester.make();
    assertEquals("starting ref count", 1, obj.getCurrentRefCount());
    RefCountedTester nativeCopy = RefCountedTester.make(obj);
    assertEquals("native copy should increment", 2, obj.getCurrentRefCount());
    assertEquals("native copy should increment", 2, nativeCopy.getCurrentRefCount());
    nativeCopy.delete();
    nativeCopy = null;
    assertEquals("native copy should be decremented", 1, obj.getCurrentRefCount());
    obj.delete();
    obj = null;
    while(JNIReference.getMgr().getNumPinnedObjects() > 0)
View Full Code Here

  @Test(timeout=20*1000)
  public void testCopyByReference() throws InterruptedException
  {
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());
    RefCountedTester obj1 = RefCountedTester.make();
   
    RefCountedTester obj2 = obj1.copyReference();
   
    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());
   
    obj1.delete(); obj1 = null;
    assertEquals("should now have refcount of 1", 1, obj2.getCurrentRefCount());
    obj2.delete();
    obj2 = null;
    while(JNIReference.getMgr().getNumPinnedObjects() > 0)
    {
      byte[] bytes = new byte[1024*1024];
      bytes[0] = 0;
View Full Code Here

  throws InterruptedException
  {
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());

    RefCountedTester obj1 = RefCountedTester.make();
   
    RefCountedTester obj2 = obj1.copyReference();
   
    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());
   
    obj1 = null;
   
    // obj1 should now be unreachable, so if we try a Garbage collection it should get caught.
    while(JNIReference.getMgr().getNumPinnedObjects() > 1)
    {
      byte[] bytes = new byte[1024*1024];
      bytes[0] = 0;
      JNIReference.getMgr().gc();
    }
    // at this point the Java proxy object will be unreachable, but should be sitting in the
    // reference queue and also awaiting finalization.  The finalization should have occurred by now.
    assertEquals("should be only the first object for collection",
        1, JNIReference.getMgr().getNumPinnedObjects());       
    assertEquals("should have a ref refcount of 1", 1, obj2.getCurrentRefCount());

    obj2.delete();
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());

  }
View Full Code Here

  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());

  }
View Full Code Here

   * the JVM
   */
  @Test(expected=NullPointerException.class)
  public void testDeleteThenCallRaisesException()
  {
    RefCountedTester obj = RefCountedTester.make();
    obj.delete();
    // this should raise an exception
    obj.getCurrentRefCount();
    assertEquals("should be no objects for collection",
        0, JNIReference.getMgr().getNumPinnedObjects());

  }
View Full Code Here

TOP

Related Classes of com.xuggle.ferry.RefCountedTester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.