Recently we had a few breakages of running Gerrit in slave mode (e.g.
due to trying to access secondary indexes which don't exist on slaves).
These breakages were only noticed after user reports since we don't have
any integration tests for Gerrit slaves at all.
This change enables integration tests against Gerrit slaves. It is easy
to start the Gerrit daemon in slave mode but then the server is in
read-only mode and we can't create any test data using the Gerrit API.
To be able to test against a slave server which is populated with test
data we first start the daemon as master and then after the test data
has been created we restart the daemon in slave mode.
If the server is restarted in slave mode we must preserve the content
of the test site, the repositories and the database content.
Preserving the content of the test site is not a problem since the test
site folders are only deleted at the very end after executing all tests.
The git repositories and the database may exist only in memory and in
this case we must make sure that the same instances are used when the
daemon is restarted in slave mode.
As in-memory database we use H2 [1]. The contents of an in-memory H2
database are gone as soon as the last connection to the database is
closed. This is why we must ensure to keep a database connection open
when then server in master mode is shutdown and we intend to restart it
as slave.
When the server is restarted we must make sure to reopen SSH connections
and reinject members into the test class and into the project resettter.
Tests that want to run against a Gerrit slave can use the normal Gerrit
API to setup the test data and then use the 'restartAsGerritSlave'
method from AbstractDaemonTest to restart the daemon in slave mode. For
these tests it is required to use the @Sandboxed annotation so that they
get an own server instance. Restarting the common server instance as
slave would break other tests using this server.
As an example the SshCommandsIT test is extended to check the list of
available commands in master and slave mode. Also it executes all
available commands in both modes.
[1] http://www.h2database.com/html/features.html#in_memory_databases
Change-Id: I2856e04ffa9fe4aac63747d4fc463581f7a1a6d6
Signed-off-by: Edwin Kempin <ekempin@google.com>