use of org.neo4j.graphdb.Resource in project neo4j by neo4j.
the class StoreCopyCheckPointMutexTest method shouldPropagateStoreCopyActionFailureToOtherStoreCopyRequests.
@Test
public void shouldPropagateStoreCopyActionFailureToOtherStoreCopyRequests() throws Exception {
// GIVEN
Barrier.Control barrier = new Barrier.Control();
IOException controlledFailure = new IOException("My own fault");
AtomicReference<Future<Object>> secondRequest = new AtomicReference<>();
ThrowingAction<IOException> controllableAndFailingAction = new ThrowingAction<IOException>() {
@Override
public void apply() throws IOException {
// Now that we know we're first, start the second request...
secondRequest.set(t3.execute(state -> mutex.storeCopy(ASSERT_NOT_CALLED)));
// ...and wait for it to reach its destination
barrier.awaitUninterruptibly();
try {
// OK, second request has made progress into the request, so we can now produce our failure
throw controlledFailure;
} finally {
barrier.release();
}
}
};
Future<Object> firstRequest = t2.execute(state -> mutex.storeCopy(controllableAndFailingAction));
while (secondRequest.get() == null) {
parkARandomWhile();
}
t3.get().waitUntilWaiting(details -> details.isAt(StoreCopyCheckPointMutex.class, "waitForFirstStoreCopyActionToComplete"));
// WHEN
barrier.reached();
// THEN
try {
firstRequest.get();
} catch (ExecutionException e) {
assertSame(controlledFailure, e.getCause());
}
try {
secondRequest.get().get();
} catch (ExecutionException e) {
Throwable cooperativeActionFailure = e.getCause();
assertThat(cooperativeActionFailure.getMessage(), containsString("Co-operative"));
assertSame(controlledFailure, cooperativeActionFailure.getCause());
}
// WHEN afterwards trying another store-copy
CountingAction action = new CountingAction();
try (Resource lock = mutex.storeCopy(action)) {
// THEN
assertEquals(1, action.count());
}
}
use of org.neo4j.graphdb.Resource in project neo4j by neo4j.
the class StoreCopyCheckPointMutexTest method shouldHandleMultipleConcurrentStoreCopyRequests.
@Test
public void shouldHandleMultipleConcurrentStoreCopyRequests() throws Throwable {
// GIVEN
Race race = new Race();
CountingAction action = new CountingAction();
int threads = Runtime.getRuntime().availableProcessors() * 10;
race.addContestants(threads, throwing(() -> {
parkARandomWhile();
try (Resource lock = mutex.storeCopy(action)) {
parkARandomWhile();
}
}));
race.go();
// THEN
// It's hard to make predictions about what should have been seen. Most importantly is that
// The lock doesn't hang any requests and that number of calls to the action less than number of threads
assertThat(action.count(), lessThan(threads));
}
Aggregations