Search in sources :

Example 1 with Indexer

use of org.opensolaris.opengrok.index.Indexer in project OpenGrok by OpenGrok.

the class ProjectMessageTest method testDelete.

/**
 * This test needs to perform indexing so that it can be verified that
 * the delete message handling performs removal of the index data.
 * @throws Exception
 */
@Test
public void testDelete() throws Exception {
    String[] projectsToDelete = { "git", "svn" };
    assertTrue("No point in running indexer tests without valid ctags", RuntimeEnvironment.getInstance().validateExuberantCtags());
    // Add a group matching the project to be added.
    String groupName = "gitgroup";
    Group group = new Group(groupName, "git.*");
    env.getGroups().add(group);
    Assert.assertTrue(env.hasGroups());
    Assert.assertEquals(1, env.getGroups().stream().filter(g -> g.getName().equals(groupName)).collect(Collectors.toSet()).size());
    Assert.assertEquals(0, group.getRepositories().size());
    Assert.assertEquals(0, group.getProjects().size());
    // Firstly add some projects.
    Message m = new ProjectMessage();
    m.setText("add");
    m.addTag("mercurial");
    m.addTag("git");
    m.addTag("svn");
    Assert.assertEquals(0, env.getProjects().size());
    Assert.assertEquals(0, env.getRepositories().size());
    Assert.assertEquals(0, env.getProjectRepositoriesMap().size());
    m.apply(env);
    Assert.assertEquals(3, env.getProjects().size());
    Assert.assertEquals(3, env.getRepositories().size());
    Assert.assertEquals(3, env.getProjectRepositoriesMap().size());
    // Check the group was populated properly.
    Assert.assertEquals(1, group.getRepositories().size());
    Assert.assertEquals(0, group.getProjects().size());
    Assert.assertEquals(1, group.getRepositories().stream().filter(p -> p.getName().equals("git")).collect(Collectors.toSet()).size());
    // Run the indexer (ala 'indexpart') so that data directory is populated.
    ArrayList<String> subFiles = new ArrayList<>();
    subFiles.add("/git");
    subFiles.add("/mercurial");
    subFiles.add("/svn");
    ArrayList<String> repos = new ArrayList<>();
    repos.add("/git");
    repos.add("/mercurial");
    repos.add("/svn");
    // This is necessary so that repositories in HistoryGuru get populated.
    // When 'indexpart' is run, this is called from setConfiguration() because
    // of the -R option is present.
    HistoryGuru.getInstance().invalidateRepositories(env.getRepositories());
    env.setHistoryEnabled(true);
    Indexer.getInstance().prepareIndexer(env, // don't search for repositories
    false, // don't scan and add projects
    false, // no default project
    null, // don't list files
    false, // don't create dictionary
    false, // subFiles - needed when refreshing history partially
    subFiles, // repositories - needed when refreshing history partially
    repos, // don't zap cache
    new ArrayList<>(), // don't list repos
    false);
    Indexer.getInstance().doIndexerExecution(true, null, null);
    // Then remove multiple projects.
    m.setText("delete");
    m.setTags(new TreeSet<String>());
    for (String p : projectsToDelete) {
        m.addTag(p);
    }
    m.apply(env);
    Assert.assertEquals(1, env.getProjects().size());
    Assert.assertEquals(1, env.getRepositories().size());
    Assert.assertEquals(1, env.getProjectRepositoriesMap().size());
    // Test data removal.
    File dataRoot = env.getDataRootFile();
    for (String projectName : projectsToDelete) {
        for (String dirName : new String[] { "historycache", IndexDatabase.XREF_DIR, IndexDatabase.INDEX_DIR }) {
            File dir = new File(env.getDataRootFile(), dirName + File.separator + projectName);
            Assert.assertFalse(dir.exists());
        }
    }
    // Check that HistoryGuru no longer maintains the removed projects.
    for (String p : projectsToDelete) {
        Assert.assertFalse(HistoryGuru.getInstance().getRepositories().stream().map(ri -> ri.getDirectoryName()).collect(Collectors.toSet()).contains(repository.getSourceRoot() + File.separator + p));
    }
    // Check the group no longer contains the removed project.
    Assert.assertEquals(0, group.getRepositories().size());
    Assert.assertEquals(0, group.getProjects().size());
}
Also used : IOUtils.removeRecursive(org.opensolaris.opengrok.util.IOUtils.removeRecursive) HistoryGuru(org.opensolaris.opengrok.history.HistoryGuru) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Indexer(org.opensolaris.opengrok.index.Indexer) RepositoryInstalled(org.opensolaris.opengrok.condition.RepositoryInstalled) GitRepository(org.opensolaris.opengrok.history.GitRepository) Project(org.opensolaris.opengrok.configuration.Project) RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) After(org.junit.After) Assume(org.junit.Assume) ConditionalRun(org.opensolaris.opengrok.condition.ConditionalRun) Group(org.opensolaris.opengrok.configuration.Group) Before(org.junit.Before) MercurialRepository(org.opensolaris.opengrok.history.MercurialRepository) SubversionRepository(org.opensolaris.opengrok.history.SubversionRepository) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) TestRepository(org.opensolaris.opengrok.util.TestRepository) List(java.util.List) IndexDatabase(org.opensolaris.opengrok.index.IndexDatabase) RepositoryFactory(org.opensolaris.opengrok.history.RepositoryFactory) MercurialRepositoryTest(org.opensolaris.opengrok.history.MercurialRepositoryTest) Assert(org.junit.Assert) RepositoryInfo(org.opensolaris.opengrok.history.RepositoryInfo) Group(org.opensolaris.opengrok.configuration.Group) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test) MercurialRepositoryTest(org.opensolaris.opengrok.history.MercurialRepositoryTest)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Collectors (java.util.stream.Collectors)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assume (org.junit.Assume)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ConditionalRun (org.opensolaris.opengrok.condition.ConditionalRun)1 RepositoryInstalled (org.opensolaris.opengrok.condition.RepositoryInstalled)1 Group (org.opensolaris.opengrok.configuration.Group)1 Project (org.opensolaris.opengrok.configuration.Project)1 RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)1 GitRepository (org.opensolaris.opengrok.history.GitRepository)1