11 files changed

+392
-320
lines changed
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public void setAsciiStream(int parameterIndex, InputStream value, int length)
169169
}
170170

171171
@Override
172+
@Deprecated
172173
public void setUnicodeStream(int parameterIndex, InputStream value, int length)
173174
throws SQLException {
174175
checkClosed();
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ public InputStream getAsciiStream(int columnIndex) throws SQLException {
215215
}
216216

217217
@Override
218+
@Deprecated
218219
public InputStream getUnicodeStream(int columnIndex) throws SQLException {
219220
checkClosedAndValidRow();
220221
return getInputStream(getString(columnIndex), StandardCharsets.UTF_16LE);
@@ -314,6 +315,7 @@ public InputStream getAsciiStream(String columnLabel) throws SQLException {
314315
}
315316

316317
@Override
318+
@Deprecated
317319
public InputStream getUnicodeStream(String columnLabel) throws SQLException {
318320
checkClosedAndValidRow();
319321
return getInputStream(getString(columnLabel), StandardCharsets.UTF_16LE);
@@ -406,12 +408,14 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
406408
}
407409

408410
@Override
411+
@Deprecated
409412
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
410413
checkClosedAndValidRow();
411414
return getBigDecimal(columnIndex, true, scale);
412415
}
413416

414417
@Override
418+
@Deprecated
415419
public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException {
416420
checkClosedAndValidRow();
417421
return getBigDecimal(spanner.getColumnIndex(columnLabel) + 1, true, scale);
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616

1717
package com.google.cloud.spanner.jdbc;
1818

19-
import static org.hamcrest.CoreMatchers.endsWith;
20-
import static org.hamcrest.CoreMatchers.equalTo;
21-
import static org.hamcrest.CoreMatchers.is;
22-
import static org.hamcrest.CoreMatchers.nullValue;
23-
import static org.hamcrest.MatcherAssert.assertThat;
19+
import static com.google.common.truth.Truth.assertThat;
2420
import static org.junit.Assert.fail;
2521

2622
import com.google.cloud.Timestamp;
@@ -53,9 +49,7 @@
5349
import java.util.List;
5450
import org.junit.AfterClass;
5551
import org.junit.BeforeClass;
56-
import org.junit.Rule;
5752
import org.junit.Test;
58-
import org.junit.rules.ExpectedException;
5953
import org.junit.runner.RunWith;
6054
import org.junit.runners.Parameterized;
6155
import org.junit.runners.Parameterized.Parameter;
@@ -110,8 +104,6 @@ public void retryFinished(
110104
@Parameter(0)
111105
public boolean retryAbortsInternally;
112106

113-
@Rule public ExpectedException expected = ExpectedException.none();
114-
115107
@Parameters(name = "retryAbortsInternally = {0}")
116108
public static Collection<Object[]> data() {
117109
List<Object[]> params = new ArrayList<>();
@@ -175,23 +167,25 @@ public void testAutocommitUpdateAborted() throws SQLException {
175167
try (java.sql.Connection connection = createConnection()) {
176168
mockSpanner.abortNextStatement();
177169
int updateCount = connection.createStatement().executeUpdate(UPDATE_STATEMENT.getSql());
178-
assertThat(updateCount, is(equalTo(UPDATE_COUNT)));
170+
assertThat(updateCount).isEqualTo(UPDATE_COUNT);
179171
}
180172
}
181173

182174
@Test
183175
public void testTransactionalUpdateAborted() throws SQLException {
184176
// Updates in transactional mode are automatically retried by default, but this can be switched
185177
// off.
186-
if (!retryAbortsInternally) {
187-
expected.expect(JdbcAbortedException.class);
188-
}
189178
try (java.sql.Connection connection = createConnection()) {
190179
connection.setAutoCommit(false);
191180
mockSpanner.abortNextStatement();
192181
int updateCount = connection.createStatement().executeUpdate(UPDATE_STATEMENT.getSql());
193-
assertThat(updateCount, is(equalTo(UPDATE_COUNT)));
194-
assertThat(getRetryCount(connection), is(equalTo(1)));
182+
if (!retryAbortsInternally) {
183+
fail("missing expected exception");
184+
}
185+
assertThat(updateCount).isEqualTo(UPDATE_COUNT);
186+
assertThat(getRetryCount(connection)).isEqualTo(1);
187+
} catch (JdbcAbortedException e) {
188+
assertThat(retryAbortsInternally).isFalse();
195189
}
196190
}
197191

@@ -203,25 +197,27 @@ public void testAutocommitBatchUpdateAborted() throws SQLException {
203197
statement.addBatch(UPDATE_STATEMENT.getSql());
204198
statement.addBatch(UPDATE_STATEMENT.getSql());
205199
int[] updateCounts = statement.executeBatch();
206-
assertThat(updateCounts, is(equalTo(new int[] {UPDATE_COUNT, UPDATE_COUNT})));
200+
assertThat(updateCounts).asList().containsExactly(UPDATE_COUNT, UPDATE_COUNT);
207201
}
208202
}
209203
}
210204

211205
@Test
212206
public void testTransactionalBatchUpdateAborted() throws SQLException {
213-
if (!retryAbortsInternally) {
214-
expected.expect(JdbcAbortedException.class);
215-
}
216207
try (java.sql.Connection connection = createConnection()) {
217208
connection.setAutoCommit(false);
218209
mockSpanner.abortNextStatement();
219210
try (java.sql.Statement statement = connection.createStatement()) {
220211
statement.addBatch(UPDATE_STATEMENT.getSql());
221212
statement.addBatch(UPDATE_STATEMENT.getSql());
222213
int[] updateCounts = statement.executeBatch();
223-
assertThat(updateCounts, is(equalTo(new int[] {UPDATE_COUNT, UPDATE_COUNT})));
224-
assertThat(getRetryCount(connection), is(equalTo(1)));
214+
if (!retryAbortsInternally) {
215+
fail("missing expected exception");
216+
}
217+
assertThat(updateCounts).asList().containsExactly(UPDATE_COUNT, UPDATE_COUNT);
218+
assertThat(getRetryCount(connection)).isEqualTo(1);
219+
} catch (JdbcAbortedException e) {
220+
assertThat(retryAbortsInternally).isFalse();
225221
}
226222
}
227223
}
@@ -233,38 +229,35 @@ public void testAutocommitSelectAborted() throws SQLException {
233229
mockSpanner.abortNextStatement();
234230
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
235231
while (rs.next()) {
236-
assertThat(rs.getLong(1), is(equalTo(1L)));
232+
assertThat(rs.getLong(1)).isEqualTo(1L);
237233
}
238234
}
239235
}
240236
}
241237

