Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit 6fddea2

Browse files
committed
address review comments
1 parent 81bda14 commit 6fddea2

2 files changed

Lines changed: 59 additions & 125 deletions

File tree

src/test/java/com/google/cloud/spanner/jdbc/ConcurrentTransactionOnEmulatorTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ public static void startEmulator() {
5757
new GenericContainer<>(
5858
DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator:latest"))
5959
.withExposedPorts(9010)
60-
.waitingFor(Wait.forListeningPorts(9010));
60+
.waitingFor(Wait.forLogMessage(".*gRPC server listening at.*\\n", 1));
6161
emulator.start();
62-
try {
63-
Thread.sleep(1500); // Give gRPC server time to fully initialize
64-
} catch (InterruptedException e) {
65-
Thread.currentThread().interrupt();
66-
}
6762
properties = new Properties();
6863
properties.setProperty("autoConfigEmulator", "true");
6964
properties.setProperty(

src/test/java/com/google/cloud/spanner/jdbc/JdbcResultSetTest.java

Lines changed: 58 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -556,20 +556,14 @@ public void testGetBooleanIndexForString() throws SQLException {
556556

557557
@Test
558558
public void testGetBooleanIndexForDate() {
559-
try {
560-
subject.getBoolean(DATE_COLINDEX_NOTNULL);
561-
fail("missing expected SQLException");
562-
} catch (SQLException e) {
563-
assertTrue(e instanceof JdbcSqlException);
564-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
565-
}
566-
try {
567-
subject.getBoolean(DATE_COLINDEX_NULL);
568-
fail("missing expected SQLException");
569-
} catch (SQLException e) {
570-
assertTrue(e instanceof JdbcSqlException);
571-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
572-
}
559+
SQLException e =
560+
assertThrows(SQLException.class, () -> subject.getBoolean(DATE_COLINDEX_NOTNULL));
561+
assertTrue(e instanceof JdbcSqlException);
562+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
563+
564+
e = assertThrows(SQLException.class, () -> subject.getBoolean(DATE_COLINDEX_NULL));
565+
assertTrue(e instanceof JdbcSqlException);
566+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
573567
}
574568

575569
@Test
@@ -660,56 +654,34 @@ public void testGetIntegerTypesOnPgNumericNaN() throws SQLException {
660654
assertTrue(Double.isNaN(subject.getDouble(PG_NUMERIC_COLINDEX_NAN)));
661655
assertTrue(Float.isNaN(subject.getFloat(PG_NUMERIC_COLINDEX_NAN)));
662656
assertEquals("NaN", subject.getString(PG_NUMERIC_COLINDEX_NAN));
663-
try {
664-
subject.getByte(PG_NUMERIC_COLINDEX_NAN);
665-
fail("missing expected SQLException");
666-
} catch (SQLException e) {
667-
assertTrue(e instanceof JdbcSqlException);
668-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
669-
}
657+
SQLException e =
658+
assertThrows(SQLException.class, () -> subject.getByte(PG_NUMERIC_COLINDEX_NAN));
659+
assertTrue(e instanceof JdbcSqlException);
660+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
670661

671-
try {
672-
subject.getShort(PG_NUMERIC_COLINDEX_NAN);
673-
fail("missing expected SQLException");
674-
} catch (SQLException e) {
675-
assertTrue(e instanceof JdbcSqlException);
676-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
677-
}
662+
e = assertThrows(SQLException.class, () -> subject.getShort(PG_NUMERIC_COLINDEX_NAN));
663+
assertTrue(e instanceof JdbcSqlException);
664+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
678665

679-
try {
680-
subject.getInt(PG_NUMERIC_COLINDEX_NAN);
681-
fail("missing expected SQLException");
682-
} catch (SQLException e) {
683-
assertTrue(e instanceof JdbcSqlException);
684-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
685-
}
666+
e = assertThrows(SQLException.class, () -> subject.getInt(PG_NUMERIC_COLINDEX_NAN));
667+
assertTrue(e instanceof JdbcSqlException);
668+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
686669

687-
try {
688-
subject.getLong(PG_NUMERIC_COLINDEX_NAN);
689-
fail("missing expected SQLException");
690-
} catch (SQLException e) {
691-
assertTrue(e instanceof JdbcSqlException);
692-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
693-
}
670+
e = assertThrows(SQLException.class, () -> subject.getLong(PG_NUMERIC_COLINDEX_NAN));
671+
assertTrue(e instanceof JdbcSqlException);
672+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
694673

695-
try {
696-
subject.getBigDecimal(PG_NUMERIC_COLINDEX_NAN);
697-
fail("missing expected SQLException");
698-
} catch (SQLException e) {
699-
assertTrue(e instanceof JdbcSqlException);
700-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
701-
}
674+
e = assertThrows(SQLException.class, () -> subject.getBigDecimal(PG_NUMERIC_COLINDEX_NAN));
675+
assertTrue(e instanceof JdbcSqlException);
676+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
702677
}
703678

704679
@Test
705680
public void testGetLongIndexForString() {
706-
try {
707-
subject.getLong(STRING_COLINDEX_NOTNULL);
708-
fail("missing expected SQLException");
709-
} catch (SQLException e) {
710-
assertTrue(e instanceof JdbcSqlException);
711-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
712-
}
681+
SQLException e =
682+
assertThrows(SQLException.class, () -> subject.getLong(STRING_COLINDEX_NOTNULL));
683+
assertTrue(e instanceof JdbcSqlException);
684+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
713685
}
714686

715687
@Test
@@ -727,13 +699,10 @@ public void testGetLongIndexForNullString() throws SQLException {
727699

728700
@Test
729701
public void testGetLongIndexForTimestamp() {
730-
try {
731-
subject.getLong(TIMESTAMP_COLINDEX_NOTNULL);
732-
fail("missing expected SQLException");
733-
} catch (SQLException e) {
734-
assertTrue(e instanceof JdbcSqlException);
735-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
736-
}
702+
SQLException e =
703+
assertThrows(SQLException.class, () -> subject.getLong(TIMESTAMP_COLINDEX_NOTNULL));
704+
assertTrue(e instanceof JdbcSqlException);
705+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
737706
}
738707

739708
@Test
@@ -771,13 +740,10 @@ public void testGetDoubleIndexFromInt64() throws SQLException {
771740

772741
@Test
773742
public void testGetDoubleIndexFromTimestamp() {
774-
try {
775-
subject.getDouble(TIMESTAMP_COLINDEX_NULL);
776-
fail("missing expected SQLException");
777-
} catch (SQLException e) {
778-
assertTrue(e instanceof JdbcSqlException);
779-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
780-
}
743+
SQLException e =
744+
assertThrows(SQLException.class, () -> subject.getDouble(TIMESTAMP_COLINDEX_NULL));
745+
assertTrue(e instanceof JdbcSqlException);
746+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
781747
}
782748

783749
@SuppressWarnings("deprecation")
@@ -907,13 +873,9 @@ public void testGetDateIndexFromTimestamp() throws SQLException {
907873

908874
@Test
909875
public void testGetDateIndexFromInt64() {
910-
try {
911-
subject.getDate(LONG_COLINDEX_NOTNULL);
912-
fail("missing expected SQLException");
913-
} catch (SQLException e) {
914-
assertTrue(e instanceof JdbcSqlException);
915-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
916-
}
876+
SQLException e = assertThrows(SQLException.class, () -> subject.getDate(LONG_COLINDEX_NOTNULL));
877+
assertTrue(e instanceof JdbcSqlException);
878+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
917879
}
918880

919881
@Test
@@ -1334,13 +1296,9 @@ public void testGetNullByteIndex() throws SQLException {
13341296
assertTrue(subject.wasNull());
13351297
assertEquals(0, subject.getByte(STRING_COLINDEX_NULL));
13361298
assertTrue(subject.wasNull());
1337-
try {
1338-
subject.getByte(TIMESTAMP_COL_NULL);
1339-
fail("missing expected SQLException");
1340-
} catch (SQLException e) {
1341-
assertTrue(e instanceof JdbcSqlException);
1342-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1343-
}
1299+
SQLException e = assertThrows(SQLException.class, () -> subject.getByte(TIMESTAMP_COL_NULL));
1300+
assertTrue(e instanceof JdbcSqlException);
1301+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
13441302
}
13451303

13461304
@Test
@@ -1372,13 +1330,9 @@ public void testGetShortIndexFromBoolean() throws SQLException {
13721330

13731331
@Test
13741332
public void testGetShortIndexFromBytes() {
1375-
try {
1376-
subject.getShort(BYTES_COL_NULL);
1377-
fail("missing expected SQLException");
1378-
} catch (SQLException e) {
1379-
assertTrue(e instanceof JdbcSqlException);
1380-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1381-
}
1333+
SQLException e = assertThrows(SQLException.class, () -> subject.getShort(BYTES_COL_NULL));
1334+
assertTrue(e instanceof JdbcSqlException);
1335+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
13821336
}
13831337

13841338
@Test
@@ -1391,13 +1345,9 @@ public void testGetNullShortIndex() throws SQLException {
13911345
assertTrue(subject.wasNull());
13921346
assertEquals(0, subject.getShort(STRING_COLINDEX_NULL));
13931347
assertTrue(subject.wasNull());
1394-
try {
1395-
subject.getShort(TIMESTAMP_COL_NULL);
1396-
fail("missing expected SQLException");
1397-
} catch (SQLException e) {
1398-
assertTrue(e instanceof JdbcSqlException);
1399-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1400-
}
1348+
SQLException e = assertThrows(SQLException.class, () -> subject.getShort(TIMESTAMP_COL_NULL));
1349+
assertTrue(e instanceof JdbcSqlException);
1350+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
14011351
}
14021352

14031353
@Test
@@ -1430,13 +1380,9 @@ public void testGetIntIndexFromBoolean() throws SQLException {
14301380

14311381
@Test
14321382
public void testGetIntIndexFromTimestamp() {
1433-
try {
1434-
subject.getInt(TIMESTAMP_COL_NULL);
1435-
fail("missing expected SQLException");
1436-
} catch (SQLException e) {
1437-
assertTrue(e instanceof JdbcSqlException);
1438-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1439-
}
1383+
SQLException e = assertThrows(SQLException.class, () -> subject.getInt(TIMESTAMP_COL_NULL));
1384+
assertTrue(e instanceof JdbcSqlException);
1385+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
14401386
}
14411387

14421388
@Test
@@ -1449,13 +1395,9 @@ public void testGetNullIntIndex() throws SQLException {
14491395
assertTrue(subject.wasNull());
14501396
assertEquals(0, subject.getInt(STRING_COLINDEX_NULL));
14511397
assertTrue(subject.wasNull());
1452-
try {
1453-
subject.getInt(TIMESTAMP_COL_NULL);
1454-
fail("missing expected SQLException");
1455-
} catch (SQLException e) {
1456-
assertTrue(e instanceof JdbcSqlException);
1457-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1458-
}
1398+
SQLException e = assertThrows(SQLException.class, () -> subject.getInt(TIMESTAMP_COL_NULL));
1399+
assertTrue(e instanceof JdbcSqlException);
1400+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
14591401
}
14601402

14611403
@Test
@@ -1494,13 +1436,10 @@ public void testGetFloatIndexFromInt64() throws SQLException {
14941436

14951437
@Test
14961438
public void testGetFloatIndexFromTimestamp() {
1497-
try {
1498-
subject.getFloat(TIMESTAMP_COLINDEX_NULL);
1499-
fail("missing expected SQLException");
1500-
} catch (SQLException e) {
1501-
assertTrue(e instanceof JdbcSqlException);
1502-
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
1503-
}
1439+
SQLException e =
1440+
assertThrows(SQLException.class, () -> subject.getFloat(TIMESTAMP_COLINDEX_NULL));
1441+
assertTrue(e instanceof JdbcSqlException);
1442+
assertEquals(Code.INVALID_ARGUMENT, ((JdbcSqlException) e).getCode());
15041443
}
15051444

15061445
@Test

0 commit comments

Comments
 (0)