예제 #1
0
  @Test
  public void testPooledIteratorBrokenForEach() {
    // A) for-each loop interrupted

    // must accommodate even the smallest primitive type
    // so that the iteration do not break before it should...
    final int TEST_SIZE = 126;
    final long TEST_ROUNDS = 5000;

    final KTypeSet<KType> testContainer = createSetWithOrderedData(TEST_SIZE);

    int count = 0;
    for (int round = 0; round < TEST_ROUNDS; round++) {
      // for-each in test :
      final long initialPoolSize = getEntryPoolSize(testContainer);

      count = 0;
      int guard = 0;
      for (final KTypeCursor<KType> cursor : testContainer) {
        guard += castType(cursor.value);
        // we consume 1 iterator for this loop, but reallocs can happen,
        // so we can only say its != initialPoolSize
        Assert.assertTrue(initialPoolSize != getEntryPoolSize(testContainer));

        // brutally interrupt in the middle
        if (count > TEST_SIZE / 2) {
          break;
        }

        count++;
      } // end for-each

      // iterator is NOT returned to its pool, due to the break.
      // reallocation could happen, so that the only testable thing
      // is that the size is != full pool
      Assert.assertTrue(initialPoolSize != getEntryPoolSize(testContainer));
    } // end for rounds

    // Due to policy of the Iterator pool, the intended pool never get bigger that some limit
    // despite the Iterator leak.
    Assert.assertTrue(getEntryPoolCapacity(testContainer) < IteratorPool.getMaxPoolSize() + 1);
  }
예제 #2
0
 @BeforeClass
 public static void configure() {
   IteratorPool.configureInitialPoolSize(8);
 }