public void test_restartSafe_multipleWrites(){
  IAtomicStore store=(IAtomicStore)getStore();
  try {
    assertTrue(store.isStable());
    Random r=new Random();
    final int limit=100;
    final long[] addrs=new long[limit];
    final byte[][] records=new byte[limit][];
    for (int i=0; i < limit; i++) {
      byte[] expected=new byte[r.nextInt(100) + 1];
      r.nextBytes(expected);
      ByteBuffer tmp=ByteBuffer.wrap(expected);
      long addr=store.write(tmp);
      assertEquals(expected.length,tmp.position());
      assertEquals(tmp.position(),tmp.limit());
      assertEquals(expected,store.read(addr));
      addrs[i]=addr;
      records[i]=expected;
    }
    int[] order=getRandomOrder(limit);
    for (int i=0; i < limit; i++) {
      long addr=addrs[order[i]];
      byte[] expected=records[order[i]];
      assertEquals(expected,store.read(addr));
    }
    store.commit();
    store=(IAtomicStore)reopenStore(store);
    assertTrue(store.isStable());
    order=getRandomOrder(limit);
    for (int i=0; i < limit; i++) {
      long addr=addrs[order[i]];
      byte[] expected=records[order[i]];
      assertEquals(expected,store.read(addr));
    }
  }
  finally {
    store.destroy();
  }
}

public void test_restartSafe_multipleWrites ( ) { IAtomicStore store = ( IAtomicStore ) getStore ( ) ; try { assertTrue ( store . isStable ( ) ) ; Random r = new Random ( ) ; final int limit = 100 ; final long [ ] addrs = new long [ limit ] ; final byte [ ] [ ] records = new byte [ limit ] [ ] ; for ( int i = 0 ; i < limit ; i ++ ) { byte [ ] expected = new byte [ r . nextInt ( 100 ) + 1 ] ; r . nextBytes ( expected ) ; ByteBuffer tmp = ByteBuffer . wrap ( expected ) ; long addr = store . write ( tmp ) ; assertEquals ( expected . length , tmp . position ( ) ) ; assertEquals ( tmp . position ( ) , tmp . limit ( ) ) ; assertEquals ( expected , store . read ( addr ) ) ; addrs [ i ] = addr ; records [ i ] = expected ; } int [ ] order = getRandomOrder ( limit ) ; for ( int i = 0 ; i < limit ; i ++ ) { long addr = addrs [ order [ i ] ] ; byte [ ] expected = records [ order [ i ] ] ; assertEquals ( expected , store . read ( addr ) ) ; } store . commit ( ) ; store = ( IAtomicStore ) reopenStore ( store ) ; assertTrue ( store . isStable ( ) ) ; order = getRandomOrder ( limit ) ; for ( int i = 0 ; i < limit ; i ++ ) { long addr = addrs [ order [ i ] ] ; byte [ ] expected = records [ order [ i ] ] ; assertEquals ( expected , store . read ( addr ) ) ; } } finally { store . destroy ( ) ; } }
test writes a bunch of records and verifies that each can be read after it is written . the test then performs a random order read and verifies that each of the records can be read correctly .
