use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testRenamedFile.
/**
* Make sure produces correct history for a renamed and moved file in Subversion.
*/
@EnabledForRepository(SUBVERSION)
@Test
void testRenamedFile() throws Exception {
createSvnRepository();
File reposRoot = new File(repositories.getSourceRoot(), "subversion");
History updatedHistory;
// The test expects support for renamed files.
env.setHandleHistoryOfRenamedFiles(true);
// Generate history index.
Repository repo = RepositoryFactory.getRepository(reposRoot);
History historyToStore = repo.getHistory(reposRoot);
cache.store(historyToStore, repo);
/* quick sanity check */
updatedHistory = cache.get(reposRoot, repo, true);
assertEquals(10, updatedHistory.getHistoryEntries().size());
// Check complete list of history entries for the renamed file.
File testFile = new File(reposRoot.toString() + File.separatorChar + "subfolder" + File.separatorChar + "TestFileRenamedAgain.txt");
updatedHistory = cache.get(testFile, repo, false);
assertEquals(4, updatedHistory.getHistoryEntries().size());
HistoryEntry e0 = new HistoryEntry("5", DateUtils.parseDate("2020-03-28T07:20:11.821Z", SVN_DATE_FORMAT), "RichardH", "Moved file to subfolder and renamed", true);
HistoryEntry e1 = new HistoryEntry("3", DateUtils.parseDate("2020-03-28T07:19:03.145Z", SVN_DATE_FORMAT), "RichardH", "Edited content", true);
HistoryEntry e2 = new HistoryEntry("2", DateUtils.parseDate("2020-03-28T07:18:29.481Z", SVN_DATE_FORMAT), "RichardH", "Rename file", true);
HistoryEntry e3 = new HistoryEntry("1", DateUtils.parseDate("2020-03-28T07:17:54.756Z", SVN_DATE_FORMAT), "RichardH", "Add initial file", true);
History histConstruct = new History();
LinkedList<HistoryEntry> entriesConstruct = new LinkedList<>();
entriesConstruct.add(e0);
entriesConstruct.add(e1);
entriesConstruct.add(e2);
entriesConstruct.add(e3);
histConstruct.setHistoryEntries(entriesConstruct);
assertSameEntries(histConstruct.getHistoryEntries(), updatedHistory.getHistoryEntries(), false);
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testStoreTouchGet.
/**
* {@link FileHistoryCache#get(File, Repository, boolean)} should not disturb history cache
* if run between repository update and reindex.
*/
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testStoreTouchGet() 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));
File file = new File(reposRoot, "main.c");
assertTrue(file.exists());
FileTime fileTimeBeforeImport = Files.getLastModifiedTime(file.toPath());
History historyBeforeImport = cache.get(file, repo, false);
MercurialRepositoryTest.runHgCommand(reposRoot, "import", Paths.get(getClass().getResource("/history/hg-export.txt").toURI()).toString());
FileTime fileTimeAfterImport = Files.getLastModifiedTime(file.toPath());
assertTrue(fileTimeBeforeImport.compareTo(fileTimeAfterImport) < 0);
// This get() call basically mimics a request through the UI or API.
History historyAfterImport = cache.get(file, repo, false);
assertNotNull(historyAfterImport);
assertNotEquals(historyBeforeImport, historyAfterImport);
// Simulates reindex, or at least its first part when history cache is updated.
repo.createCache(cache, cache.getLatestCachedRevision(repo));
// This makes sure that the file which contains the latest revision has indeed been created.
assertEquals("11:bbb3ce75e1b8", cache.getLatestCachedRevision(repo));
/*
* The history should not be disturbed.
* Make sure that get() retrieved the history from cache. Mocking/spying static methods
* (FileHistoryCache#readCache() in this case) is tricky so use the cache hits metric.
*/
double cacheHitsBeforeGet = cache.getFileHistoryCacheHits();
History historyAfterReindex = cache.get(file, repo, false);
double cacheHitsAfterGet = cache.getFileHistoryCacheHits();
assertNotNull(historyAfterReindex);
assertEquals(historyAfterImport, historyAfterReindex);
assertEquals(1, cacheHitsAfterGet - cacheHitsBeforeGet);
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testMultipleRenamedFiles.
/**
* Make sure produces correct history where several files are renamed in a single commit.
*/
@EnabledForRepository(SUBVERSION)
@Test
void testMultipleRenamedFiles() throws Exception {
createSvnRepository();
File reposRoot = new File(repositories.getSourceRoot(), "subversion");
History updatedHistory;
// The test expects support for renamed files.
env.setHandleHistoryOfRenamedFiles(true);
// Generate history index.
Repository repo = RepositoryFactory.getRepository(reposRoot);
History historyToStore = repo.getHistory(reposRoot);
cache.store(historyToStore, repo);
/* quick sanity check */
updatedHistory = cache.get(reposRoot, repo, true);
assertEquals(10, updatedHistory.getHistoryEntries().size());
// Check complete list of history entries for the renamed file.
File testFile = new File(reposRoot.toString() + File.separatorChar + "FileZ.txt");
updatedHistory = cache.get(testFile, repo, false);
assertEquals(3, updatedHistory.getHistoryEntries().size());
HistoryEntry e0 = new HistoryEntry("10", DateUtils.parseDate("2020-03-28T07:24:43.921Z", SVN_DATE_FORMAT), "RichardH", "Rename FileA to FileZ and FileB to FileX in a single commit", true);
HistoryEntry e1 = new HistoryEntry("7", DateUtils.parseDate("2020-03-28T07:21:55.273Z", SVN_DATE_FORMAT), "RichardH", "Amend file A", true);
HistoryEntry e2 = new HistoryEntry("6", DateUtils.parseDate("2020-03-28T07:21:05.888Z", SVN_DATE_FORMAT), "RichardH", "Add file A", true);
History histConstruct = new History();
LinkedList<HistoryEntry> entriesConstruct = new LinkedList<>();
entriesConstruct.add(e0);
entriesConstruct.add(e1);
entriesConstruct.add(e2);
histConstruct.setHistoryEntries(entriesConstruct);
assertSameEntries(histConstruct.getHistoryEntries(), updatedHistory.getHistoryEntries(), false);
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class FileHistoryCacheTest method testStoreAndTryToGetIgnored.
/**
* Test history when activating PathAccepter for ignoring files.
*/
@EnabledOnOs({ OS.LINUX, OS.MAC, OS.SOLARIS, OS.AIX, OS.OTHER })
@EnabledForRepository(MERCURIAL)
@Test
void testStoreAndTryToGetIgnored() throws Exception {
env.getIgnoredNames().add("f:Make*");
File reposRoot = new File(repositories.getSourceRoot(), "mercurial");
Repository repo = RepositoryFactory.getRepository(reposRoot);
History historyToStore = repo.getHistory(reposRoot);
cache.store(historyToStore, repo);
// test reindex history
History historyNull = new History();
cache.store(historyNull, repo);
// test get history for single file
File makefile = new File(reposRoot, "Makefile");
assertTrue(makefile.exists(), "" + makefile + " should exist");
History retrievedHistory = cache.get(makefile, repo, true);
assertNull(retrievedHistory, "history for Makefile should be null");
// Gross that we can break encapsulation, but oh well.
env.getIgnoredNames().clear();
cache.store(historyToStore, repo);
retrievedHistory = cache.get(makefile, repo, true);
assertNotNull(retrievedHistory, "history for Makefile should not be null");
}
use of org.opengrok.indexer.condition.EnabledForRepository in project OpenGrok by OpenGrok.
the class IndexerRepoTest method testSymlinks.
/**
* Test that symlinked directories from source root get their relative
* path set correctly in RepositoryInfo objects.
*/
@EnabledForRepository(MERCURIAL)
@Test
public void testSymlinks() throws IndexerException, IOException {
final String SYMLINK = "symlink";
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
// Set source root to pristine directory so that there is only one
// repository to deal with (which makes this faster and easier to write)
// and clone the mercurial repository outside of the source root.
Path realSource = Files.createTempDirectory("real");
Path sourceRoot = Files.createTempDirectory("src");
MercurialRepositoryTest.runHgCommand(sourceRoot.toFile(), "clone", repository.getSourceRoot() + File.separator + "mercurial", realSource.toString());
// Create symlink from source root to the real repository.
String symlinkPath = sourceRoot.toString() + File.separator + SYMLINK;
Files.createSymbolicLink(Paths.get(symlinkPath), realSource);
// Use alternative source root.
env.setSourceRoot(sourceRoot.toString());
// Need to have history cache enabled in order to perform scan of repositories.
env.setHistoryEnabled(true);
// Normally the Indexer would add the symlink automatically.
env.setAllowedSymlinks(new HashSet<>(Arrays.asList(symlinkPath)));
// Do a rescan of the projects, and only that (we don't care about
// the other aspects of indexing in this test case).
Indexer.getInstance().prepareIndexer(env, // search for repositories
true, // scan and add projects
true, // don't create dictionary
false, // subFiles - not needed since we don't list files
null, // repositories - not needed when not refreshing history
null);
// Check the repository paths.
List<RepositoryInfo> repos = env.getRepositories();
assertEquals(repos.size(), 1);
RepositoryInfo repo = repos.get(0);
assertEquals(File.separator + SYMLINK, repo.getDirectoryNameRelative());
String epath = sourceRoot.toString() + File.separator + SYMLINK;
String apath = repo.getDirectoryName();
assertTrue(epath.equals(apath) || apath.equals("/private" + epath), "Should match (with macOS leeway):\n" + epath + "\nv.\n" + apath);
// Check that history exists for a file in the repository.
File repoRoot = new File(env.getSourceRootFile(), SYMLINK);
File fileInRepo = new File(repoRoot, "main.c");
assertTrue(fileInRepo.exists());
assertTrue(HistoryGuru.getInstance().hasHistory(fileInRepo));
assertTrue(HistoryGuru.getInstance().hasCacheForFile(fileInRepo));
// cleanup
IOUtils.removeRecursive(realSource);
IOUtils.removeRecursive(sourceRoot);
}
Aggregations