242238
@Test
243239
public void testTransactionalSelectAborted() throws SQLException {
244-
if (!retryAbortsInternally) {
245-
expected.expect(JdbcAbortedException.class);
246-
}
247240
try (java.sql.Connection connection = createConnection()) {
248241
connection.setAutoCommit(false);
249242
mockSpanner.abortNextStatement();
250243
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
251244
while (rs.next()) {
252-
assertThat(rs.getLong(1), is(equalTo(1L)));
245+
if (!retryAbortsInternally) {
246+
fail("missing expected exception");
247+
}
248+
assertThat(rs.getLong(1)).isEqualTo(1L);
253249
}
254250
}
255-
assertThat(getRetryCount(connection), is(equalTo(1)));
251+
assertThat(getRetryCount(connection)).isEqualTo(1);
252+
} catch (JdbcAbortedException e) {
253+
assertThat(retryAbortsInternally).isFalse();
256254
}
257255
}
258256

259257
@Test
260258
public void testTransactionalUpdateWithConcurrentModificationsAborted() throws SQLException {
261-
if (retryAbortsInternally) {
262-
// As the transaction does a random select, the retry will always see different data than the
263-
// original attempt.
264-
expected.expect(JdbcAbortedDueToConcurrentModificationException.class);
265-
} else {
266-
expected.expect(JdbcAbortedException.class);
267-
}
259+
// As the transaction does a random select, the retry will always see different data than the
260+
// original attempt.
268261
try (java.sql.Connection connection = createConnection()) {
269262
connection.setAutoCommit(false);
270263
// Set a random answer.
@@ -281,14 +274,15 @@ public void testTransactionalUpdateWithConcurrentModificationsAborted() throws S
281274
// This will abort and start an internal retry.
282275
connection.createStatement().executeUpdate(UPDATE_STATEMENT.getSql());
283276
fail("missing expected aborted exception");
277+
} catch (JdbcAbortedDueToConcurrentModificationException e) {
278+
assertThat(retryAbortsInternally).isTrue();
279+
} catch (JdbcAbortedException e) {
280+
assertThat(retryAbortsInternally).isFalse();
284281
}
285282
}
286283

