use of org.apache.flink.runtime.io.disk.iomanager.AsynchronousBufferFileWriter in project flink by apache.
the class SpillableSubpartitionTest method testConcurrentFinishAndReleaseMemory.
/**
* Tests a fix for FLINK-2384.
*
* @see <a href="https://issues.apache.org/jira/browse/FLINK-2384">FLINK-2384</a>
*/
@Test
public void testConcurrentFinishAndReleaseMemory() throws Exception {
// Latches to blocking
final CountDownLatch doneLatch = new CountDownLatch(1);
final CountDownLatch blockLatch = new CountDownLatch(1);
// Blocking spill writer (blocks on the close call)
AsynchronousBufferFileWriter spillWriter = mock(AsynchronousBufferFileWriter.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
blockLatch.countDown();
doneLatch.await();
return null;
}
}).when(spillWriter).close();
// Mock I/O manager returning the blocking spill writer
IOManager ioManager = mock(IOManager.class);
when(ioManager.createBufferFileWriter(any(FileIOChannel.ID.class))).thenReturn(spillWriter);
// The partition
final SpillableSubpartition partition = new SpillableSubpartition(0, mock(ResultPartition.class), ioManager);
// Spill the partition initially (creates the spill writer)
assertEquals(0, partition.releaseMemory());
ExecutorService executor = Executors.newSingleThreadExecutor();
// Finish the partition (this blocks because of the mock blocking writer)
Future<Void> blockingFinish = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
partition.finish();
return null;
}
});
// Ensure that the blocking call has been made
blockLatch.await();
// This call needs to go through. FLINK-2384 discovered a bug, in
// which the finish call was holding a lock, which was leading to a
// deadlock when another operation on the partition was happening.
partition.releaseMemory();
// Check that the finish call succeeded w/o problems as well to avoid
// false test successes.
doneLatch.countDown();
blockingFinish.get();
}
Aggregations