use of jetbrains.exodus.core.execution.JobProcessorExceptionHandler in project xodus by JetBrains.
the class StoreTest method concurrentPutLikeJetPass.
private void concurrentPutLikeJetPass(@NotNull final StoreConfig config) {
env.getEnvironmentConfig().setGcEnabled(false);
final Store store = openStoreAutoCommit("store", config);
final JobProcessor processor = new MultiThreadDelegatingJobProcessor("ConcurrentPutProcessor", 8) {
};
processor.setExceptionHandler(new JobProcessorExceptionHandler() {
@Override
public void handle(JobProcessor processor, Job job, Throwable t) {
t.printStackTrace(System.out);
}
});
processor.start();
final int count = 50000;
final LongSet keys = new LongHashSet();
for (int i = 0; i < count; ++i) {
processor.queue(new Job() {
@Override
protected void execute() {
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final long key = randomLong();
store.put(txn, LongBinding.longToCompressedEntry(key), getValue());
if (txn.flush()) {
final boolean added;
synchronized (keys) {
added = keys.add(key);
}
if (!added) {
System.out.println("Happy birthday paradox!");
}
}
}
});
}
});
}
processor.waitForJobs(10);
processor.finish();
assertEquals(count, keys.size());
env.executeInTransaction(new TransactionalExecutable() {
@Override
public void execute(@NotNull final Transaction txn) {
final long[] longs = keys.toLongArray();
for (long key : longs) {
assertEquals(getValue(), store.get(txn, LongBinding.longToCompressedEntry(key)));
}
Arrays.sort(longs);
try (Cursor cursor = store.openCursor(txn)) {
int i = 0;
while (cursor.getNext()) {
assertEquals(longs[i++], LongBinding.compressedEntryToLong(cursor.getKey()));
}
assertEquals(count, i);
}
}
});
}
Aggregations