public void test_allocationContexts() throws IOException {
  final Journal store=(Journal)getStore();
  try {
    final RWStrategy bs=(RWStrategy)store.getBufferStrategy();
    final RWStore rw=bs.getStore();
    final IAllocationContext allocContext1=rw.newAllocationContext(true);
    final IAllocationContext allocContext2=rw.newAllocationContext(true);
    final int sze=650;
    final byte[] buf=new byte[sze + 4];
    r.nextBytes(buf);
    final long addr1a=bs.write(ByteBuffer.wrap(buf),allocContext1);
    final long addr1b=bs.write(ByteBuffer.wrap(buf),allocContext1);
    rw.detachContext(allocContext1);
    final long addr2a=bs.write(ByteBuffer.wrap(buf),allocContext2);
    final long addr2b=bs.write(ByteBuffer.wrap(buf),allocContext2);
    rw.detachContext(allocContext2);
    try {
      bs.write(ByteBuffer.wrap(buf),allocContext1);
      fail("Should have failed to re-use detached context");
    }
 catch (    IllegalStateException ise) {
    }
    final IAllocationContext allocContext3=rw.newAllocationContext(true);
    final long addr1c=bs.write(ByteBuffer.wrap(buf),allocContext3);
    assertTrue("allocator re-use",bs.getPhysicalAddress(addr1c) > bs.getPhysicalAddress(addr2b));
    bs.delete(addr1c,allocContext3);
    final long addr1d=bs.write(ByteBuffer.wrap(buf),allocContext3);
    assertTrue("re-allocation",addr1c == addr1d);
    rw.detachContext(allocContext3);
    store.commit();
    bs.delete(addr1d);
    final long addr1e=bs.write(ByteBuffer.wrap(buf));
    assertTrue("deferred-delete",addr1e != addr1d);
    store.commit();
  }
  finally {
    store.destroy();
  }
}

public void test_allocationContexts ( ) throws IOException { final Journal store = ( Journal ) getStore ( ) ; try { final RWStrategy bs = ( RWStrategy ) store . getBufferStrategy ( ) ; final RWStore rw = bs . getStore ( ) ; final IAllocationContext allocContext1 = rw . newAllocationContext ( true ) ; final IAllocationContext allocContext2 = rw . newAllocationContext ( true ) ; final int sze = 650 ; final byte [ ] buf = new byte [ sze + 4 ] ; r . nextBytes ( buf ) ; final long addr1a = bs . write ( ByteBuffer . wrap ( buf ) , allocContext1 ) ; final long addr1b = bs . write ( ByteBuffer . wrap ( buf ) , allocContext1 ) ; rw . detachContext ( allocContext1 ) ; final long addr2a = bs . write ( ByteBuffer . wrap ( buf ) , allocContext2 ) ; final long addr2b = bs . write ( ByteBuffer . wrap ( buf ) , allocContext2 ) ; rw . detachContext ( allocContext2 ) ; try { bs . write ( ByteBuffer . wrap ( buf ) , allocContext1 ) ; fail ( "Should have failed to re-use detached context" ) ; } catch ( IllegalStateException ise ) { } final IAllocationContext allocContext3 = rw . newAllocationContext ( true ) ; final long addr1c = bs . write ( ByteBuffer . wrap ( buf ) , allocContext3 ) ; assertTrue ( "allocator re-use" , bs . getPhysicalAddress ( addr1c ) > bs . getPhysicalAddress ( addr2b ) ) ; bs . delete ( addr1c , allocContext3 ) ; final long addr1d = bs . write ( ByteBuffer . wrap ( buf ) , allocContext3 ) ; assertTrue ( "re-allocation" , addr1c == addr1d ) ; rw . detachContext ( allocContext3 ) ; store . commit ( ) ; bs . delete ( addr1d ) ; final long addr1e = bs . write ( ByteBuffer . wrap ( buf ) ) ; assertTrue ( "deferred-delete" , addr1e != addr1d ) ; store . commit ( ) ; } finally { store . destroy ( ) ; } }
from a rwstore , creates multiple allocationcontexts to isolate updates , re - allocate storage and protect against by concurrent contexts . this is the core functionality required to support transactions . if an allocation is made for an allocationcontext then this will result in a contextallocation object being created in the rwstore within which " shadow " allocations can be made . if such a shadow allocation is deleted , within the allocationcontext , then this can be removed immediately .
