}
}
}
public void testMultiThreadedWriting() throws Exception {
final AtomicInteger datastoreCount = new AtomicInteger();
final OutputWriterScenarioHelper scenarioHelper = new OutputWriterScenarioHelper();
final DatastoreCreationDelegate creationDelegate = new DatastoreCreationDelegate() {
@Override
public synchronized void createDatastore(Datastore datastore) {
if (_datastore != null) {
assertEquals(_datastore, datastore);
}
_datastore = datastore;
datastoreCount.incrementAndGet();
}
};
final InputColumn<?>[] columns = scenarioHelper.getColumns().toArray(new InputColumn[0]);
// creating 9 similar writers that all write at the same time
Thread[] threads = new Thread[9];
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
public void run() {
try {
OutputWriter writer = DatastoreOutputWriterFactory.getWriter(outputDir, creationDelegate, "ds",
"tab", false, columns);
scenarioHelper.writeExampleData(writer);
} catch (Exception e) {
_exception = e;
}
};
};
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
}
for (int i = 0; i < threads.length; i++) {
threads[i].join();
}
if (_exception != null) {
throw _exception;
}
assertEquals(9, datastoreCount.get());
assertNotNull(_datastore);
DataContextProvider dataContextProvider = _datastore.getDataContextProvider();
DataContext dc = dataContextProvider.getDataContext();
dc.refreshSchemas();