Skip to content

Commit

Permalink
Resolves issue 7316, which features some intermittent database-relate…
Browse files Browse the repository at this point in the history
…d tests (#7317)

Signed-off-by: Laird Nelson <laird.nelson@oracle.com>
  • Loading branch information
ljnelson authored Aug 5, 2023
1 parent 771471e commit fac2c3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Oracle and/or its affiliates.
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,7 @@
import javax.sql.DataSource;

import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -40,12 +41,20 @@ private TestConditionallyCloseableConnection() {
@BeforeEach
final void initializeDataSource() throws SQLException {
final JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test");
ds.setURL("jdbc:h2:mem:testConditionallyCloseableConnection");
ds.setUser("sa");
ds.setPassword("sa");
this.ds = ds;
}

@AfterEach
final void closeDataSource() throws SQLException {
try (final Connection c = this.ds.getConnection();
final Statement s = c.createStatement();) {
s.execute("SHUTDOWN");
}
}

@SuppressWarnings("try")
@Test
final void testLegacyIsCloseable() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.sql.DataSource;

import org.h2.jdbcx.JdbcDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -41,12 +42,20 @@ private TestH2IsolationLevelCases() {
@BeforeEach
final void initializeDataSource() throws SQLException {
final JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;INIT=SET DB_CLOSE_DELAY=-1");
ds.setURL("jdbc:h2:mem:testH2IsolationLevelCases;INIT=SET DB_CLOSE_DELAY=-1");
ds.setUser("sa");
ds.setPassword("sa");
this.ds = ds;
}

@AfterEach
final void closeDataSource() throws SQLException {
try (final Connection c = this.ds.getConnection();
final Statement s = c.createStatement();) {
s.execute("SHUTDOWN");
}
}

@Test
final void testGeneratedKeysAreVisibleWithinATransactionWithReadCommittedIsolationLevel() throws SQLException {
try (final Connection c = this.ds.getConnection()) {
Expand Down

0 comments on commit fac2c3c

Please sign in to comment.