public void testStressAllocationContextRecycling(){
  final Journal store=(Journal)getStore(1);
  try {
    final RWStrategy bufferStrategy=(RWStrategy)store.getBufferStrategy();
    final RWStore rw=bufferStrategy.getStore();
    final IAllocationContext cntxt=rw.newAllocationContext(true);
    final int allocs=100000;
    final Random ran=new Random();
    for (int r=0; r < 20; r++) {
      ArrayList<Integer> addrs=new ArrayList<Integer>();
      for (int a=0; a < allocs; a++) {
        addrs.add(rw.alloc(50,cntxt));
      }
      final PseudoRandom ps=new PseudoRandom(allocs,ran.nextInt(allocs));
      for (      int a : addrs) {
        rw.free(addrs.get(ps.next()),50,cntxt);
      }
    }
    assertTrue(rw.getFixedAllocatorCount() < 20);
    if (log.isInfoEnabled()) {
      final StringBuilder str=new StringBuilder();
      rw.showAllocators(str);
      log.info(str);
    }
    store.commit();
  }
  finally {
    store.destroy();
  }
}

public void testStressAllocationContextRecycling ( ) { final Journal store = ( Journal ) getStore ( 1 ) ; try { final RWStrategy bufferStrategy = ( RWStrategy ) store . getBufferStrategy ( ) ; final RWStore rw = bufferStrategy . getStore ( ) ; final IAllocationContext cntxt = rw . newAllocationContext ( true ) ; final int allocs = 100000 ; final Random ran = new Random ( ) ; for ( int r = 0 ; r < 20 ; r ++ ) { ArrayList < Integer > addrs = new ArrayList < Integer > ( ) ; for ( int a = 0 ; a < allocs ; a ++ ) { addrs . add ( rw . alloc ( 50 , cntxt ) ) ; } final PseudoRandom ps = new PseudoRandom ( allocs , ran . nextInt ( allocs ) ) ; for ( int a : addrs ) { rw . free ( addrs . get ( ps . next ( ) ) , 50 , cntxt ) ; } } assertTrue ( rw . getFixedAllocatorCount ( ) < 20 ) ; if ( log . isInfoEnabled ( ) ) { final StringBuilder str = new StringBuilder ( ) ; rw . showAllocators ( str ) ; log . info ( str ) ; } store . commit ( ) ; } finally { store . destroy ( ) ; } }
this tests whether allocationcontexts efficiently recycle transient allocations . to do this it will allocate and free 1 million 50 byte regions , in batches of 10k .
