|
18 | 18 | import tech.ydb.core.StatusCode; |
19 | 19 | import tech.ydb.core.UnexpectedResultException; |
20 | 20 | import tech.ydb.jdbc.context.YdbContext; |
| 21 | +import tech.ydb.jdbc.context.YdbExecutor; |
| 22 | +import tech.ydb.jdbc.exception.YdbConditionallyRetryableException; |
| 23 | +import tech.ydb.jdbc.exception.YdbRetryableException; |
21 | 24 | import tech.ydb.jdbc.impl.YdbTracerImpl; |
22 | 25 | import tech.ydb.jdbc.impl.helper.ExceptionAssert; |
23 | 26 | import tech.ydb.jdbc.impl.helper.JdbcConnectionExtention; |
@@ -153,6 +156,52 @@ public void commitedTxTest() throws SQLException { |
153 | 156 | } |
154 | 157 | } |
155 | 158 |
|
| 159 | + @Test |
| 160 | + public void executeDataQueryTest() throws SQLException { |
| 161 | + String url = jdbcURL.withArg("withTxValidationTable", "tx1_store").build(); |
| 162 | + try (Connection conn = DriverManager.getConnection(url)) { |
| 163 | + ErrorTxTracer tracer = YdbTracerImpl.use(new ErrorTxTracer()); |
| 164 | + // table was created automatically |
| 165 | + assertTxCount("tx1_store", 0); |
| 166 | + |
| 167 | + conn.setAutoCommit(true); |
| 168 | + try (Statement st = conn.createStatement()) { |
| 169 | + st.execute("DELETE FROM tx1_store"); |
| 170 | + |
| 171 | + tracer.throwErrorOn("<-- Status", Status.of(StatusCode.UNDETERMINED)); |
| 172 | + YdbConditionallyRetryableException e = Assertions.assertThrows(YdbConditionallyRetryableException.class, |
| 173 | + () -> st.execute("DELETE FROM tx1_store")); |
| 174 | + Assertions.assertEquals(Status.of(StatusCode.UNDETERMINED), e.getStatus()); |
| 175 | + |
| 176 | + tracer.throwErrorOn("<-- Status", Status.of(StatusCode.ABORTED)); |
| 177 | + YdbRetryableException e2 = Assertions.assertThrows(YdbRetryableException.class, |
| 178 | + () -> st.execute("DELETE FROM tx1_store")); |
| 179 | + Assertions.assertEquals(Status.of(StatusCode.ABORTED), e2.getStatus()); |
| 180 | + } |
| 181 | + |
| 182 | + |
| 183 | + conn.setAutoCommit(false); |
| 184 | + try (Statement st = conn.createStatement()) { |
| 185 | + YdbExecutor executor = st.unwrap(YdbStatement.class).getConnection().getExecutor(); |
| 186 | + st.execute("DELETE FROM tx1_store"); |
| 187 | + conn.commit(); |
| 188 | + |
| 189 | + tracer.throwErrorOn("<-- Status", Status.of(StatusCode.UNDETERMINED)); |
| 190 | + YdbRetryableException e = Assertions.assertThrows(YdbRetryableException.class, |
| 191 | + () -> st.execute("DELETE FROM tx1_store")); |
| 192 | + Assertions.assertEquals(StatusCode.ABORTED, e.getStatus().getCode()); |
| 193 | + Assertions.assertNotNull(e.getStatus().getCause()); |
| 194 | + |
| 195 | + tracer.throwErrorOn("<-- Status", Status.of(StatusCode.ABORTED)); |
| 196 | + YdbRetryableException e2 = Assertions.assertThrows(YdbRetryableException.class, |
| 197 | + () -> st.execute("DELETE FROM tx1_store")); |
| 198 | + Assertions.assertEquals(Status.of(StatusCode.ABORTED), e2.getStatus()); |
| 199 | + } |
| 200 | + } finally { |
| 201 | + jdbc.connection().createStatement().execute("DROP TABLE tx1_store"); |
| 202 | + } |
| 203 | + } |
| 204 | + |
156 | 205 | @Test |
157 | 206 | public void invalididTxTableTest() throws SQLException { |
158 | 207 | String url = jdbcURL.withArg("withTxValidationTable", "tx store").build(); |
|
0 commit comments