@SmallTest
  public void testRun() throws Exception {
    MemoryFile file = new MemoryFile("MemoryFileTest", 1000000);

    byte[] buffer = new byte[testString.length];

    // check low level accessors
    file.writeBytes(testString, 0, 2000, testString.length);
    file.readBytes(buffer, 2000, 0, testString.length);
    compareBuffers(testString, buffer, testString.length);

    // check streams
    buffer = new byte[testString.length];

    OutputStream os = file.getOutputStream();
    os.write(testString);

    InputStream is = file.getInputStream();
    is.mark(testString.length);
    is.read(buffer);
    compareBuffers(testString, buffer, testString.length);

    // test mark/reset
    buffer = new byte[testString.length];
    is.reset();
    is.read(buffer);
    compareBuffers(testString, buffer, testString.length);

    file.close();
  }
 /** Keep allocating new files till the system purges them. */
 @MediumTest
 public void testPurge() throws Exception {
   List<MemoryFile> files = new ArrayList<MemoryFile>();
   while (true) {
     MemoryFile newFile = new MemoryFile("MemoryFileTest", 1000000);
     newFile.allowPurging(true);
     newFile.writeBytes(testString, 0, 0, testString.length);
     files.add(newFile);
     for (MemoryFile file : files) {
       try {
         file.readBytes(testString, 0, 0, testString.length);
       } catch (IOException e) {
         // Expected
         for (MemoryFile fileToClose : files) {
           fileToClose.close();
         }
         return;
       }
     }
   }
 }