final int threadID = i;
threads[i] = new Thread() {
public void run() {
for (int ii = 0; ii < ITERATIONS; ii++) {
Key key = new Key("T" + threadID + "I" + ii);
Value value = new Value("<test thread=\"" + threadID + "\" iteration=\"" + ii + "\"/>");
try {
filer.writeRecord(key, value);
} catch (Exception e) {
e.printStackTrace();
}
}
// System.out.println(getName() + " done.");
}
};
threads[i].setName("FilerTest" + i);
}
// Start all the threads at once
for (int i = 0; i < THREADS; i++) {
threads[i].start();
}
Thread.sleep(1000);
for (int i = 0; i < THREADS; i++) {
threads[i].join();
}
filer.flush();
// Check results
assertEquals(filer.getRecordCount(), THREADS * ITERATIONS);
for (int i = 0; i < THREADS; i++) {
for (int ii = 0; ii < ITERATIONS; ii++) {
Key key = new Key("T" + i + "I" + ii);
Value value = new Value("<test thread=\"" + i + "\" iteration=\"" + ii + "\"/>");
Record record = filer.readRecord(key);
assertNotNull("Record with key '" + key + "' was not found",
record);
assertEquals("Expected record with key '" + key + "', found record with key '" + record.getKey() + "'",
key, record.getKey());