aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2025-08-06 14:13:56 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2025-08-06 14:13:56 +0200
commit2a635383d0c0f63c79bd7df7af0c8ac4fd7c4a2b (patch)
treed2bbcd1ab5d1a5c406ebadd51559fe1deb31a3f4 /org.eclipse.jgit.test/tst/org/eclipse
parent0a32120fac17af19af2dc6e76226952a7eef1a9b (diff)
parent97c257a57e59dc4247490cc328757416aa5aa84d (diff)
downloadjgit-master.tar.gz
jgit-master.zip
Merge branch 'stable-7.3'HEADmaster
* stable-7.3: Shortcut PackWriter reuse selection when possible Don't use Yoda style conditions to improve readability Change-Id: Ic8ca92cfc294ca01540218151bafca889256847b
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BasePackWriterTest.java72
1 files changed, 50 insertions, 22 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BasePackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BasePackWriterTest.java
index 92d7465376..cd73c6ae83 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BasePackWriterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/BasePackWriterTest.java
@@ -19,7 +19,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -702,13 +702,29 @@ public class BasePackWriterTest extends SampleDataRepositoryTestCase {
}
@Test
- public void testTotalPackFilesScanWhenSearchForReuseTimeoutNotSet()
+ public void testTotalPackFilesScanWhenSearchForReuseTimeoutNotSetTrue()
throws Exception {
+ totalPackFilesScanWhenSearchForReuseTimeoutNotSet(true);
+ }
+
+ @Test
+ public void testTotalPackFilesScanWhenSearchForReuseTimeoutNotSetFalse()
+ throws Exception {
+ totalPackFilesScanWhenSearchForReuseTimeoutNotSet(false);
+ }
+
+ public void totalPackFilesScanWhenSearchForReuseTimeoutNotSet(boolean doReturn) throws Exception {
FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+ int numberOfPackFiles = (int) new GC(fileRepository).getStatistics().numberOfPackFiles;
+ int objectsInMultiplePacks = 2;
+ int objectsInOnePacks = 1;
+ int expectedSelectCalls = objectsInMultiplePacks * (doReturn ? numberOfPackFiles : 1)
+ + objectsInOnePacks;
+
PackWriter mockedPackWriter = Mockito
.spy(new PackWriter(config, fileRepository.newObjectReader()));
- doNothing().when(mockedPackWriter).select(any(), any());
+ doReturn(doReturn).when(mockedPackWriter).select(any(), any());
try (FileOutputStream packOS = new FileOutputStream(
getPackFileToWrite(fileRepository, mockedPackWriter))) {
@@ -716,27 +732,37 @@ public class BasePackWriterTest extends SampleDataRepositoryTestCase {
NullProgressMonitor.INSTANCE, packOS);
}
- long numberOfPackFiles = new GC(fileRepository)
- .getStatistics().numberOfPackFiles;
- int expectedSelectCalls =
- // Objects contained in multiple packfiles * number of packfiles
- 2 * (int) numberOfPackFiles +
- // Objects in single packfile
- 1;
verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
any());
}
@Test
- public void testTotalPackFilesScanWhenSkippingSearchForReuseTimeoutCheck()
+ public void testTotalPackFilesScanWhenSkippingSearchForReuseTimeoutCheckTrue()
throws Exception {
+ totalPackFilesScanWhenSkippingSearchForReuseTimeoutCheck(true);
+ }
+
+ @Test
+ public void testTotalPackFilesScanWhenSkippingSearchForReuseTimeoutCheckFalse()
+ throws Exception {
+ totalPackFilesScanWhenSkippingSearchForReuseTimeoutCheck(false);
+ }
+
+ public void totalPackFilesScanWhenSkippingSearchForReuseTimeoutCheck(
+ boolean doReturn) throws Exception {
FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+ int numberOfPackFiles = (int) new GC(fileRepository).getStatistics().numberOfPackFiles;
+ int objectsInMultiplePacks = 2;
+ int objectsInOnePacks = 1;
+ int expectedSelectCalls = objectsInMultiplePacks * (doReturn ? numberOfPackFiles : 1)
+ + objectsInOnePacks;
+
PackConfig packConfig = new PackConfig();
packConfig.setSearchForReuseTimeout(Duration.ofSeconds(-1));
PackWriter mockedPackWriter = Mockito.spy(
new PackWriter(packConfig, fileRepository.newObjectReader()));
- doNothing().when(mockedPackWriter).select(any(), any());
+ doReturn(doReturn).when(mockedPackWriter).select(any(), any());
try (FileOutputStream packOS = new FileOutputStream(
getPackFileToWrite(fileRepository, mockedPackWriter))) {
@@ -744,28 +770,31 @@ public class BasePackWriterTest extends SampleDataRepositoryTestCase {
NullProgressMonitor.INSTANCE, packOS);
}
- long numberOfPackFiles = new GC(fileRepository)
- .getStatistics().numberOfPackFiles;
- int expectedSelectCalls =
- // Objects contained in multiple packfiles * number of packfiles
- 2 * (int) numberOfPackFiles +
- // Objects contained in single packfile
- 1;
verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
any());
}
@Test
- public void testPartialPackFilesScanWhenDoingSearchForReuseTimeoutCheck()
+ public void partialPackFilesScanWhenDoingSearchForReuseTimeoutCheck()
throws Exception {
+ int objectsInMultiplePacks = 2;
+ int objectsInOnePacks = 1;
+ int expectedSelectCalls = objectsInMultiplePacks + objectsInOnePacks;
+ testPartialPackFilesScanWhenDoingSearchForReuseTimeoutCheck(true, expectedSelectCalls);
+ testPartialPackFilesScanWhenDoingSearchForReuseTimeoutCheck(false, expectedSelectCalls);
+ }
+
+ public void testPartialPackFilesScanWhenDoingSearchForReuseTimeoutCheck(
+ boolean doReturn, int expectedSelectCalls) throws Exception {
FileRepository fileRepository = setUpRepoWithMultiplePackfiles();
+
PackConfig packConfig = new PackConfig();
packConfig.setSearchForReuseTimeout(Duration.ofSeconds(-1));
PackWriter mockedPackWriter = Mockito.spy(
new PackWriter(packConfig, fileRepository.newObjectReader()));
mockedPackWriter.enableSearchForReuseTimeout();
- doNothing().when(mockedPackWriter).select(any(), any());
+ doReturn(doReturn).when(mockedPackWriter).select(any(), any());
try (FileOutputStream packOS = new FileOutputStream(
getPackFileToWrite(fileRepository, mockedPackWriter))) {
@@ -773,7 +802,6 @@ public class BasePackWriterTest extends SampleDataRepositoryTestCase {
NullProgressMonitor.INSTANCE, packOS);
}
- int expectedSelectCalls = 3; // Objects in packfiles
verify(mockedPackWriter, times(expectedSelectCalls)).select(any(),
any());
}