Skip to content

Commit 851c7b4

Browse files
committed
Merge branch 'master' into 4740-feat
Signed-off-by: Bernát Gábor <[email protected]>
2 parents 982b4db + 00c2c86 commit 851c7b4

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5858
run: ./dev/main
5959
- name: Upload artifact
60-
uses: actions/upload-artifact@v4
60+
uses: actions/upload-artifact@v5
6161
with:
6262
name: opengrok-${{ github.sha }}-${{ matrix.os }}.tar.gz
6363
path: distribution/target/opengrok-*.tar.gz

opengrok-indexer/src/test/java/org/opengrok/indexer/search/SearchEngineTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void testSortOrderLastModified() {
167167
int hitsCount = instance.search();
168168
List<Hit> hits = new ArrayList<>();
169169
instance.results(0, hitsCount, hits);
170-
assertTrue(hits.size() != 6, "Should return at least 2 hits for RELEVANCY sort to check order");
170+
assertTrue(hits.size() == 6, "Should return at least 2 hits for RELEVANCY sort to check order");
171171

172172
String[] results = hits.stream().
173173
map(hit -> hit.getPath() + "@" + hit.getLineno()).
@@ -195,7 +195,7 @@ void testSortOrderByPath() {
195195
int hitsCount = instance.search();
196196
List<Hit> hits = new ArrayList<>();
197197
instance.results(0, hitsCount, hits);
198-
assertTrue(hits.size() != 11, "Should return at least 2 hits for RELEVANCY sort to check order");
198+
assertTrue(hits.size() == 11, "Should return at least 2 hits for RELEVANCY sort to check order");
199199

200200
String[] results = hits.stream().
201201
map(hit -> hit.getPath() + "@" + hit.getLineno()).

opengrok-indexer/src/test/java/org/opengrok/indexer/util/TestRepository.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import java.nio.file.FileSystems;
3333
import java.nio.file.Files;
3434
import java.nio.file.Path;
35+
import java.nio.file.attribute.FileTime;
36+
import java.time.Instant;
3537
import java.util.LinkedHashMap;
3638
import java.util.List;
3739
import java.util.Map;
@@ -135,35 +137,34 @@ public void copyDirectory(Path src, Path dest) throws IOException {
135137
}
136138

137139
/**
138-
* Assumes the destination directory exists.
140+
* Create a deterministic order of paths for creation time.
141+
* This is so last modified time indexing is stable in tests. Note we cannot use
142+
* Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES) as the original creation time is the user
143+
* checkout and not different across files.
144+
*
139145
* @param src source directory
140146
* @param dest destination directory
141147
* @throws IOException on error
142148
*/
143149
public void copyDirectoryWithUniqueModifiedTime(Path src, Path dest) throws IOException {
144-
// Create a deterministic order of paths for creation time, so last modified time indexing is stable in tests
145-
// note we cannot use Files.copy(sourceFile, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES)
146-
// as the original creation time is the user checkout and not different accross files
147-
List<Path> allPaths;
150+
List<Path> allPaths;
148151
try (Stream<Path> stream = Files.walk(src)) {
149152
allPaths = stream.filter(p -> !p.equals(src)).sorted().toList();
150153
}
151154
// Set base time to now, and go ahead in time for each subsequent path by 1 minute
152-
java.time.Instant baseTime = java.time.Instant.now();
155+
Instant baseTime = java.time.Instant.now();
153156
for (int i = 0; i < allPaths.size(); i++) {
154157
Path sourcePath = allPaths.get(i);
155158
Path destRelativePath = getDestinationRelativePath(src, sourcePath);
156159
Path destPath = dest.resolve(destRelativePath);
157-
var fileTime = java.nio.file.attribute.FileTime.from(baseTime.plusSeconds(i * 60L));
160+
var fileTime = FileTime.from(baseTime.plusSeconds(i * 60L));
158161
if (Files.isDirectory(sourcePath)) {
159-
if (!Files.exists(destPath)) {
160-
Files.createDirectories(destPath);
161-
}
162+
Files.createDirectories(destPath);
162163
Files.setLastModifiedTime(destPath, fileTime);
163164
} else {
164165
// Ensure parent directory exists before copying file
165166
Path parentDir = destPath.getParent();
166-
if (parentDir != null && !Files.exists(parentDir)) {
167+
if (parentDir != null) {
167168
Files.createDirectories(parentDir);
168169
}
169170
Files.copy(sourcePath, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES);

opengrok-web/src/main/java/org/opengrok/web/api/v1/controller/SearchController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SearchController {
5959
public static final String PATH = "search";
6060

6161
private static final int MAX_RESULTS = 1000;
62-
private static final String DEFAULT_SORT_ORDER = "relevancy";
62+
public static final String DEFAULT_SORT_ORDER = "relevancy";
6363

6464
private final SuggesterService suggester;
6565

opengrok-web/src/test/java/org/opengrok/web/api/v1/controller/SearchControllerTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.junit.jupiter.api.Test;
3636
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3737
import org.opengrok.indexer.util.TestRepository;
38+
import org.opengrok.indexer.web.SortOrder;
3839
import org.opengrok.web.api.v1.RestApp;
3940

4041
import java.util.Collections;
@@ -86,4 +87,9 @@ void testSearchCors() {
8687
.get();
8788
assertEquals("*", response.getHeaderString(ALLOW_CORS_HEADER));
8889
}
90+
91+
@Test
92+
void defaultSortOrderRelevancy() {
93+
assertEquals(SearchController.DEFAULT_SORT_ORDER, SortOrder.RELEVANCY.name().toLowerCase());
94+
}
8995
}

0 commit comments

Comments
 (0)