Search in sources :

Example 1 with WriteOperation

use of org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation in project jackrabbit-oak by apache.

the class SegmentBufferWriterPoolTest method testFlushBlocks.

@Test
public void testFlushBlocks() throws ExecutionException, InterruptedException {
    Future<RecordId> res = execute(new WriteOperation() {

        @Nonnull
        @CheckForNull
        @Override
        public RecordId execute(@Nonnull SegmentBufferWriter writer) {
            try {
                // This should deadlock as flush waits for this write
                // operation to finish, which in this case contains the
                // call to flush itself.
                executors[1].submit(new Callable<Void>() {

                    @Override
                    public Void call() throws Exception {
                        pool.flush(store);
                        return null;
                    }
                }).get(100, MILLISECONDS);
                // No deadlock -> null indicates test failure
                return null;
            } catch (InterruptedException | ExecutionException ignore) {
                // No deadlock -> null indicates test failure
                return null;
            } catch (TimeoutException ignore) {
                // Deadlock -> rootId indicates test pass
                return rootId;
            }
        }
    }, 0);
    assertEquals(rootId, res.get());
}
Also used : WriteOperation(org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation) Nonnull(javax.annotation.Nonnull) CheckForNull(javax.annotation.CheckForNull) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 CheckForNull (javax.annotation.CheckForNull)1 Nonnull (javax.annotation.Nonnull)1 WriteOperation (org.apache.jackrabbit.oak.segment.WriteOperationHandler.WriteOperation)1 Test (org.junit.Test)1