Search in sources :

Example 21 with TestRepository

use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.

the class IndexerTest method testRemoveFileOnFileChange.

/**
 * Test that reindex after changing a file does not wipe out history index
 * for this file. This is important for the incremental history indexing.
 */
@Test
@EnabledForRepository(MERCURIAL)
void testRemoveFileOnFileChange() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String path = "/mercurial/bar.txt";
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResource("/repositories"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setDataRoot(testrepo.getDataRoot());
    env.setRepositories(testrepo.getSourceRoot());
    // Create history cache.
    Indexer.getInstance().prepareIndexer(env, true, true, false, null, List.of("mercurial"));
    File historyFile = new File(env.getDataRootPath(), TandemPath.join("historycache" + path, ".gz"));
    assertTrue(historyFile.exists(), String.format("history cache for %s has to exist", path));
    // create index
    Project project = new Project("mercurial", "/mercurial");
    IndexDatabase idb = new IndexDatabase(project);
    assertNotNull(idb);
    RemoveIndexChangeListener listener = new RemoveIndexChangeListener(path);
    idb.addIndexChangedListener(listener);
    idb.update();
    assertEquals(5, listener.filesToAdd.size());
    listener.reset();
    // Change a file so that it gets picked up by the indexer.
    File bar = new File(testrepo.getSourceRoot() + File.separator + "mercurial", "bar.txt");
    assertTrue(bar.exists());
    try (BufferedWriter bw = new BufferedWriter(new FileWriter(bar, true))) {
        bw.write("foo\n");
    }
    // reindex
    idb.update();
    // Make sure that the file was actually processed.
    assertEquals(1, listener.removedFiles.size());
    assertEquals(1, listener.filesToAdd.size());
    assertEquals("/mercurial/bar.txt", listener.removedFiles.peek());
    testrepo.destroy();
}
Also used : Project(org.opengrok.indexer.configuration.Project) TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) FileWriter(java.io.FileWriter) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) File(java.io.File) BufferedWriter(java.io.BufferedWriter) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 22 with TestRepository

use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.

the class IndexerTest method testSetRepositories.

@Test
@EnabledForRepository(MERCURIAL)
void testSetRepositories() throws Exception {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    TestRepository testrepo = new TestRepository();
    testrepo.create(HistoryGuru.class.getResource("/repositories"));
    env.setSourceRoot(testrepo.getSourceRoot());
    env.setRepositories(testrepo.getSourceRoot());
    assertEquals(7, env.getRepositories().size());
    String[] repoNames = { "mercurial", "git" };
    env.setRepositories(Arrays.stream(repoNames).map(t -> Paths.get(env.getSourceRootPath(), t).toString()).distinct().toArray(String[]::new));
    assertEquals(2, env.getRepositories().size());
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) Repository(org.opengrok.indexer.history.Repository) RepositoryFactory(org.opengrok.indexer.history.RepositoryFactory) Arrays(java.util.Arrays) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Project(org.opengrok.indexer.configuration.Project) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Executor(org.opengrok.indexer.util.Executor) TandemPath(org.opengrok.indexer.util.TandemPath) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) FileUtilities(org.opengrok.indexer.util.FileUtilities) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) TestRepository(org.opengrok.indexer.util.TestRepository) CommandTimeoutType(org.opengrok.indexer.configuration.CommandTimeoutType) EnabledIf(org.junit.jupiter.api.condition.EnabledIf) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) AnalyzerGuru(org.opengrok.indexer.analysis.AnalyzerGuru) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) StringWriter(java.io.StringWriter) FileWriter(java.io.FileWriter) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MERCURIAL(org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL) FileReader(java.io.FileReader) Queue(java.util.Queue) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) AnalyzerFactory(org.opengrok.indexer.analysis.AnalyzerFactory) TestRepository(org.opengrok.indexer.util.TestRepository) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Test(org.junit.jupiter.api.Test) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 23 with TestRepository

use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.

the class MercurialRepositoryTest method setUpTestRepository.

/**
 * Set up a test repository. Should be called by the tests that need it. The
 * test repository will be destroyed automatically when the test finishes.
 */
private void setUpTestRepository() throws IOException, URISyntaxException {
    repository = new TestRepository();
    repository.create(getClass().getResource("/repositories"));
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository)

Example 24 with TestRepository

use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.

the class RepositoryFactoryTest method testNotWorkingRepository.

/*
     * There is no conditional run based on whether given repository is installed because
     * this test is not supposed to have working Mercurial anyway.
     */
static void testNotWorkingRepository(TestRepository repository, String repoPath, String propName) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException, ForbiddenSymlinkException {
    String origPropValue = System.setProperty(propName, "/foo/bar/nonexistent");
    try {
        File root = new File(repository.getSourceRoot(), repoPath);
        RuntimeEnvironment.getInstance().setSourceRoot(repository.getSourceRoot());
        Repository repo = RepositoryFactory.getRepository(root);
        assertNotNull(repo, "should have defined repo");
        assertFalse(repo.isWorking(), "repo should not be working");
    } finally {
        if (origPropValue != null) {
            System.setProperty(propName, origPropValue);
        } else {
            System.clearProperty(propName);
        }
    }
}
Also used : EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) TestRepository(org.opengrok.indexer.util.TestRepository) File(java.io.File)

Example 25 with TestRepository

use of org.opengrok.indexer.util.TestRepository in project OpenGrok by OpenGrok.

the class RepositoryWithPerPartesHistoryTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    repositories = new TestRepository();
    repositories.create(getClass().getResource("/repositories"));
    File reposRoot = new File(repositories.getSourceRoot(), "git");
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    assertNotNull(repo);
    assertTrue(repo instanceof RepositoryWithPerPartesHistory);
    gitRepository = (GitRepository) repo;
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) TestRepository(org.opengrok.indexer.util.TestRepository) File(java.io.File) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TestRepository (org.opengrok.indexer.util.TestRepository)45 BeforeAll (org.junit.jupiter.api.BeforeAll)26 BeforeEach (org.junit.jupiter.api.BeforeEach)16 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)15 File (java.io.File)14 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)10 Ctags (org.opengrok.indexer.analysis.Ctags)6 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)3 Project (org.opengrok.indexer.configuration.Project)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 CharArrayWriter (java.io.CharArrayWriter)1 FileReader (java.io.FileReader)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1