287284
@Test
288285
public void testTransactionalUpdateWithErrorOnOriginalAndRetry() throws SQLException {
289-
if (!retryAbortsInternally) {
290-
expected.expect(JdbcAbortedException.class);
291-
}
292286
final String sql = "UPDATE SOMETHING SET OTHER=1";
293287
mockSpanner.putStatementResult(
294288
StatementResult.exception(
@@ -298,7 +292,7 @@ public void testTransactionalUpdateWithErrorOnOriginalAndRetry() throws SQLExcep
298292
connection.setAutoCommit(false);
299293
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
300294
while (rs.next()) {
301-
assertThat(rs.getLong(1), is(equalTo(1L)));
295+
assertThat(rs.getLong(1)).isEqualTo(1L);
302296
}
303297
}
304298
try {
@@ -309,16 +303,16 @@ public void testTransactionalUpdateWithErrorOnOriginalAndRetry() throws SQLExcep
309303
}
310304
mockSpanner.abortNextStatement();
311305
connection.commit();
306+
if (!retryAbortsInternally) {
307+
fail("missing expected exception");
308+
}
309+
} catch (JdbcAbortedException e) {
310+
assertThat(retryAbortsInternally).isFalse();
312311
}
313312
}
314313

315314
@Test
316315
public void testTransactionalUpdateWithErrorOnRetryAndNotOnOriginal() throws SQLException {
317-
if (retryAbortsInternally) {
318-
expected.expect(JdbcAbortedDueToConcurrentModificationException.class);
319-
} else {
320-
expected.expect(JdbcAbortedException.class);
321-
}
322316
final String sql = "UPDATE SOMETHING SET OTHER=1";
323317
try (java.sql.Connection connection = createConnection()) {
324318
connection.setAutoCommit(false);
@@ -335,20 +329,17 @@ public void testTransactionalUpdateWithErrorOnRetryAndNotOnOriginal() throws SQL
335329
connection.commit();
336330
fail("missing expected aborted exception");
337331
} catch (JdbcAbortedDueToConcurrentModificationException e) {
338-
assertThat(
339-
e.getDatabaseErrorDuringRetry().getErrorCode(), is(equalTo(ErrorCode.INVALID_ARGUMENT)));
340-
assertThat(e.getDatabaseErrorDuringRetry().getMessage(), endsWith("test"));
341-
throw e;
332+
assertThat(retryAbortsInternally).isTrue();
333+
assertThat(e.getDatabaseErrorDuringRetry().getErrorCode())
334+
.isEqualTo(ErrorCode.INVALID_ARGUMENT);
335+
assertThat(e.getDatabaseErrorDuringRetry().getMessage()).endsWith("test");
336+
} catch (JdbcAbortedException e) {
337+
assertThat(retryAbortsInternally).isFalse();
342338
}
343339
}
344340

345341
@Test
346342
public void testTransactionalUpdateWithErrorOnOriginalAndNotOnRetry() throws SQLException {
347-
if (retryAbortsInternally) {
348-
expected.expect(JdbcAbortedDueToConcurrentModificationException.class);
349-
} else {
350-
expected.expect(JdbcAbortedException.class);
351-
}
352343
final String sql = "UPDATE SOMETHING SET OTHER=1";
353344
mockSpanner.putStatementResult(
354345
StatementResult.exception(
@@ -358,7 +349,7 @@ public void testTransactionalUpdateWithErrorOnOriginalAndNotOnRetry() throws SQL
358349
connection.setAutoCommit(false);
359350
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
360351
while (rs.next()) {
361-
assertThat(rs.getLong(1), is(equalTo(1L)));
352+
assertThat(rs.getLong(1)).isEqualTo(1L);
362353
}
363354
}
364355
try {
@@ -373,8 +364,10 @@ public void testTransactionalUpdateWithErrorOnOriginalAndNotOnRetry() throws SQL
373364
connection.commit();
374365
fail("missing expected aborted exception");
375366
} catch (JdbcAbortedDueToConcurrentModificationException e) {
376-
assertThat(e.getDatabaseErrorDuringRetry(), is(nullValue()));
377-
throw e;
367+
assertThat(retryAbortsInternally).isTrue();
368+
assertThat(e.getDatabaseErrorDuringRetry()).isNull();
369+
} catch (JdbcAbortedException e) {
370+
assertThat(retryAbortsInternally).isFalse();
378371
}
379372
}
380373
}

0 commit comments

Comments
 (0)