use of org.neo4j.function.IOFunction in project neo4j by neo4j.
the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.
@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
// given
updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
// when
// needs to be acquired before drop() is called
IndexReader indexReader = accessor.newReader();
IndexSampler indexSampler = indexReader.createSampler();
Future<Void> drop = threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
accessor.drop();
return nothing;
}, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
try (IndexReader reader = indexReader) /* do not inline! */
{
indexSampler.sampleIndex();
fail("expected exception");
} catch (IndexNotFoundKernelException e) {
assertEquals("Index dropped while sampling.", e.getMessage());
} finally {
drop.get();
}
}
use of org.neo4j.function.IOFunction in project neo4j by neo4j.
the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.
@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
// given
updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
// when
var indexReader = accessor.newValueReader();
BinaryLatch dropLatch = new BinaryLatch();
BinaryLatch sampleLatch = new BinaryLatch();
LuceneIndexSampler indexSampler = spy((LuceneIndexSampler) indexReader.createSampler());
doAnswer(inv -> {
var obj = inv.callRealMethod();
// We have now started the sampling, let the index try to drop
dropLatch.release();
// Wait for the drop to be blocked
sampleLatch.await();
return obj;
}).when(indexSampler).newTask();
List<Future<?>> futures = new ArrayList<>();
try (var reader = indexReader;
/* do not inline! */
IndexSampler sampler = indexSampler) /* do not inline! */
{
futures.add(threading.execute((IOFunction<Void, Void>) nothing -> {
try {
indexSampler.sampleIndex(NULL);
fail("expected exception");
} catch (IndexNotFoundKernelException e) {
assertEquals("Index dropped while sampling.", e.getMessage());
} finally {
dropLatch.release();
}
return nothing;
}, null));
futures.add(threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
dropLatch.await();
accessor.drop();
return nothing;
}, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 10, MINUTES));
} finally {
// drop is blocked, okay to finish sampling (will fail since index is dropped)
sampleLatch.release();
for (Future<?> future : futures) {
future.get();
}
}
}
Aggregations