use of com.google.gerrit.acceptance.FakeGroupAuditService.FakeGroupAuditServiceModule 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);
}
Aggregations