Skip to content

Commit 7eac694

Browse files
committed
#139 Test for fix with rollback() before LogicalLock unlock()
1 parent de2af00 commit 7eac694

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

ebean-migration/src/test/java/io/ebean/migration/MigrationRunnerTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,37 @@ public void run_when_fileSystemResources() {
5656
runner.run();
5757
}
5858

59+
@Test
60+
public void run_when_error() throws SQLException {
61+
62+
DataSourceConfig dataSourceConfig = new DataSourceConfig();
63+
dataSourceConfig.setDriver("org.h2.Driver");
64+
dataSourceConfig.setUrl("jdbc:h2:mem:err.db");
65+
dataSourceConfig.setUsername("sa");
66+
dataSourceConfig.setPassword("");
67+
68+
DataSourcePool dataSource = DataSourceFactory.create("test", dataSourceConfig);
69+
70+
MigrationConfig config = createMigrationConfig();
71+
config.setMigrationPath("dbmig_error");
72+
MigrationRunner runner = new MigrationRunner(config);
73+
try {
74+
runner.run(dataSource);
75+
} catch (Exception expected) {
76+
try (Connection connection = dataSource.getConnection()) {
77+
try (var pstmt = connection.prepareStatement("select count(*) from m1")) {
78+
try (var resultSet = pstmt.executeQuery()) {
79+
assertThat(resultSet.next()).isTrue();
80+
int val = resultSet.getInt(1);
81+
assertThat(val).isEqualTo(0);
82+
}
83+
} catch (SQLException ex) {
84+
fail(ex);
85+
}
86+
}
87+
}
88+
}
89+
5990
@Test
6091
public void run_when_suppliedConnection() {
6192

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
create table m1 (id integer, acol varchar(20));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
insert into m1 (id, acol) values (1,'hi');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
not valid sql

0 commit comments

Comments
 (0)