for (int i = 0; i < 4; i++) {
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
Mutation m = new Mutation(new Text(String.format("r_%10d", row)));
m.put(new Text("cf"), new Text("cq"), new Value(("" + row).getBytes()));
bw.addMutation(m);
}
bw.flush();
// do a few random lookups into the data just flushed
for (int k = 0; k < 10; k++) {
int rowToLookup = r.nextInt(NUM_TO_FLUSH) + i * NUM_TO_FLUSH;
scanner.setRange(new Range(new Text(String.format("r_%10d", rowToLookup))));
Iterator<Entry<Key,Value>> iter = scanner.iterator();
if (!iter.hasNext())
throw new Exception(" row " + rowToLookup + " not found after flush");
Entry<Key,Value> entry = iter.next();
if (iter.hasNext())
throw new Exception("Scanner returned too much");
verifyEntry(rowToLookup, entry);
}
// scan all data just flushed
scanner.setRange(new Range(new Text(String.format("r_%10d", i * NUM_TO_FLUSH)), true, new Text(String.format("r_%10d", (i + 1) * NUM_TO_FLUSH)), false));
Iterator<Entry<Key,Value>> iter = scanner.iterator();
for (int j = 0; j < NUM_TO_FLUSH; j++) {
int row = i * NUM_TO_FLUSH + j;
if (!iter.hasNext())
throw new Exception("Scan stopped permaturely at " + row);
Entry<Key,Value> entry = iter.next();
verifyEntry(row, entry);
}
if (iter.hasNext())
throw new Exception("Scanner returned too much");
}
bw.close();
// test adding a mutation to a closed batch writer
boolean caught = false;
try {
bw.addMutation(new Mutation(new Text("foobar")));
} catch (IllegalStateException ise) {
caught = true;
}
if (!caught) {