Skip to content

Commit

Permalink
#139 Test for fix with rollback() before LogicalLock unlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
rbygrave committed Oct 30, 2023
1 parent de2af00 commit 7eac694
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ public void run_when_fileSystemResources() {
runner.run();
}

@Test
public void run_when_error() throws SQLException {

DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDriver("org.h2.Driver");
dataSourceConfig.setUrl("jdbc:h2:mem:err.db");
dataSourceConfig.setUsername("sa");
dataSourceConfig.setPassword("");

DataSourcePool dataSource = DataSourceFactory.create("test", dataSourceConfig);

MigrationConfig config = createMigrationConfig();
config.setMigrationPath("dbmig_error");
MigrationRunner runner = new MigrationRunner(config);
try {
runner.run(dataSource);
} catch (Exception expected) {
try (Connection connection = dataSource.getConnection()) {
try (var pstmt = connection.prepareStatement("select count(*) from m1")) {
try (var resultSet = pstmt.executeQuery()) {
assertThat(resultSet.next()).isTrue();
int val = resultSet.getInt(1);
assertThat(val).isEqualTo(0);
}
} catch (SQLException ex) {
fail(ex);
}
}
}
}

@Test
public void run_when_suppliedConnection() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
create table m1 (id integer, acol varchar(20));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
insert into m1 (id, acol) values (1,'hi');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
not valid sql

0 comments on commit 7eac694

Please sign in to comment.