Search in sources :

Example 1 with Indexer

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

the class ProjectsControllerTest method testDelete.

/**
 * This test needs to perform indexing so that it can be verified that
 * delete handling does remove the index data.
 */
@Test
void testDelete() throws Exception {
    String[] projectsToDelete = { "git" };
    // Add a group matching the project to be added.
    String groupName = "gitgroup";
    Group group = new Group(groupName, "git.*");
    env.getGroups().add(group);
    assertTrue(env.hasGroups());
    assertEquals(1, env.getGroups().stream().filter(g -> g.getName().equals(groupName)).collect(Collectors.toSet()).size());
    assertEquals(0, group.getRepositories().size());
    assertEquals(0, group.getProjects().size());
    assertEquals(0, env.getProjects().size());
    assertEquals(0, env.getRepositories().size());
    assertEquals(0, env.getProjectRepositoriesMap().size());
    addProject("mercurial");
    addProject("git");
    assertEquals(2, env.getProjects().size());
    assertEquals(2, env.getRepositories().size());
    assertEquals(2, env.getProjectRepositoriesMap().size());
    // Check the group was populated properly.
    assertEquals(1, group.getRepositories().size());
    assertEquals(0, group.getProjects().size());
    assertEquals(1, group.getRepositories().stream().filter(p -> p.getName().equals("git")).collect(Collectors.toSet()).size());
    // Run the indexer so that data directory is populated.
    ArrayList<String> subFiles = new ArrayList<>();
    subFiles.add("/git");
    subFiles.add("/mercurial");
    ArrayList<String> repos = new ArrayList<>();
    repos.add("/git");
    repos.add("/mercurial");
    // This is necessary so that repositories in HistoryGuru get populated.
    // For per project reindex this is called from setConfiguration() because
    // of the -R option is present.
    HistoryGuru.getInstance().invalidateRepositories(env.getRepositories(), null, CommandTimeoutType.INDEXER);
    env.setHistoryEnabled(true);
    Indexer.getInstance().prepareIndexer(env, // don't search for repositories
    false, // don't scan and add projects
    false, // don't create dictionary
    false, // subFiles - needed when refreshing history partially
    subFiles, // repositories - needed when refreshing history partially
    repos);
    Indexer.getInstance().doIndexerExecution(true, null, null);
    for (String proj : projectsToDelete) {
        deleteProject(proj);
    }
    assertEquals(1, env.getProjects().size());
    assertEquals(1, env.getRepositories().size());
    assertEquals(1, env.getProjectRepositoriesMap().size());
    // Test data removal.
    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);
            assertFalse(dir.exists());
        }
    }
    // Check that HistoryGuru no longer maintains the removed projects.
    for (String p : projectsToDelete) {
        assertFalse(HistoryGuru.getInstance().getRepositories().stream().map(RepositoryInfo::getDirectoryName).collect(Collectors.toSet()).contains(repository.getSourceRoot() + File.separator + p));
    }
    // Check the group no longer contains the removed project.
    assertEquals(0, group.getRepositories().size());
    assertEquals(0, group.getProjects().size());
}
Also used : GrizzlyWebTestContainerFactory(org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory) BeforeEach(org.junit.jupiter.api.BeforeEach) RepositoryFactory(org.opengrok.indexer.history.RepositoryFactory) SuggesterService(org.opengrok.web.api.v1.suggester.provider.service.SuggesterService) Arrays(java.util.Arrays) Group(org.opengrok.indexer.configuration.Group) Project(org.opengrok.indexer.configuration.Project) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BeforeAll(org.junit.jupiter.api.BeforeAll) ApiTaskManager(org.opengrok.web.api.ApiTaskManager) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) RuntimeEnvironment(org.opengrok.indexer.configuration.RuntimeEnvironment) ApiUtils.waitForTask(org.opengrok.web.api.v1.controller.ApiUtils.waitForTask) Path(java.nio.file.Path) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) TestContainerException(org.glassfish.jersey.test.spi.TestContainerException) SUBVERSION(org.opengrok.indexer.condition.RepositoryInstalled.Type.SUBVERSION) IndexDatabase(org.opengrok.indexer.index.IndexDatabase) Collectors(java.util.stream.Collectors) Indexer(org.opengrok.indexer.index.Indexer) Entity(jakarta.ws.rs.client.Entity) Test(org.junit.jupiter.api.Test) IndexerException(org.opengrok.indexer.index.IndexerException) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) HistoryGuru(org.opengrok.indexer.history.HistoryGuru) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) DeploymentContext(org.glassfish.jersey.test.DeploymentContext) Mock(org.mockito.Mock) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) Response(jakarta.ws.rs.core.Response) RepositoryInfo(org.opengrok.indexer.history.RepositoryInfo) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestRepository(org.opengrok.indexer.util.TestRepository) CommandTimeoutType(org.opengrok.indexer.configuration.CommandTimeoutType) EnabledForRepository(org.opengrok.indexer.condition.EnabledForRepository) Files(java.nio.file.Files) IOUtils.removeRecursive(org.opengrok.indexer.util.IOUtils.removeRecursive) IOException(java.io.IOException) File(java.io.File) GenericType(jakarta.ws.rs.core.GenericType) AfterEach(org.junit.jupiter.api.AfterEach) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) Paths(java.nio.file.Paths) MERCURIAL(org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL) Collections(java.util.Collections) Group(org.opengrok.indexer.configuration.Group) ArrayList(java.util.ArrayList) File(java.io.File) MercurialRepositoryTest(org.opengrok.indexer.history.MercurialRepositoryTest) Test(org.junit.jupiter.api.Test)

Example 2 with Indexer

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

the class OptionParserTest method catchIndexerOptionsWithoutDescription.

// Fail options put into Indexer.java that do not have a description.
@Test
public void catchIndexerOptionsWithoutDescription() throws NoSuchFieldException, IllegalAccessException, ParseException {
    String[] argv = { "---unitTest" };
    Indexer.parseOptions(argv);
    // Use reflection to get the option parser from Indexer.
    Field f = Indexer.class.getDeclaredField("optParser");
    f.setAccessible(true);
    OptionParser op = (OptionParser) f.get(Indexer.class);
    for (OptionParser.Option o : op.getOptionList()) {
        assertNotNull(o.description, "'" + o.names.get(0) + "' option needs description");
        assertFalse(o.description.toString().isEmpty(), "'" + o.names.get(0) + "' option needs non-empty description");
    }
    // This just tests that the description is actually null.
    op = OptionParser.execute(parser -> {
        parser.on("--help-me-out");
    });
    for (OptionParser.Option o : op.getOptionList()) {
        assertNull(o.description);
    }
}
Also used : Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Field(java.lang.reflect.Field) ParseException(java.text.ParseException) Indexer(org.opengrok.indexer.index.Indexer) Field(java.lang.reflect.Field) Indexer(org.opengrok.indexer.index.Indexer) Test(org.junit.jupiter.api.Test)

Aggregations

Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 Entity (jakarta.ws.rs.client.Entity)1 GenericType (jakarta.ws.rs.core.GenericType)1 Response (jakarta.ws.rs.core.Response)1 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 StandardCopyOption (java.nio.file.StandardCopyOption)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1