Skip to content

Commit 8d493d9

Browse files
author
Vladimir Kotal
committed
reuse basic indexer test as xref test
1 parent 0d04331 commit 8d493d9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/index/IndexerTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727
import static org.junit.Assert.assertEquals;
2828
import static org.junit.Assert.assertFalse;
2929
import static org.junit.Assert.assertNotNull;
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
3031

3132
import java.io.BufferedWriter;
3233
import java.io.File;
3334
import java.io.FileReader;
3435
import java.io.FileWriter;
3536
import java.io.IOException;
3637
import java.io.StringWriter;
38+
import java.nio.file.Files;
39+
import java.nio.file.Path;
3740
import java.nio.file.Paths;
3841
import java.util.ArrayList;
3942
import java.util.Arrays;
@@ -46,6 +49,7 @@
4649
import java.util.TreeSet;
4750
import java.util.concurrent.ConcurrentLinkedQueue;
4851
import java.util.stream.Collectors;
52+
import java.util.stream.Stream;
4953

5054
import org.junit.After;
5155
import org.junit.Assert;
@@ -97,21 +101,28 @@ public void tearDown() {
97101
repository.destroy();
98102
}
99103

100-
/**
101-
* Test of doIndexerExecution method, of class Indexer.
102-
* @throws java.lang.Exception
103-
*/
104104
@Test
105-
public void testIndexGeneration() throws Exception {
106-
System.out.println("Generating index by using the class methods");
105+
public void testXrefGeneration() throws Exception {
107106
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
108107
env.setSourceRoot(repository.getSourceRoot());
109108
env.setDataRoot(repository.getDataRoot());
110109
env.setHistoryEnabled(false);
111110
Indexer.getInstance().prepareIndexer(env, true, true,
112111
false, null, null);
113-
env.setDefaultProjectsFromNames(new TreeSet<>(Collections.singletonList("/c")));
114112
Indexer.getInstance().doIndexerExecution(true, null, null);
113+
114+
// There should be certain number of xref files produced.
115+
List<String> result = null;
116+
try (Stream<Path> walk = Files.walk(Paths.get(env.getDataRootPath(), IndexDatabase.XREF_DIR))) {
117+
result = walk.filter(Files::isRegularFile).filter(f -> f.toString().endsWith(".gz")).
118+
map(x -> x.toString()).collect(Collectors.toList());
119+
}
120+
assertNotNull(result);
121+
assertTrue(result.size() > 50);
122+
123+
// Some files would have empty xref so the file should not be present.
124+
assertFalse(Paths.get(env.getDataRootPath(), IndexDatabase.XREF_DIR, "data", "Logo.png", ".gz").
125+
toFile().exists());
115126
}
116127

117128
/**

0 commit comments

Comments
 (0)