use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule in project gerrit by GerritCodeReview.
the class SiteProgram method createDbInjector.
/**
* Provides database connectivity and site path.
*/
protected Injector createDbInjector(boolean enableMetrics) {
List<Module> modules = new ArrayList<>();
Module sitePathModule = new AbstractModule() {
@Override
protected void configure() {
bind(Path.class).annotatedWith(SitePath.class).toInstance(getSitePath());
bind(String.class).annotatedWith(SecureStoreClassName.class).toProvider(Providers.of(getConfiguredSecureStoreClass()));
}
};
modules.add(sitePathModule);
if (enableMetrics) {
modules.add(new DropWizardMetricMaker.ApiModule());
} else {
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(MetricMaker.class).to(DisabledMetricMaker.class);
}
});
}
modules.add(new LifecycleModule() {
@Override
protected void configure() {
listener().to(SystemReaderInstaller.class);
}
});
Module configModule = new GerritServerConfigModule();
modules.add(configModule);
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(GerritRuntime.class).toInstance(getGerritRuntime());
}
});
Injector cfgInjector = Guice.createInjector(sitePathModule, configModule);
modules.add(new SchemaModule());
modules.add(cfgInjector.getInstance(GitRepositoryManagerModule.class));
// The only implementation of experiments is available in all programs that can use
// gerrit.config
modules.add(new ConfigExperimentFeaturesModule());
try {
return Guice.createInjector(PRODUCTION, ModuleOverloader.override(modules, LibModuleLoader.loadModules(cfgInjector, LibModuleType.DB_MODULE_TYPE)));
} catch (CreationException ce) {
Message first = ce.getErrorMessages().iterator().next();
Throwable why = first.getCause();
StringBuilder buf = new StringBuilder();
if (why != null) {
buf.append(why.getMessage());
why = why.getCause();
} else {
buf.append(first.getMessage());
}
while (why != null) {
buf.append("\n caused by ");
buf.append(why.toString());
why = why.getCause();
}
throw die(buf.toString(), new RuntimeException("DbInjector failed", ce));
}
}
use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule 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);
}
use of com.google.gerrit.server.experiments.ConfigExperimentFeatures.ConfigExperimentFeaturesModule 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);
}
Aggregations