Skip to content

Commit 3fe1350

Browse files
author
Vladimir Kotal
committed
add test for single incoming changeset
1 parent f056d83 commit 3fe1350

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/BoundaryChangesets.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class BoundaryChangesets implements IChangesetVisitor {
4949
public BoundaryChangesets(RepositoryWithPerPartesHistory repository) {
5050
this.repository = repository;
5151
this.maxCount = repository.getPerPartesCount();
52-
// TODO: what if there is just one incoming changeset ?
5352
if (maxCount <= 1) {
5453
throw new RuntimeException(String.format("per partes count for repository ''%s'' " +
5554
"must be stricly greater than 1", repository.getDirectoryName()));

opengrok-indexer/src/main/java/org/opengrok/indexer/history/GitRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ public void accept(String sinceRevision, IChangesetVisitor visitor) throws Histo
550550
}
551551
}
552552

553-
// TODO: could this miss some renamed files at the boundaries ? add test for this
554553
public History getHistory(File file, String sinceRevision, String tillRevision) throws HistoryException {
555554
final List<HistoryEntry> entries = new ArrayList<>();
556555
final Set<String> renamedFiles = new HashSet<>();

opengrok-indexer/src/test/java/org/opengrok/indexer/history/RepositoryWithPerPartesHistoryTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232
import org.opengrok.indexer.util.TestRepository;
3333

3434
import java.io.File;
35+
import java.nio.file.Paths;
3536
import java.util.ArrayList;
3637
import java.util.List;
3738

3839
import static org.junit.jupiter.api.Assertions.assertEquals;
40+
import static org.junit.jupiter.api.Assertions.assertFalse;
3941
import static org.junit.jupiter.api.Assertions.assertNotNull;
4042
import static org.junit.jupiter.api.Assertions.assertTrue;
4143
import static org.mockito.ArgumentMatchers.any;
44+
import static org.mockito.ArgumentMatchers.anyString;
45+
import static org.mockito.ArgumentMatchers.isNull;
4246
import static org.mockito.Mockito.times;
4347

4448
public class RepositoryWithPerPartesHistoryTest {
@@ -98,4 +102,29 @@ void testChangesets() throws HistoryException {
98102
tillRevisions.add(null);
99103
assertEquals(tillRevisions, stringArgumentCaptor2.getAllValues());
100104
}
105+
106+
/**
107+
* Test a (perceived) corner case to simulate there is exactly one "incoming" changeset
108+
* for a repository with per partes history handling. This changeset has to be stored in history cache.
109+
* @throws Exception on error
110+
*/
111+
@Test
112+
void testPseudoIncomingChangeset() throws Exception {
113+
FileHistoryCache cache = new FileHistoryCache();
114+
GitRepository gitSpyRepository = Mockito.spy(gitRepository);
115+
Mockito.when(gitSpyRepository.getPerPartesCount()).thenReturn(3);
116+
List<HistoryEntry> historyEntries = gitRepository.getHistory(new File(gitRepository.getDirectoryName())).
117+
getHistoryEntries();
118+
assertFalse(historyEntries.isEmpty());
119+
120+
gitSpyRepository.createCache(cache, historyEntries.get(1).getRevision());
121+
Mockito.verify(gitSpyRepository, times(1)).
122+
getHistory(any(), anyString(), isNull());
123+
assertEquals(historyEntries.get(0).getRevision(), cache.getLatestCachedRevision(gitSpyRepository));
124+
History cachedHistory = cache.get(Paths.get(gitRepository.getDirectoryName(), "moved2", "renamed2.c").toFile(),
125+
gitSpyRepository, false);
126+
assertNotNull(cachedHistory);
127+
assertEquals(1, cachedHistory.getHistoryEntries().size());
128+
assertEquals(historyEntries.get(0).getRevision(), cachedHistory.getHistoryEntries().get(0).getRevision());
129+
}
101130
}

0 commit comments

Comments
 (0)