Search in sources :

Example 1 with FakeEmailSenderModule

use of com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule in project gerrit by GerritCodeReview.

the class GerritServer method start.

/**
 * Starts Gerrit server from existing on-disk site.
 *
 * @param desc server description.
 * @param baseConfig default config values; merged with config from {@code desc}.
 * @param site existing temporary directory for site. Required, but may be empty, for in-memory
 *     servers. For on-disk servers, assumes that {@link #init} was previously called to
 *     initialize this directory. Can be retrieved from the returned instance via {@link
 *     #getSitePath()}.
 * @param testSysModule optional additional module to add to the system injector.
 * @param testSshModule optional additional module to add to the ssh injector.
 * @param inMemoryRepoManager {@link InMemoryRepositoryManager} that should be used if the site is
 *     started in memory
 * @param additionalArgs additional command-line arguments for the daemon program; only allowed if
 *     the test is not in-memory.
 * @return started server.
 */
public static GerritServer start(Description desc, Config baseConfig, Path site, @Nullable Module testSysModule, @Nullable Module testAuditModule, @Nullable Module testSshModule, @Nullable InMemoryRepositoryManager inMemoryRepoManager, String... additionalArgs) throws Exception {
    checkArgument(site != null, "site is required (even for in-memory server");
    desc.checkValidAnnotations();
    TestLoggingActivator.configureLogging();
    CyclicBarrier serverStarted = new CyclicBarrier(2);
    Daemon daemon = new Daemon(() -> {
        try {
            serverStarted.await();
        } catch (InterruptedException | BrokenBarrierException e) {
            throw new RuntimeException(e);
        }
    }, site);
    daemon.setEmailModuleForTesting(new FakeEmailSenderModule());
    daemon.setAuditEventModuleForTesting(MoreObjects.firstNonNull(testAuditModule, new FakeGroupAuditServiceModule()));
    if (testSysModule != null) {
        daemon.addAdditionalSysModuleForTesting(testSysModule);
    }
    if (testSshModule != null) {
        daemon.addAdditionalSshModuleForTesting(testSshModule);
    }
    daemon.setEnableSshd(desc.useSsh());
    daemon.addAdditionalSysModuleForTesting(new AbstractModule() {

        @Override
        protected void configure() {
            bind(CommitValidationListener.class).annotatedWith(Exports.named("object-visibility-listener")).to(GitObjectVisibilityChecker.class);
        }
    });
    daemon.addAdditionalSysModuleForTesting(new AbstractModule() {

        @Override
        protected void configure() {
            super.configure();
            // GerritServer isn't restarted between tests. TestTicker allows to replace actual
            // Ticker in tests without restarting server and transparently for other code.
            // Alternative option with Provider<Ticker> is less convinient, because it affects how
            // gerrit code should be written - i.e. Ticker must not be stored in fields and must
            // always be obtained from the provider.
            TestTicker testTicker = new TestTicker();
            OptionalBinder.newOptionalBinder(binder(), Ticker.class).setBinding().toInstance(testTicker);
            bind(TestTicker.class).toInstance(testTicker);
        }
    });
    if (desc.memory()) {
        checkArgument(additionalArgs.length == 0, "cannot pass args to in-memory server");
        return startInMemory(desc, site, baseConfig, daemon, inMemoryRepoManager);
    }
    return startOnDisk(desc, site, daemon, serverStarted, additionalArgs);
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) Ticker(com.google.common.base.Ticker) TestTicker(com.google.gerrit.acceptance.AbstractDaemonTest.TestTicker) CyclicBarrier(java.util.concurrent.CyclicBarrier) AbstractModule(com.google.inject.AbstractModule) FakeEmailSenderModule(com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule) Daemon(com.google.gerrit.pgm.Daemon) FakeGroupAuditServiceModule(com.google.gerrit.acceptance.FakeGroupAuditService.FakeGroupAuditServiceModule) TestTicker(com.google.gerrit.acceptance.AbstractDaemonTest.TestTicker)

Example 2 with FakeEmailSenderModule

use of com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule in project gerrit by GerritCodeReview.

the class InMemoryModule method configure.

