Fixed race condition in ZipStreamingOutputTest.
@@ -36,9 +36,13 @@ import org.apache.hadoop.fs.permission.FsPermission;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
import java.io.IOException;
import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -63,7 +67,14 @@ public class ZipStreamingOutputTest {
Mockito.when(fs.open(file1.getPath())).thenReturn(fileStream);
Mockito.when(fs.open(file2.getPath())).thenReturn(fileStream);
- Mockito.when(fs.delete(source, true)).thenReturn(true);
+ final CountDownLatch deleteLatch = new CountDownLatch(1);
+ Mockito.when(fs.delete(source, true)).then(new Answer<Boolean>() {
+ @Override
+ public Boolean answer(final InvocationOnMock invocation) {
+ deleteLatch.countDown();
+ return true;
+ }
+ });
// Write ZIP to output stream
final ByteArrayOutputStream out = new ByteArrayOutputStream();
@@ -85,6 +96,7 @@ public class ZipStreamingOutputTest {
Assert.assertNull("Unexpected entry", entry);
// Verify path deleted
+ deleteLatch.await(1, TimeUnit.SECONDS);
Mockito.verify(fs).delete(source, true);
}
