public void test_copyStream_smallRandomStreams() throws IOException {
  final int LIMIT=20;
  final Random r=new Random();
  int nzero=0;
  int nfull=0;
  for (int i=0; i < LIMIT; i++) {
    final String id="test#" + r.nextInt(1000);
    final int version=i;
    final int len;
{
      final int x=r.nextInt(100);
      if (x < 10) {
        len=r.nextInt(5);
      }
 else       if (x >= 90) {
        len=r.nextInt(5) + BLOCK_SIZE - 4;
      }
 else {
        len=r.nextInt(BLOCK_SIZE + 1);
      }
    }
    if (len == 0)     nzero++;
    if (len == BLOCK_SIZE)     nfull++;
    final byte[] expected=new byte[len];
    r.nextBytes(expected);
    assertEquals("nbytes",expected.length,repo.copyStream(id,version,new ByteArrayInputStream(expected)));
    assertEquals("blockCount",1,repo.getBlockCount(id,version));
    assertSameIterator("block identifiers",new Long[]{0L},repo.blocks(id,version));
    assertEquals("data",expected,read(repo.inputStream(id,version)));
  }
  log.warn("There were " + nzero + " zero length blocks and "+ nfull+ " full length blocks out of "+ LIMIT+ " trials");
}

public void test_copyStream_smallRandomStreams ( ) throws IOException { final int LIMIT = 20 ; final Random r = new Random ( ) ; int nzero = 0 ; int nfull = 0 ; for ( int i = 0 ; i < LIMIT ; i ++ ) { final String id = "test#" + r . nextInt ( 1000 ) ; final int version = i ; final int len ; { final int x = r . nextInt ( 100 ) ; if ( x < 10 ) { len = r . nextInt ( 5 ) ; } else if ( x >= 90 ) { len = r . nextInt ( 5 ) + BLOCK_SIZE - 4 ; } else { len = r . nextInt ( BLOCK_SIZE + 1 ) ; } } if ( len == 0 ) nzero ++ ; if ( len == BLOCK_SIZE ) nfull ++ ; final byte [ ] expected = new byte [ len ] ; r . nextBytes ( expected ) ; assertEquals ( "nbytes" , expected . length , repo . copyStream ( id , version , new ByteArrayInputStream ( expected ) ) ) ; assertEquals ( "blockCount" , 1 , repo . getBlockCount ( id , version ) ) ; assertSameIterator ( "block identifiers" , new Long [ ] { 0L } , repo . blocks ( id , version ) ) ; assertEquals ( "data" , expected , read ( repo . inputStream ( id , version ) ) ) ; } log . warn ( "There were " + nzero + " zero length blocks and " + nfull + " full length blocks out of " + LIMIT + " trials" ) ; }
stress test writing small streams of random length ( from zero bytes to a full block in length ) .
