Skip to content

Commit d08f9d8

Browse files
committed
Revise IndexerTest with concurrent listeners
... after seeing once a test failure with new, parallelized indexing (non-test code was unaffected). IndexerTest.testIncrementalIndexAddRemoveFile() had to be trivially revised to expect append-only collections -- but it was anyway a test with a single file.
1 parent b92758c commit d08f9d8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test/org/opensolaris/opengrok/index/IndexerTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
import java.util.HashMap;
3535
import java.util.List;
3636
import java.util.Map;
37+
import java.util.Queue;
3738
import java.util.Set;
3839
import java.util.TreeSet;
40+
import java.util.concurrent.ConcurrentLinkedQueue;
3941
import java.util.stream.Collectors;
4042
import org.junit.After;
4143
import org.junit.AfterClass;
@@ -210,8 +212,8 @@ public void testMain() throws IOException {
210212

211213
private class MyIndexChangeListener implements IndexChangedListener {
212214

213-
List<String> files = new ArrayList<>();
214-
List<String> removedFiles = new ArrayList<>();
215+
final Queue<String> files = new ConcurrentLinkedQueue<>();
216+
final Queue<String> removedFiles = new ConcurrentLinkedQueue<>();
215217

216218
@Override
217219
public void fileAdd(String path, String analyzer) {
@@ -232,12 +234,12 @@ public void fileUpdate(String path) {
232234

233235
@Override
234236
public void fileRemoved(String path) {
235-
files.remove(path);
236237
removedFiles.add(path);
237238
}
238239

239240
public void reset() {
240-
this.files = new ArrayList<>();
241+
this.files.clear();
242+
this.removedFiles.clear();
241243
}
242244
}
243245

@@ -291,8 +293,8 @@ public void testIndexWithSetIndexVersionedFilesOnly() throws Exception {
291293
*/
292294
private class RemoveIndexChangeListener implements IndexChangedListener {
293295

294-
List<String> filesToAdd = new ArrayList<>();
295-
List<String> removedFiles = new ArrayList<>();
296+
final Queue<String> filesToAdd = new ConcurrentLinkedQueue<>();
297+
final Queue<String> removedFiles = new ConcurrentLinkedQueue<>();
296298

297299
@Override
298300
public void fileAdd(String path, String analyzer) {
@@ -325,8 +327,8 @@ public void fileRemoved(String path) {
325327
}
326328

327329
public void reset() {
328-
this.filesToAdd = new ArrayList<>();
329-
this.removedFiles = new ArrayList<>();
330+
this.filesToAdd.clear();
331+
this.removedFiles.clear();
330332
}
331333
}
332334

@@ -378,7 +380,7 @@ public void testRemoveFileOnFileChange() throws Exception {
378380
// Make sure that the file was actually processed.
379381
assertEquals(1, listener.removedFiles.size());
380382
assertEquals(1, listener.filesToAdd.size());
381-
assertEquals("/mercurial/bar.txt", listener.removedFiles.get(0));
383+
assertEquals("/mercurial/bar.txt", listener.removedFiles.peek());
382384

383385
testrepo.destroy();
384386
}
@@ -449,8 +451,11 @@ public void testIncrementalIndexAddRemoveFile() throws Exception {
449451
assertEquals("No new file added", 1, listener.files.size());
450452
repository.removeDummyFile(ppath);
451453
idb.update(parallelizer);
452-
assertEquals("Didn't remove the dummy file", 0, listener.files.size());
454+
assertEquals("(added)files changed unexpectedly", 1,
455+
listener.files.size());
453456
assertEquals("Didn't remove the dummy file", 1, listener.removedFiles.size());
457+
assertEquals("Should have added then removed the same file",
458+
listener.files.peek(), listener.removedFiles.peek());
454459
} else {
455460
System.out.println("Skipping test. Could not find a ctags I could use in path.");
456461
}

0 commit comments

Comments
 (0)