Search in sources :

Example 16 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class FileHistoryCacheTest method testRenamedFilePlusChangesBranched.

/**
 * Make sure generating incremental history index in branched repository
 * with renamed file produces correct history for the renamed file
 * (i.e. there should not be history entries from the default branch made
 * there after the branch was created).
 */
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testRenamedFilePlusChangesBranched() throws Exception {
    File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
    History updatedHistory;
    // The test expects support for renamed files.
    env.setHandleHistoryOfRenamedFiles(true);
    // Use tags for better coverage.
    env.setTagsEnabled(true);
    // Branch the repo and add one changeset.
    runHgCommand(reposRoot, "unbundle", Paths.get(getClass().getResource("/history/hg-branch.bundle").toURI()).toString());
    // Import changesets which rename one of the files in the default branch.
    runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export-renamed.txt").toURI()).toString());
    // Switch to the newly created branch.
    runHgCommand(reposRoot, "update", "mybranch");
    // Generate history index.
    // It is necessary to call getRepository() only after tags were enabled
    // to produce list of tags.
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    History historyToStore = repo.getHistory(reposRoot);
    cache.store(historyToStore, repo);
    /* quick sanity check */
    updatedHistory = cache.get(reposRoot, repo, true);
    assertEquals(11, updatedHistory.getHistoryEntries().size());
    // Import changesets which rename the file in the new branch.
    runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export-renamed-branched.txt").toURI()).toString());
    // Perform incremental reindex.
    repo.createCache(cache, cache.getLatestCachedRevision(repo));
    /* overall history check */
    updatedHistory = cache.get(reposRoot, repo, false);
    assertEquals(12, updatedHistory.getHistoryEntries().size());
    // Check complete list of history entries for the renamed file.
    File testFile = new File(reposRoot.toString() + File.separatorChar + "blog.txt");
    updatedHistory = cache.get(testFile, repo, false);
    HistoryEntry e0 = new HistoryEntry("15:709c7a27f9fa", // whole minutes only
    new Date(1489160275L / 60 * 60 * 1000), "Vladimir Kotal <Vladimir.Kotal@oracle.com>", "novels are so last century. Let's write a blog !", true);
    HistoryEntry e1 = new HistoryEntry("10:c4518ca0c841", // whole minutes only
    new Date(1415483555L / 60 * 60 * 1000), "Vladimir Kotal <Vladimir.Kotal@oracle.com>", "branched", true);
    HistoryEntry e2 = new HistoryEntry("8:6a8c423f5624", // whole minutes only
    new Date(1362586899L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "first words of the novel", true);
    HistoryEntry e3 = new HistoryEntry("7:db1394c05268", // whole minutes only
    new Date(1362586862L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "book sounds too boring, let's do a novel !", true);
    HistoryEntry e4 = new HistoryEntry("6:e386b51ddbcc", // whole minutes only
    new Date(1362586839L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "stub of chapter 1", true);
    HistoryEntry e5 = new HistoryEntry("5:8706402863c6", // whole minutes only
    new Date(1362586805L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "I decided to actually start writing a book based on the first plaintext file.", true);
    HistoryEntry e6 = new HistoryEntry("4:e494d67af12f", // whole minutes only
    new Date(1362586747L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "first change", true);
    HistoryEntry e7 = new HistoryEntry("3:2058725c1470", // whole minutes only
    new Date(1362586483L / 60 * 60 * 1000), "Vladimir Kotal <vlada@devnull.cz>", "initial checking of text files", true);
    History histConstruct = new History();
    LinkedList<HistoryEntry> entriesConstruct = new LinkedList<>();
    entriesConstruct.add(e0);
    entriesConstruct.add(e1);
    entriesConstruct.add(e2);
    entriesConstruct.add(e3);
    entriesConstruct.add(e4);
    entriesConstruct.add(e5);
    entriesConstruct.add(e6);
    entriesConstruct.add(e7);
    histConstruct.setHistoryEntries(entriesConstruct);
    assertSameEntries(histConstruct.getHistoryEntries(), updatedHistory.getHistoryEntries(), false);
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) File(java.io.File) Date(java.util.Date) LinkedList(java.util.LinkedList) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 17 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class FileHistoryCacheTest method testStoreAndGet.

/**
 * Basic tests for the {@code store()} and {@code get()} methods.
 */
@Test
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
void testStoreAndGet() throws Exception {
    File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
    // The test expects support for renamed files.
    env.setHandleHistoryOfRenamedFiles(true);
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    History historyToStore = repo.getHistory(reposRoot);
    cache.store(historyToStore, repo);
    // test reindex
    History historyNull = new History();
    cache.store(historyNull, repo);
    // test get history for single file
    File makefile = new File(reposRoot, "Makefile");
    assertTrue(makefile.exists());
    History retrievedHistory = cache.get(makefile, repo, true);
    List<HistoryEntry> entries = retrievedHistory.getHistoryEntries();
    assertEquals(2, entries.size(), "Unexpected number of entries");
    final String TROND = "Trond Norbye <trond.norbye@sun.com>";
    Iterator<HistoryEntry> entryIt = entries.iterator();
    HistoryEntry e1 = entryIt.next();
    assertEquals(TROND, e1.getAuthor());
    assertEquals("2:585a1b3f2efb", e1.getRevision());
    assertEquals(0, e1.getFiles().size());
    HistoryEntry e2 = entryIt.next();
    assertEquals(TROND, e2.getAuthor());
    assertEquals("1:f24a5fd7a85d", e2.getRevision());
    assertEquals(0, e2.getFiles().size());
    assertFalse(entryIt.hasNext());
    // test get history for renamed file
    File novel = new File(reposRoot, "novel.txt");
    assertTrue(novel.exists());
    retrievedHistory = cache.get(novel, repo, true);
    entries = retrievedHistory.getHistoryEntries();
    assertEquals(6, entries.size(), "Unexpected number of entries");
    // test get history for directory
    // Need to refresh history to store since the file lists were stripped
    // from it in the call to cache.store() above.
    historyToStore = repo.getHistory(reposRoot);
    History dirHistory = cache.get(reposRoot, repo, true);
    assertSameEntries(historyToStore.getHistoryEntries(), dirHistory.getHistoryEntries(), true);
    // test incremental update
    MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export.txt").toURI()).toString());
    repo.createCache(cache, cache.getLatestCachedRevision(repo));
    History updatedHistory = cache.get(reposRoot, repo, true);
    HistoryEntry newEntry1 = new HistoryEntry("10:1e392ef0b0ed", // whole minutes only
    new Date(1245446973L / 60 * 60 * 1000), "xyz", "Return failure when executed with no arguments", true);
    newEntry1.addFile("/mercurial/main.c");
    HistoryEntry newEntry2 = new HistoryEntry("11:bbb3ce75e1b8", // whole minutes only
    new Date(1245447973L / 60 * 60 * 1000), "xyz", "Do something else", true);
    newEntry2.addFile("/mercurial/main.c");
    LinkedList<HistoryEntry> updatedEntries = new LinkedList<>(updatedHistory.getHistoryEntries());
    // The history for retrieved for the whole directory so it will contain
    // lists of files so we need to set isdir to true.
    assertSameEntry(newEntry2, updatedEntries.removeFirst(), true);
    assertSameEntry(newEntry1, updatedEntries.removeFirst(), true);
    assertSameEntries(historyToStore.getHistoryEntries(), updatedEntries, true);
    // test clearing of cache
    File dir = new File(cache.getRepositoryHistDataDirname(repo));
    assertTrue(dir.isDirectory());
    cache.clear(repo);
    // We cannot call cache.get() here since it would read the history anew.
    // Instead check that the data directory does not exist anymore.
    assertFalse(dir.exists());
    cache.store(historyToStore, repo);
    // check that the data directory is non-empty
    assertTrue(dir.list().length > 0);
    updatedHistory = cache.get(reposRoot, repo, true);
    assertSameEntries(updatedHistory.getHistoryEntries(), cache.get(reposRoot, repo, true).getHistoryEntries(), true);
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) File(java.io.File) Date(java.util.Date) LinkedList(java.util.LinkedList) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 18 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class FileHistoryCacheTest method testStoreAndGetIncrementalTags.

/**
 * Test tagging by creating history cache for repository with one tag and
 * then importing couple of changesets which add both file changes and tags.
 * The last history entry before the import is important as it needs to be
 * retagged when old history is merged with the new one.
 */
@EnabledForRepository(MERCURIAL)
@Test
void testStoreAndGetIncrementalTags() throws Exception {
    // Enable tagging of history entries.
    env.setTagsEnabled(true);
    File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    History historyToStore = repo.getHistory(reposRoot);
    // Store the history.
    cache.store(historyToStore, repo);
    // Avoid uncommitted changes.
    MercurialRepositoryTest.runHgCommand(reposRoot, "revert", "--all");
    // Add bunch of changesets with file based changes and tags.
    MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export-tag.txt").toURI()).toString());
    // Perform incremental reindex.
    repo.createCache(cache, cache.getLatestCachedRevision(repo));
    // Check that the changesets were indeed applied and indexed.
    History updatedHistory = cache.get(reposRoot, repo, true);
    assertEquals(15, updatedHistory.getHistoryEntries().size(), "Unexpected number of history entries");
    // Verify tags in fileHistory for main.c which is the most interesting
    // file from the repository from the perspective of tags.
    File main = new File(reposRoot, "main.c");
    assertTrue(main.exists());
    History retrievedHistoryMainC = cache.get(main, repo, true);
    List<HistoryEntry> entries = retrievedHistoryMainC.getHistoryEntries();
    assertEquals(3, entries.size(), "Unexpected number of entries for main.c");
    HistoryEntry e0 = entries.get(0);
    assertEquals("13:3d386f6bd848", e0.getRevision(), "Unexpected revision for entry 0");
    assertEquals("tag3", retrievedHistoryMainC.getTags().get(e0.getRevision()), "Invalid tag list for revision 13");
    HistoryEntry e1 = entries.get(1);
    assertEquals("2:585a1b3f2efb", e1.getRevision(), "Unexpected revision for entry 1");
    assertEquals("tag2, tag1, start_of_novel", retrievedHistoryMainC.getTags().get(e1.getRevision()), "Invalid tag list for revision 2");
    HistoryEntry e2 = entries.get(2);
    assertEquals("1:f24a5fd7a85d", e2.getRevision(), "Unexpected revision for entry 2");
    assertNull(retrievedHistoryMainC.getTags().get(e2.getRevision()), "Invalid tag list for revision 1");
    // Reindex from scratch.
    File dir = new File(cache.getRepositoryHistDataDirname(repo));
    assertTrue(dir.isDirectory());
    cache.clear(repo);
    // We cannot call cache.get() here since it would read the history anew.
    // Instead check that the data directory does not exist anymore.
    assertFalse(dir.exists());
    History freshHistory = repo.getHistory(reposRoot);
    cache.store(freshHistory, repo);
    History updatedHistoryFromScratch = cache.get(reposRoot, repo, true);
    assertEquals(freshHistory.getHistoryEntries().size(), updatedHistoryFromScratch.getHistoryEntries().size(), "Unexpected number of history entries");
    // Verify that the result for the directory is the same as incremental reindex.
    assertSameEntries(updatedHistory.getHistoryEntries(), updatedHistoryFromScratch.getHistoryEntries(), true);
    // Do the same for main.c.
    History retrievedUpdatedHistoryMainC = cache.get(main, repo, true);
    assertSameEntries(retrievedHistoryMainC.getHistoryEntries(), retrievedUpdatedHistoryMainC.getHistoryEntries(), false);
    assertEquals(Map.of("13:3d386f6bd848", "tag3", "2:585a1b3f2efb", "tag2, tag1, start_of_novel"), retrievedUpdatedHistoryMainC.getTags());
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 19 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class FileHistoryCacheTest method testStoreAndGetNotRenamed.

/**
 * Basic tests for the {@code store()} method on cache with disabled
 * handling of renamed files.
 */
@EnabledForRepository(MERCURIAL)
@Test
void testStoreAndGetNotRenamed() throws Exception {
    File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
    Repository repo = RepositoryFactory.getRepository(reposRoot);
    History historyToStore = repo.getHistory(reposRoot);
    cache.store(historyToStore, repo);
    // This makes sure that the file which contains the latest revision
    // has indeed been created.
    assertEquals("9:8b340409b3a8", cache.getLatestCachedRevision(repo));
    // test reindex
    History historyNull = new History();
    cache.store(historyNull, repo);
    assertEquals("9:8b340409b3a8", cache.getLatestCachedRevision(repo));
}
Also used : TestRepository(org.opengrok.indexer.util.TestRepository) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Example 20 with EnabledForRepository

use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.

the class HistoryGuruTest method testBug16465.

@Test
@EnabledForRepository(SUBVERSION)
void testBug16465() throws HistoryException, IOException {
    HistoryGuru instance = HistoryGuru.getInstance();
    for (File f : FILES) {
        if (f.getName().equals("bugreport16465@")) {
            assertNotNull(instance.getHistory(f), f.getPath() + " must have history");
            assertNotNull(instance.annotate(f, null), f.getPath() + " must have annotations");
        }
    }
}
Also used : File(java.io.File) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository)

Aggregations

Test (org.junit.jupiter.api.Test)21 EnabledForRepository (org.opengrok.indexer.condition.EnabledForRepository)21 File (java.io.File)19 TestRepository (org.opengrok.indexer.util.TestRepository)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 LinkedList (java.util.LinkedList)5 EnabledOnOs (org.junit.jupiter.api.condition.EnabledOnOs)5 Path (java.nio.file.Path)3 Date (java.util.Date)3 RuntimeEnvironment (org.opengrok.indexer.configuration.RuntimeEnvironment)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 Term (org.apache.lucene.index.Term)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)2 PhraseQuery (org.apache.lucene.search.PhraseQuery)2 TermQuery (org.apache.lucene.search.TermQuery)2 Project (org.opengrok.indexer.configuration.Project)2 HistoryGuru (org.opengrok.indexer.history.HistoryGuru)2