summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2021-06-26 16:37:59 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-06-26 16:37:59 +0200
commitd46af8c69d598b63301900758e49b6b260168c16 (patch)
tree3e7fe3fc41152817e21dab0c7c4b43abc3a282cf /org.eclipse.jgit.test/tst
parent6976a30f443ece4815a977b0a5a897c0236018f7 (diff)
parent8bd0161c83c54911be59bbfdee00eeb9c1f6adb9 (diff)
downloadjgit-d46af8c69d598b63301900758e49b6b260168c16.tar.gz
jgit-d46af8c69d598b63301900758e49b6b260168c16.zip
Merge branch 'stable-5.12'
* stable-5.12: Retry loose object read upon "Stale file handle" exception Ignore missing javadoc in test bundles Change-Id: I67c613c066a3252f9b0d0a3dcc026b57e10bfe1d
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
index d269457eb1..316e33639d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
@@ -44,8 +44,12 @@ package org.eclipse.jgit.internal.storage.file;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
import java.io.File;
import java.io.IOException;
@@ -69,6 +73,7 @@ import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.util.FS;
import org.junit.Assume;
import org.junit.Test;
+import org.mockito.Mockito;
public class ObjectDirectoryTest extends RepositoryTestCase {
@@ -195,6 +200,42 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
}
@Test
+ public void testOpenLooseObjectSuppressStaleFileHandleException()
+ throws Exception {
+ ObjectId id = ObjectId
+ .fromString("873fb8d667d05436d728c52b1d7a09528e6eb59b");
+ WindowCursor curs = new WindowCursor(db.getObjectDatabase());
+
+ LooseObjects mock = mock(LooseObjects.class);
+ UnpackedObjectCache unpackedObjectCacheMock = mock(
+ UnpackedObjectCache.class);
+
+ Mockito.when(mock.getObjectLoader(any(), any(), any()))
+ .thenThrow(new IOException("Stale File Handle"));
+ Mockito.when(mock.open(curs, id)).thenCallRealMethod();
+ Mockito.when(mock.unpackedObjectCache())
+ .thenReturn(unpackedObjectCacheMock);
+
+ assertNull(mock.open(curs, id));
+ verify(unpackedObjectCacheMock).remove(id);
+ }
+
+ @Test
+ public void testOpenLooseObjectPropagatesIOExceptions() throws Exception {
+ ObjectId id = ObjectId
+ .fromString("873fb8d667d05436d728c52b1d7a09528e6eb59b");
+ WindowCursor curs = new WindowCursor(db.getObjectDatabase());
+
+ LooseObjects mock = mock(LooseObjects.class);
+
+ Mockito.when(mock.getObjectLoader(any(), any(), any()))
+ .thenThrow(new IOException("some IO failure"));
+ Mockito.when(mock.open(curs, id)).thenCallRealMethod();
+
+ assertThrows(IOException.class, () -> mock.open(curs, id));
+ }
+
+ @Test
public void testShallowFileCorrupt() throws Exception {
FileRepository repository = createBareRepository();
ObjectDirectory dir = repository.getObjectDatabase();