@Override
protected void configure() {
    // Do NOT bind @RemotePeer, as it is bound in a child injector of
    // ChangeMergeQueue (bound via GerritGlobalModule below), so there cannot be
    // a binding in the parent injector. If you need @RemotePeer, you must bind
    // it in a child injector of the one containing InMemoryModule. But unless
    // you really need to test something request-scoped, you likely don't
    // actually need it.
    // For simplicity, don't create child injectors, just use this one to get a
    // few required modules.
    Injector cfgInjector = Guice.createInjector(new AbstractModule() {

        @Override
        protected void configure() {
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
        }
    });
    bind(GerritRuntime.class).toInstance(GerritRuntime.DAEMON);
    bind(MetricMaker.class).to(DisabledMetricMaker.class);
    install(cfgInjector.getInstance(GerritGlobalModule.class));
    AuthConfig authConfig = cfgInjector.getInstance(AuthConfig.class);
    install(new AuthModule(authConfig));
    install(new GerritApiModule());
    factory(PluginUser.Factory.class);
    install(new PluginApiModule());
    install(new DefaultPermissionBackendModule());
    install(new SearchingChangeCacheImplModule());
    factory(GarbageCollection.Factory.class);
    install(new AuditModule());
    install(new SubscriptionGraphModule());
    install(new SuperprojectUpdateSubmissionListenerModule());
    bindScope(RequestScoped.class, PerThreadRequestScope.REQUEST);
    // It would be nice to use Jimfs for the SitePath, but the biggest blocker is that JGit does not
    // support Path-based Configs, only FileBasedConfig.
    bind(Path.class).annotatedWith(SitePath.class).toInstance(Paths.get("."));
    bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(cfg);
    bind(GerritOptions.class).toInstance(new GerritOptions(false, false));
    bind(AllProjectsConfigProvider.class).to(FileBasedAllProjectsConfigProvider.class);
    bind(GlobalPluginConfigProvider.class).to(FileBasedGlobalPluginConfigProvider.class);
    bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
    bind(InMemoryRepositoryManager.class).in(SINGLETON);
    bind(TrackingFooters.class).toProvider(TrackingFootersProvider.class).in(SINGLETON);
    bind(SecureStore.class).to(DefaultSecureStore.class);
    install(new InMemorySchemaModule());
    install(NoSshKeyCache.module());
    install(new GerritInstanceNameModule());
    install(new GerritInstanceIdModule());
    install(new CanonicalWebUrlModule() {

        @Override
        protected Class<? extends Provider<String>> provider() {
            return CanonicalWebUrlProvider.class;
        }
    });
    install(new DefaultUrlFormatterModule());
    // Replacement of DiffExecutorModule to not use thread pool in the tests
    install(new AbstractModule() {

        @Override
        protected void configure() {
        }

        @Provides
        @Singleton
        @DiffExecutor
        public ExecutorService createDiffExecutor() {
            return newDirectExecutorService();
        }
    });
    install(new DefaultMemoryCacheModule());
    install(new H2CacheModule());
    install(new FakeEmailSenderModule());
    install(new SignedTokenEmailTokenVerifierModule());
    install(new GpgModule(cfg));
    install(new LocalMergeSuperSetComputationModule());
    bind(AllAccountsIndexer.class).toProvider(Providers.of(null));
    bind(AllChangesIndexer.class).toProvider(Providers.of(null));
    bind(AllGroupsIndexer.class).toProvider(Providers.of(null));
    String indexTypeCfg = cfg.getString("index", null, "type");
    IndexType indexType = new IndexType(indexTypeCfg != null ? indexTypeCfg : "fake");
    // For custom index types, callers must provide their own module.
    if (indexType.isLucene()) {
        install(luceneIndexModule());
    } else if (indexType.isFake()) {
        install(fakeIndexModule());
    }
    bind(ServerInformationImpl.class);
    bind(ServerInformation.class).to(ServerInformationImpl.class);
    install(new RestApiModule());
    install(new OAuthRestModule());
    install(new DefaultProjectNameLockManagerModule());
    install(new FileInfoJsonModule());
    install(new ConfigExperimentFeaturesModule());
    bind(ProjectOperations.class).to(ProjectOperationsImpl.class);
}
Also used : MetricMaker(com.google.gerrit.metrics.MetricMaker) DisabledMetricMaker(com.google.gerrit.metrics.DisabledMetricMaker) RestApiModule(com.google.gerrit.server.restapi.RestApiModule) AuthConfig(com.google.gerrit.server.config.AuthConfig) DefaultProjectNameLockManagerModule(com.google.gerrit.server.project.DefaultProjectNameLockManager.DefaultProjectNameLockManagerModule) GerritGlobalModule(com.google.gerrit.server.config.GerritGlobalModule) SearchingChangeCacheImplModule(com.google.gerrit.server.git.SearchingChangeCacheImpl.SearchingChangeCacheImplModule) GerritRuntime(com.google.gerrit.server.config.GerritRuntime) FakeEmailSenderModule(com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule) Injector(com.google.inject.Injector) SuperprojectUpdateSubmissionListenerModule(com.google.gerrit.server.update.SuperprojectUpdateSubmissionListener.SuperprojectUpdateSubmissionListenerModule) ConfigExperimentFeaturesModule(com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) DefaultPermissionBackendModule(com.google.gerrit.server.permissions.DefaultPermissionBackendModule) FileInfoJsonModule(com.google.gerrit.server.change.FileInfoJsonModule) GerritOptions(com.google.gerrit.server.config.GerritOptions) DefaultSecureStore(com.google.gerrit.server.securestore.DefaultSecureStore) SecureStore(com.google.gerrit.server.securestore.SecureStore) SignedTokenEmailTokenVerifierModule(com.google.gerrit.server.mail.SignedTokenEmailTokenVerifier.SignedTokenEmailTokenVerifierModule) Singleton(com.google.inject.Singleton) AuditModule(com.google.gerrit.server.audit.AuditModule) SitePath(com.google.gerrit.server.config.SitePath) DiffExecutor(com.google.gerrit.server.patch.DiffExecutor) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) AuthConfig(com.google.gerrit.server.config.AuthConfig) FileBasedGlobalPluginConfigProvider(com.google.gerrit.server.config.FileBasedGlobalPluginConfigProvider) GlobalPluginConfigProvider(com.google.gerrit.server.config.GlobalPluginConfigProvider) LocalMergeSuperSetComputationModule(com.google.gerrit.server.submit.LocalMergeSuperSetComputation.LocalMergeSuperSetComputationModule) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) AllChangesIndexer(com.google.gerrit.server.index.change.AllChangesIndexer) GarbageCollection(com.google.gerrit.server.git.GarbageCollection) AllAccountsIndexer(com.google.gerrit.server.index.account.AllAccountsIndexer) PluginApiModule(com.google.gerrit.server.api.PluginApiModule) GerritInstanceNameModule(com.google.gerrit.server.config.GerritInstanceNameModule) ServerInformation(com.google.gerrit.extensions.systemstatus.ServerInformation) OAuthRestModule(com.google.gerrit.httpd.auth.restapi.OAuthRestModule) GpgModule(com.google.gerrit.gpg.GpgModule) GerritApiModule(com.google.gerrit.server.api.GerritApiModule) IndexType(com.google.gerrit.index.IndexType) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) Provides(com.google.inject.Provides) DefaultUrlFormatterModule(com.google.gerrit.server.config.DefaultUrlFormatter.DefaultUrlFormatterModule) AbstractModule(com.google.inject.AbstractModule) CanonicalWebUrlModule(com.google.gerrit.server.config.CanonicalWebUrlModule) FileBasedGlobalPluginConfigProvider(com.google.gerrit.server.config.FileBasedGlobalPluginConfigProvider) AllUsersNameProvider(com.google.gerrit.server.config.AllUsersNameProvider) CanonicalWebUrlProvider(com.google.gerrit.server.config.CanonicalWebUrlProvider) GerritPersonIdentProvider(com.google.gerrit.server.GerritPersonIdentProvider) GlobalPluginConfigProvider(com.google.gerrit.server.config.GlobalPluginConfigProvider) AllProjectsNameProvider(com.google.gerrit.server.config.AllProjectsNameProvider) GerritServerIdProvider(com.google.gerrit.server.config.GerritServerIdProvider) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) TrackingFootersProvider(com.google.gerrit.server.config.TrackingFootersProvider) FileBasedAllProjectsConfigProvider(com.google.gerrit.server.config.FileBasedAllProjectsConfigProvider) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Provider(com.google.inject.Provider) DefaultMemoryCacheModule(com.google.gerrit.server.cache.mem.DefaultMemoryCacheModule) H2CacheModule(com.google.gerrit.server.cache.h2.H2CacheModule) AllGroupsIndexer(com.google.gerrit.server.index.group.AllGroupsIndexer) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) MoreExecutors.newDirectExecutorService(com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService) ExecutorService(java.util.concurrent.ExecutorService) AuthModule(com.google.gerrit.auth.AuthModule) GerritInstanceIdModule(com.google.gerrit.server.config.GerritInstanceIdModule) SubscriptionGraphModule(com.google.gerrit.server.submit.SubscriptionGraph.SubscriptionGraphModule) PluginUser(com.google.gerrit.server.PluginUser)

