You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by al...@apache.org on 2007/06/06 22:17:40 UTC

svn commit: r544935 - /incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java

Author: alally
Date: Wed Jun  6 13:17:39 2007
New Revision: 544935

URL: http://svn.apache.org/viewvc?view=rev&rev=544935
Log:
UIMA-440: https://issues.apache.org/jira/browse/UIMA-440
Test case for issue with CAS heap growing excessively.

Modified:
    incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java

Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java?view=diff&rev=544935&r1=544934&r2=544935
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/impl/CasResetResizeTest.java Wed Jun  6 13:17:39 2007
@@ -52,26 +52,47 @@
       TextAnalysisEngine taeDefault = UIMAFramework.produceTAE(testDescriptor);
       CAS cas = taeDefault.newCAS();
       int heapSize = ((CASImpl) cas).getHeap().getCurrentTempSize();
-      // System.out.println("Heap size: " + heapSize + ", buffer size: " + ((CASImpl)
-      // cas).getHeap().heap.length);
-      Assert.assertTrue(heapSize < CASImpl.DEFAULT_RESET_HEAP_SIZE);
-      assertTrue(heapSize <= ((CASImpl) cas).getHeap().heap.length);
+      int bufSize = ((CASImpl)cas).getHeap().heap.length;
+      //System.out.println("Heap size: " + heapSize + ", buffer size: " + bufSize);       
+      Assert.assertTrue(bufSize < CASImpl.DEFAULT_RESET_HEAP_SIZE);
+      assertTrue(heapSize <= bufSize);
+      
+      //create enough annotations to exceed the DEFAULT_RESET_HEAP_SIZE
       Type annotType = cas.getTypeSystem().getType(CAS.TYPE_NAME_ANNOTATION);
       for (int i = 0; i < 2000000; i++) {
         cas.createAnnotation(annotType, i, i);
       }
+      
       heapSize = ((CASImpl) cas).getHeap().getCurrentTempSize();
-      // System.out.println("Heap size: " + heapSize + ", buffer size: " + ((CASImpl)
-      // cas).getHeap().heap.length);
-      assertTrue(heapSize <= ((CASImpl) cas).getHeap().heap.length);
+      bufSize = ((CASImpl)cas).getHeap().heap.length;
+      //System.out.println("Heap size: " + heapSize + ", buffer size: " + bufSize);      
+      assertTrue(heapSize <= bufSize);
       Assert.assertTrue(heapSize > CASImpl.DEFAULT_RESET_HEAP_SIZE);
+      
+      //reset the CAS - it should shrink
       cas.reset();
       heapSize = ((CASImpl) cas).getHeap().getCurrentTempSize();
-      // System.out.println("Heap size: " + heapSize + ", buffer size: " + ((CASImpl)
-      // cas).getHeap().heap.length);
-      assertTrue(heapSize <= ((CASImpl) cas).getHeap().heap.length);
-      Assert.assertTrue(heapSize < CASImpl.DEFAULT_RESET_HEAP_SIZE);
+      bufSize = ((CASImpl)cas).getHeap().heap.length;
+      //System.out.println("Heap size: " + heapSize + ", buffer size: " + bufSize);
+      assertTrue(heapSize <= bufSize);
+      Assert.assertTrue(bufSize < CASImpl.DEFAULT_RESET_HEAP_SIZE);
 
+      
+      //If instead we create the annotations in smaller chunks and reset each time,
+      //the CAS buffer size shouldn't grow    
+      for (int j = 0; j < 10; j++) {
+        for (int i = 0; i < 200000; i++) {
+          cas.createAnnotation(annotType, i, i);
+        }
+        
+        heapSize = ((CASImpl) cas).getHeap().getCurrentTempSize();
+        bufSize = ((CASImpl)cas).getHeap().heap.length;
+        //System.out.println("Heap size: " + heapSize + ", buffer size: " + bufSize);      
+        assertTrue(heapSize <= bufSize);
+        Assert.assertTrue(bufSize < CASImpl.DEFAULT_RESET_HEAP_SIZE);      
+        cas.reset();
+      }
+  
     } catch (Exception e) {
       JUnitExtension.handleException(e);
     }