Search in sources :

Example 1 with ReindexGroupsAtStartupModule

use of com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule in project gerrit by GerritCodeReview.

the class GerritServer method startInMemory.

private static GerritServer startInMemory(Description desc, Path site, Config baseConfig, Daemon daemon, @Nullable InMemoryRepositoryManager inMemoryRepoManager) throws Exception {
    Config cfg = desc.buildConfig(baseConfig);
    daemon.setReplica(ReplicaUtil.isReplica(baseConfig) || ReplicaUtil.isReplica(cfg));
    mergeTestConfig(cfg);
    // Set the log4j configuration to an invalid one to prevent system logs
    // from getting configured and creating log files.
    System.setProperty(SystemLog.LOG4J_CONFIGURATION, "invalidConfiguration");
    cfg.setBoolean("httpd", null, "requestLog", false);
    cfg.setBoolean("sshd", null, "requestLog", false);
    cfg.setBoolean("index", "lucene", "testInmemory", true);
    cfg.setBoolean("index", null, "onlineUpgrade", false);
    cfg.setString("gitweb", null, "cgi", "");
    cfg.setString("accountPatchReviewDb", null, "url", JdbcAccountPatchReviewStore.TEST_IN_MEMORY_URL);
    String configuredIndexBackend = cfg.getString("index", null, "type");
    IndexType indexType;
    if (configuredIndexBackend != null) {
        // Explicitly configured index backend from gerrit.config trumps any other ways to configure
        // index backends so that Reindex tests can be explicit about the backend they want to test
        // against.
        indexType = new IndexType(configuredIndexBackend);
    } else {
        // Allow configuring the index backend based on sys/env variables so that integration tests
        // can be run against different index backends.
        indexType = IndexType.fromEnvironment().orElse(new IndexType("fake"));
    }
    if (indexType.isLucene()) {
        daemon.setIndexModule(LuceneIndexModule.singleVersionAllLatest(0, ReplicaUtil.isReplica(baseConfig), AutoFlush.ENABLED));
    } else {
        daemon.setIndexModule(FakeIndexModule.latestVersion(false));
    }
    daemon.setEnableHttpd(desc.httpd());
    daemon.setInMemory(true);
    daemon.setDatabaseForTesting(ImmutableList.of(new InMemoryTestingDatabaseModule(cfg, site, inMemoryRepoManager), new AbstractModule() {

        @Override
        protected void configure() {
            bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
        }
    }, new ConfigExperimentFeaturesModule()));
    daemon.addAdditionalSysModuleForTesting(new ReindexProjectsAtStartupModule(), new ReindexGroupsAtStartupModule());
    daemon.start();
    return new GerritServer(desc, null, createTestInjector(daemon), daemon, null);
}
Also used : GerritRuntime(com.google.gerrit.server.config.GerritRuntime) ReindexProjectsAtStartupModule(com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule) Config(org.eclipse.jgit.lib.Config) GlobalPluginConfig(com.google.gerrit.acceptance.config.GlobalPluginConfig) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) ReindexGroupsAtStartupModule(com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule) IndexType(com.google.gerrit.index.IndexType) AbstractModule(com.google.inject.AbstractModule)

Example 2 with ReindexGroupsAtStartupModule

use of com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule in project gerrit by GerritCodeReview.

the class GerritServer method startOnDisk.

private static GerritServer startOnDisk(Description desc, Path site, Daemon daemon, CyclicBarrier serverStarted, String[] additionalArgs) throws Exception {
    requireNonNull(site);
    daemon.addAdditionalSysModuleForTesting(new ReindexProjectsAtStartupModule(), new ReindexGroupsAtStartupModule());
    ExecutorService daemonService = Executors.newSingleThreadExecutor();
    String[] args = Stream.concat(Stream.of("-d", site.toString(), "--headless", "--console-log", "--show-stack-trace"), Arrays.stream(additionalArgs)).toArray(String[]::new);
    @SuppressWarnings("unused") Future<?> possiblyIgnoredError = daemonService.submit(() -> {
        int rc = daemon.main(args);
        if (rc != 0) {
            System.err.println("Failed to start Gerrit daemon");
            serverStarted.reset();
        }
        return null;
    });
    try {
        serverStarted.await();
    } catch (BrokenBarrierException e) {
        daemon.stop();
        throw new StartupException("Failed to start Gerrit daemon; see log", e);
    }
    System.out.println("Gerrit Server Started");
    return new GerritServer(desc, site, createTestInjector(daemon), daemon, daemonService);
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) ReindexProjectsAtStartupModule(com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule) ReindexGroupsAtStartupModule(com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

ReindexGroupsAtStartupModule (com.google.gerrit.acceptance.ReindexGroupsAtStartup.ReindexGroupsAtStartupModule)2 ReindexProjectsAtStartupModule (com.google.gerrit.acceptance.ReindexProjectsAtStartup.ReindexProjectsAtStartupModule)2 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)1 GlobalPluginConfig (com.google.gerrit.acceptance.config.GlobalPluginConfig)1 IndexType (com.google.gerrit.index.IndexType)1 GerritRuntime (com.google.gerrit.server.config.GerritRuntime)1 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 ConfigExperimentFeaturesModule (com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule)1 AbstractModule (com.google.inject.AbstractModule)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Config (org.eclipse.jgit.lib.Config)1