Skip to content

Commit

Permalink
migration: Test migration failures
Browse files Browse the repository at this point in the history
  • Loading branch information
alvasw committed Nov 4, 2024
1 parent da6178d commit b397b76
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package bisq.evolution.migration.migrations;

public class MigrationFailedException extends RuntimeException {
public MigrationFailedException(String message) {
super(message);
}

public MigrationFailedException(Throwable cause) {
super(cause);
}
Expand Down
29 changes: 29 additions & 0 deletions evolution/src/test/java/bisq/evolution/migration/MigratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import bisq.common.application.ApplicationVersion;
import bisq.common.platform.Version;
import bisq.evolution.migration.migrations.Migration;
import bisq.evolution.migration.migrations.MigrationFailedException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -27,4 +30,30 @@ void migrationSuccess(@TempDir Path dataDir) throws IOException {
String readVersion = Files.readString(dataDir.resolve("version"));
assertThat(readVersion).isEqualTo(appVersion.toString());
}

@Test
void migrationFailure(@TempDir Path dataDir) throws IOException {
Path versionFilePath = dataDir.resolve("version");
Version dataDirVersion = new Version("2.1.0");
Files.writeString(versionFilePath, dataDirVersion.toString());

Version appVersion = ApplicationVersion.getVersion();
var migration = new Migration() {
@Override
public void run(Path dataDir) {
throw new MigrationFailedException("Migration failed.");
}

@Override
public Version getVersion() {
return new Version("2.1.1");
}
};

Migrator migrator = new Migrator(appVersion, dataDir, List.of(migration, migration));
migrator.migrate();

String readVersion = Files.readString(dataDir.resolve("version"));
assertThat(readVersion).isEqualTo(dataDirVersion.toString());
}
}

0 comments on commit b397b76

Please sign in to comment.