|
| 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 | +} |
0 commit comments