# Zero Downtime Backup Functionality Tests

## Rationale 

These tests serve to verify that restoring inconsistent snapshots yield the expected recovery behaviour. They are 
intended to warn about regressions. It is unlikely that these tests will catch restoration issues caused by new 
features.

## How do I run these tests? 

`mvn clean install -Pit.integrity`

## How does it work?

The tests are split into two stages: 

1. Setup 
    * Starts a Bitbucket instance with test data
    * Takes a filesystem and database snapshot *before* modifying the test data
    * Modifies test data 
    * Takes a filesystem and database snapshot

2. Assertions
    * Filesystem **ahead** of database assertions
    * Filesystem **behind** database assertions
    
For each of the assertion scenarios (ahead and behind) Bitbucket will need to be restarted. 

**Important:** you **must** write test cases for both scenarios. Every test case must have an "Ahead" and a "Behind" 
test. This also serves to document expected behaviour.
Note that you *may* need to change and/or add to the modifications the Setup tests make to the data to support and test
a new feature.
      
## What is a 'snapshot'?

A copy of the home directory.

These tests will run against a H2 database, so it is implicitly included in the filesystem snapshot.
After shutting down the Bitbucket instance in the setup step, the H2 files are switched to produce inconsistent FS<->DB 
state.

## Running with bitbucket:run to debug tests

1. Running disk ahead of database
mvn -Dpackaging.type=atlassian-plugin -Dproduct.version=4.8.0-SNAPSHOT -Dproduct.data.version=4.8.0-SNAPSHOT \
-Dproduct.data.path=func-test/integrity/setup/target/bitbucket-it-integrity-setup-4.8.0-SNAPSHOT-behind-snapshot.zip \
-Dxvfb.enable=false -Dintegrity.check=1 -Pit.integrity -Pit.integrity.home.ahead package bitbucket:run -pl :bitbucket-it-integrity-assertions

2. Running database ahead of disk
mvn -Dpackaging.type=atlassian-plugin -Dproduct.version=4.8.0-SNAPSHOT -Dproduct.data.version=4.8.0-SNAPSHOT \
-Dproduct.data.path=func-test/integrity/setup/target/bitbucket-it-integrity-setup-4.8.0-SNAPSHOT-ahead-snapshot.zip \
-Dxvfb.enable=false -Dintegrity.check=1 -Pit.integrity -Pit.integrity.database.ahead package bitbucket:run -pl :bitbucket-it-integrity-assertions
