Skip to content

Commit 04494b5

Browse files
committed
Add tests for Issue #3473
1 parent 98d988c commit 04494b5

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

fdb-relational-jdbc/src/test/java/com/apple/foundationdb/relational/jdbc/JDBCAutoCommitTest.java

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void tearDown() throws Exception {
6969
* Run a test with the default (auto-commit on) for sanity.
7070
*/
7171
@Test
72-
void autoCommitOn() throws SQLException, IOException {
72+
void autoCommitOn() throws SQLException {
7373
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
7474
try (RelationalStatement statement = connection.createStatement()) {
7575
insertOneRow(statement);
@@ -80,6 +80,65 @@ void autoCommitOn() throws SQLException, IOException {
8080
}
8181
}
8282

83+
@Test
84+
void autoCommitWithNoTransactionInBetween() throws SQLException {
85+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
86+
connection.setAutoCommit(false);
87+
connection.setAutoCommit(true);
88+
}
89+
}
90+
91+
@Test
92+
void autoCommitStayOn() throws SQLException {
93+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
94+
connection.setAutoCommit(true);
95+
}
96+
}
97+
98+
@Test
99+
void autoCommitStayOff() throws SQLException {
100+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
101+
connection.setAutoCommit(false);
102+
connection.setAutoCommit(false);
103+
}
104+
}
105+
106+
@Test
107+
void commitEnableAutoCommit() throws SQLException {
108+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
109+
connection.setAutoCommit(false);
110+
111+
try (RelationalStatement statement = connection.createStatement()) {
112+
insertOneRow(statement);
113+
}
114+
connection.commit();
115+
connection.setAutoCommit(true);
116+
try (RelationalStatement statement = connection.createStatement()) {
117+
RelationalResultSet resultSet = statement.executeQuery("SELECT * FROM test_table");
118+
assertNextResult(resultSet, 100, "one hundred");
119+
assertNoNextResult(resultSet);
120+
}
121+
}
122+
}
123+
124+
@Test
125+
void rollbackThenEnableAutoCommit() throws SQLException {
126+
try (RelationalConnection connection = DriverManager.getConnection(getTestDbUri()).unwrap(RelationalConnection.class)) {
127+
connection.setAutoCommit(false);
128+
129+
try (RelationalStatement statement = connection.createStatement()) {
130+
insertOneRow(statement);
131+
}
132+
connection.rollback();
133+
connection.setAutoCommit(true);
134+
try (RelationalStatement statement = connection.createStatement()) {
135+
RelationalResultSet resultSet = statement.executeQuery("SELECT * FROM test_table");
136+
assertNoNextResult(resultSet);
137+
assertNoNextResult(resultSet);
138+
}
139+
}
140+
}
141+
83142
/**
84143
* Run a test with commit and then read.
85144
*/

0 commit comments

Comments
 (0)