Aggregations

FakeEmailSenderModule (com.google.gerrit.testing.FakeEmailSender.FakeEmailSenderModule)2 AbstractModule (com.google.inject.AbstractModule)2 Ticker (com.google.common.base.Ticker)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors.newDirectExecutorService (com.google.common.util.concurrent.MoreExecutors.newDirectExecutorService)1 TestTicker (com.google.gerrit.acceptance.AbstractDaemonTest.TestTicker)1 FakeGroupAuditServiceModule (com.google.gerrit.acceptance.FakeGroupAuditService.FakeGroupAuditServiceModule)1 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)1 AuthModule (com.google.gerrit.auth.AuthModule)1 ServerInformation (com.google.gerrit.extensions.systemstatus.ServerInformation)1 GpgModule (com.google.gerrit.gpg.GpgModule)1 OAuthRestModule (com.google.gerrit.httpd.auth.restapi.OAuthRestModule)1 IndexType (com.google.gerrit.index.IndexType)1 DisabledMetricMaker (com.google.gerrit.metrics.DisabledMetricMaker)1 MetricMaker (com.google.gerrit.metrics.MetricMaker)1 Daemon (com.google.gerrit.pgm.Daemon)1 GerritPersonIdentProvider (com.google.gerrit.server.GerritPersonIdentProvider)1 PluginUser (com.google.gerrit.server.PluginUser)1 GerritApiModule (com.google.gerrit.server.api.GerritApiModule)1 PluginApiModule (com.google.gerrit.server.api.PluginApiModule)1