private void check(BytesRefSorter sorter) throws Exception {
for (int i = 0; i < 100; i++) {
byte [] current = new byte [random().nextInt(256)];
random().nextBytes(current);
sorter.add(new BytesRef(current));
}
// Create two iterators and check that they're aligned with each other.
BytesRefIterator i1 = sorter.iterator();
BytesRefIterator i2 = sorter.iterator();
// Verify sorter contract.
try {
sorter.add(new BytesRef(new byte [1]));
fail("expected contract violation.");
} catch (IllegalStateException e) {
// Expected.
}
BytesRef spare1;
BytesRef spare2;
while ((spare1 = i1.next()) != null && (spare2 = i2.next()) != null) {
assertEquals(spare1, spare2);
}
assertNull(i1.next());
assertNull(i2.next());