private static void printDocs(DirectoryReader r) throws Throwable {
   for (AtomicReaderContext ctx : r.leaves()) {
     // TODO: improve this
     AtomicReader sub = ctx.reader();
     Bits liveDocs = sub.getLiveDocs();
     System.out.println("  " + ((SegmentReader) sub).getSegmentInfo());
     for (int docID = 0; docID < sub.maxDoc(); docID++) {
       StoredDocument doc = sub.document(docID);
       if (liveDocs == null || liveDocs.get(docID)) {
         System.out.println("    docID=" + docID + " id:" + doc.get("id"));
       } else {
         System.out.println("    DEL docID=" + docID + " id:" + doc.get("id"));
       }
     }
   }
 }
  public static void verifyEquals(StoredDocument d1, StoredDocument d2) {
    List<StorableField> ff1 = d1.getFields();
    List<StorableField> ff2 = d2.getFields();

    Collections.sort(ff1, fieldNameComparator);
    Collections.sort(ff2, fieldNameComparator);

    assertEquals(ff1 + " : " + ff2, ff1.size(), ff2.size());

    for (int i = 0; i < ff1.size(); i++) {
      StorableField f1 = ff1.get(i);
      StorableField f2 = ff2.get(i);
      if (f1.binaryValue() != null) {
        assert (f2.binaryValue() != null);
      } else {
        String s1 = f1.stringValue();
        String s2 = f2.stringValue();
        assertEquals(ff1 + " : " + ff2, s1, s2);
      }
    }
  }