public void test_multipleWrites(){
  final IRawStore store=getStore();
  try {
    final int limit=100;
    final long[] addrs=new long[limit];
    final byte[][] records=new byte[limit][];
    for (int i=0; i < limit; i++) {
      final byte[] expected=new byte[r.nextInt(100) + 1];
      r.nextBytes(expected);
      final ByteBuffer tmp=ByteBuffer.wrap(expected);
      final 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;
    }
    final int[] order=getRandomOrder(limit);
    for (int i=0; i < limit; i++) {
      final long addr=addrs[order[i]];
      final byte[] expected=records[order[i]];
      assertEquals(expected,store.read(addr));
    }
  }
  finally {
    store.destroy();
  }
}

public void test_multipleWrites ( ) { final IRawStore store = getStore ( ) ; try { final int limit = 100 ; final long [ ] addrs = new long [ limit ] ; final byte [ ] [ ] records = new byte [ limit ] [ ] ; for ( int i = 0 ; i < limit ; i ++ ) { final byte [ ] expected = new byte [ r . nextInt ( 100 ) + 1 ] ; r . nextBytes ( expected ) ; final ByteBuffer tmp = ByteBuffer . wrap ( expected ) ; final 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 ; } final int [ ] order = getRandomOrder ( limit ) ; for ( int i = 0 ; i < limit ; i ++ ) { final long addr = addrs [ order [ i ] ] ; final 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 .
