public void testUnisolatedAllocationContextRecycling(){
  final Journal store=(Journal)getStore(0);
  try {
    final RWStrategy bufferStrategy=(RWStrategy)store.getBufferStrategy();
    final RWStore rw=bufferStrategy.getStore();
    final IAllocationContext cntxt=rw.newAllocationContext(false);
    final int allocs=1000;
    final PseudoRandom ran=new PseudoRandom(20000);
    final ArrayList<Integer> addrs=new ArrayList<Integer>();
    final ArrayList<Integer> sizes=new ArrayList<Integer>();
    for (int a=0; a < allocs; a++) {
      final int sze=32 + ran.nextInt(1200);
      addrs.add(rw.alloc(sze,cntxt));
      sizes.add(sze);
    }
    store.commit();
    IAllocationContext iso_cntxt=rw.newAllocationContext(true);
    for (int a=0; a < 3; a++) {
      rw.alloc(32 + ran.nextInt(1200),iso_cntxt);
    }
    if (log.isInfoEnabled()) {
      final StringBuilder str=new StringBuilder();
      rw.showAllocators(str);
      log.info(str);
    }
    for (int a=0; a < 36; a++) {
      rw.free(addrs.get(a),sizes.get(a),cntxt);
    }
    store.abort();
    for (int a=0; a < 36; a++) {
      final int rwaddr=addrs.get(a);
      if (log.isInfoEnabled())       log.info("Address: " + rw.physicalAddress(rwaddr) + ", Committed: "+ rw.isCommitted(rwaddr));
    }
    log.info("INTERMEDIATE COMMIT");
    for (int a=0; a < 36; a++) {
      final int rwaddr=addrs.get(a);
      if (log.isInfoEnabled())       log.info("Address: " + rw.physicalAddress(rwaddr) + ", Committed: "+ rw.isCommitted(rwaddr)+ ", Index: "+ getIndex(rwaddr));
    }
    log.info("DETACH CONTEXT");
    rw.detachContext(iso_cntxt);
    for (int a=0; a < 36; a++) {
      final int rwaddr=addrs.get(a);
      if (log.isInfoEnabled())       log.info("Address: " + rw.physicalAddress(rwaddr) + ", Committed: "+ rw.isCommitted(rwaddr)+ ", Index: "+ getIndex(rwaddr));
    }
    store.commit();
    log.info("COMMIT");
    for (int a=0; a < 36; a++) {
      final int rwaddr=addrs.get(a);
      if (log.isInfoEnabled())       log.info("Address: " + rw.physicalAddress(rwaddr) + ", Committed: "+ rw.isCommitted(rwaddr)+ ", Index: "+ getIndex(rwaddr));
    }
    store.commit();
    log.info("SECONDARY");
    for (int a=0; a < 36; a++) {
      final int rwaddr=addrs.get(a);
      if (log.isInfoEnabled())       log.info("Address: " + rw.physicalAddress(rwaddr) + ", Committed: "+ rw.isCommitted(rwaddr)+ ", Index: "+ getIndex(rwaddr));
    }
  }
  finally {
    store.destroy();
  }
}

public void testUnisolatedAllocationContextRecycling ( ) { final Journal store = ( Journal ) getStore ( 0 ) ; try { final RWStrategy bufferStrategy = ( RWStrategy ) store . getBufferStrategy ( ) ; final RWStore rw = bufferStrategy . getStore ( ) ; final IAllocationContext cntxt = rw . newAllocationContext ( false ) ; final int allocs = 1000 ; final PseudoRandom ran = new PseudoRandom ( 20000 ) ; final ArrayList < Integer > addrs = new ArrayList < Integer > ( ) ; final ArrayList < Integer > sizes = new ArrayList < Integer > ( ) ; for ( int a = 0 ; a < allocs ; a ++ ) { final int sze = 32 + ran . nextInt ( 1200 ) ; addrs . add ( rw . alloc ( sze , cntxt ) ) ; sizes . add ( sze ) ; } store . commit ( ) ; IAllocationContext iso_cntxt = rw . newAllocationContext ( true ) ; for ( int a = 0 ; a < 3 ; a ++ ) { rw . alloc ( 32 + ran . nextInt ( 1200 ) , iso_cntxt ) ; } if ( log . isInfoEnabled ( ) ) { final StringBuilder str = new StringBuilder ( ) ; rw . showAllocators ( str ) ; log . info ( str ) ; } for ( int a = 0 ; a < 36 ; a ++ ) { rw . free ( addrs . get ( a ) , sizes . get ( a ) , cntxt ) ; } store . abort ( ) ; for ( int a = 0 ; a < 36 ; a ++ ) { final int rwaddr = addrs . get ( a ) ; if ( log . isInfoEnabled ( ) ) log . info ( "Address: " + rw . physicalAddress ( rwaddr ) + ", Committed: " + rw . isCommitted ( rwaddr ) ) ; } log . info ( "INTERMEDIATE COMMIT" ) ; for ( int a = 0 ; a < 36 ; a ++ ) { final int rwaddr = addrs . get ( a ) ; if ( log . isInfoEnabled ( ) ) log . info ( "Address: " + rw . physicalAddress ( rwaddr ) + ", Committed: " + rw . isCommitted ( rwaddr ) + ", Index: " + getIndex ( rwaddr ) ) ; } log . info ( "DETACH CONTEXT" ) ; rw . detachContext ( iso_cntxt ) ; for ( int a = 0 ; a < 36 ; a ++ ) { final int rwaddr = addrs . get ( a ) ; if ( log . isInfoEnabled ( ) ) log . info ( "Address: " + rw . physicalAddress ( rwaddr ) + ", Committed: " + rw . isCommitted ( rwaddr ) + ", Index: " + getIndex ( rwaddr ) ) ; } store . commit ( ) ; log . info ( "COMMIT" ) ; for ( int a = 0 ; a < 36 ; a ++ ) { final int rwaddr = addrs . get ( a ) ; if ( log . isInfoEnabled ( ) ) log . info ( "Address: " + rw . physicalAddress ( rwaddr ) + ", Committed: " + rw . isCommitted ( rwaddr ) + ", Index: " + getIndex ( rwaddr ) ) ; } store . commit ( ) ; log . info ( "SECONDARY" ) ; for ( int a = 0 ; a < 36 ; a ++ ) { final int rwaddr = addrs . get ( a ) ; if ( log . isInfoEnabled ( ) ) log . info ( "Address: " + rw . physicalAddress ( rwaddr ) + ", Committed: " + rw . isCommitted ( rwaddr ) + ", Index: " + getIndex ( rwaddr ) ) ; } } finally { store . destroy ( ) ; } }
need to test the handling of aborted unisolated connections and specifically the logic behind freed addresses . < p > the process is to : allocate a range of data ( to establish a number of allocators ) create an isolated context and allocate a handful more create an unisolated context free some committed addreses abort the unisolated context - calling abort on the journal commit the isolated context observe if any of the previously committed data is freed !
