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());
}
Aggregations