Skip to content

Commit 3b65bef

Browse files
author
Vladimir Kotal
committed
split main() tests into separate class
1 parent 937bd40 commit 3b65bef

File tree

2 files changed

+96
-44
lines changed

2 files changed

+96
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
22+
* Portions Copyright (c) 2017-2019, Chris Fraire <[email protected]>.
23+
*/
24+
25+
package org.opengrok.indexer.index;
26+
27+
import org.junit.After;
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
import org.opengrok.indexer.configuration.RuntimeEnvironment;
31+
import org.opengrok.indexer.history.HistoryGuru;
32+
import org.opengrok.indexer.util.TestRepository;
33+
34+
import java.io.IOException;
35+
36+
import static org.junit.Assert.assertFalse;
37+
38+
public class IndexerMainTest {
39+
private TestRepository repository;
40+
41+
@Before
42+
public void setUp() throws IOException {
43+
repository = new TestRepository();
44+
// For these tests we need Mercurial repository with renamed files.
45+
repository.create(HistoryGuru.class.getResourceAsStream("repositories.zip"));
46+
}
47+
48+
@After
49+
public void tearDown() {
50+
repository.destroy();
51+
}
52+
53+
private void checkNumberOfThreads() {
54+
/*
55+
* There should not be any threads in the renamed pool now.
56+
* We need to check it like this since the test framework tears
57+
* down the threads at the end of the test case run so any
58+
* hangs due to executors not being shut down would not be visible.
59+
*/
60+
ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
61+
Thread[] threads = new Thread[mainGroup.activeCount()];
62+
mainGroup.enumerate(threads);
63+
for (int i = 0; i < threads.length; i++) {
64+
if (threads[i] == null || threads[i].getName() == null) {
65+
continue;
66+
}
67+
assertFalse(threads[i].getName().contains("renamed-handling"));
68+
}
69+
}
70+
71+
/**
72+
* Test cleanup of renamed thread pool after indexing with -H.
73+
*/
74+
@Test
75+
public void testMainWithH() {
76+
System.out.println("Generate index by using command line options with -H");
77+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
78+
String[] argv = {"-S", "-H", "-s", repository.getSourceRoot(),
79+
"-d", repository.getDataRoot(), "-v", "-c", env.getCtags()};
80+
Indexer.main(argv);
81+
checkNumberOfThreads();
82+
}
83+
84+
/**
85+
* Test cleanup of renamed thread pool after indexing without -H.
86+
*/
87+
@Test
88+
public void testMainWithoutH() {
89+
System.out.println("Generate index by using command line options without -H");
90+
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
91+
String[] argv = {"-S", "-P", "-s", repository.getSourceRoot(),
92+
"-d", repository.getDataRoot(), "-v", "-c", env.getCtags()};
93+
Indexer.main(argv);
94+
checkNumberOfThreads();
95+
}
96+
}

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

-44
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,6 @@ public void tearDown() {
7979
repository.destroy();
8080
}
8181

82-
private void checkNumberOfThreads() {
83-
/*
84-
* There should not be any threads in the renamed pool now.
85-
* We need to check it like this since the test framework tears
86-
* down the threads at the end of the test case run so any
87-
* hangs due to executors not being shut down would not be visible.
88-
*/
89-
ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
90-
Thread[] threads = new Thread[mainGroup.activeCount()];
91-
mainGroup.enumerate(threads);
92-
for (int i = 0; i < threads.length; i++) {
93-
if (threads[i] == null || threads[i].getName() == null) {
94-
continue;
95-
}
96-
assertFalse(threads[i].getName().contains("renamed-handling"));
97-
}
98-
}
99-
10082
/**
10183
* Test it is possible to disable history per project.
10284
*/
@@ -222,30 +204,4 @@ public void testSymlinks() throws IndexerException, IOException {
222204
IOUtils.removeRecursive(realSource);
223205
IOUtils.removeRecursive(sourceRoot);
224206
}
225-
226-
/**
227-
* Test cleanup of renamed thread pool after indexing with -H.
228-
*/
229-
@Test
230-
public void testMainWithH() {
231-
System.out.println("Generate index by using command line options with -H");
232-
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
233-
String[] argv = {"-S", "-H", "-s", repository.getSourceRoot(),
234-
"-d", repository.getDataRoot(), "-v", "-c", env.getCtags()};
235-
Indexer.main(argv);
236-
checkNumberOfThreads();
237-
}
238-
239-
/**
240-
* Test cleanup of renamed thread pool after indexing without -H.
241-
*/
242-
@Test
243-
public void testMainWithoutH() {
244-
System.out.println("Generate index by using command line options without -H");
245-
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
246-
String[] argv = {"-S", "-P", "-s", repository.getSourceRoot(),
247-
"-d", repository.getDataRoot(), "-v", "-c", env.getCtags()};
248-
Indexer.main(argv);
249-
checkNumberOfThreads();
250-
}
251207
}

0 commit comments

Comments
 (0)