Skip to content

Commit

Permalink
chore: condition tests that cast to int4
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Feb 21, 2024
1 parent 0d70347 commit 5e5131f
Showing 1 changed file with 63 additions and 24 deletions.
87 changes: 63 additions & 24 deletions src/test/java/com/google/cloud/spanner/pgadapter/ITJdbcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ public void testSelectWithParameters() throws SQLException {
statement.setBytes(++index, "test".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 3.14d);
statement.setInt(++index, 1);
// TODO: Remove when the emulator supports casting to int4
if (isSimpleMode && IntegrationTest.isRunningOnEmulator()) {
statement.setLong(++index, 1);
} else {
statement.setInt(++index, 1);
}
statement.setBigDecimal(++index, new BigDecimal("3.14"));
statement.setTimestamp(
++index, Timestamp.parseTimestamp("2022-01-27T17:51:30+01:00").toSqlTimestamp());
Expand Down Expand Up @@ -382,9 +387,12 @@ public void testSelectWithParameters() throws SQLException {
assertArrayEquals(
new String[] {"string1", null, "string2"},
(String[]) resultSet.getArray(++index).getArray());
assertArrayEquals(
new String[] {"{\"key\": \"value1\"}", null, "{\"key\": \"value2\"}"},
(String[]) resultSet.getArray(++index).getArray());
// TODO: Remove when the emulator supports casting to int4
if (!(isSimpleMode && IntegrationTest.isRunningOnEmulator())) {
assertArrayEquals(
new String[] {"{\"key\": \"value1\"}", null, "{\"key\": \"value2\"}"},
(String[]) resultSet.getArray(++index).getArray());
}

assertFalse(resultSet.next());
}
Expand Down Expand Up @@ -412,7 +420,12 @@ public void testInsertWithParameters() throws SQLException {
statement.setBytes(++index, "bytes_test".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 10.1);
statement.setInt(++index, 100);
// TODO: Remove when the emulator supports casting to int4
if (isSimpleMode && IntegrationTest.isRunningOnEmulator()) {
statement.setLong(++index, 100);
} else {
statement.setInt(++index, 100);
}
statement.setBigDecimal(++index, new BigDecimal("6.626"));
statement.setTimestamp(
++index, Timestamp.parseTimestamp("2022-02-11T13:45:00.123456+01:00").toSqlTimestamp());
Expand All @@ -438,7 +451,12 @@ public void testInsertWithParameters() throws SQLException {
}
statement.setArray(
++index, connection.createArrayOf("float8", new Double[] {3.14d, null, -99.8}));
statement.setArray(++index, connection.createArrayOf("int", new Integer[] {-1, null, -2}));
// TODO: Remove when the emulator supports casting to int4
statement.setArray(
++index,
connection.createArrayOf(
isSimpleMode && IntegrationTest.isRunningOnEmulator() ? "bigint" : "int",
new Integer[] {-1, null, -2}));
statement.setArray(
++index,
connection.createArrayOf(
Expand All @@ -461,15 +479,28 @@ public void testInsertWithParameters() throws SQLException {
statement.setArray(
++index,
connection.createArrayOf("varchar", new String[] {"string1", null, "string2"}));
statement.setArray(
++index,
connection.createArrayOf(
"jsonb",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
// TODO: Remove when the emulator supports casting to int4
if (!(isSimpleMode && IntegrationTest.isRunningOnEmulator())) {
statement.setArray(
++index,
connection.createArrayOf(
"jsonb",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
} else {
statement.setArray(
++index,
connection.createArrayOf(
"varchar",
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
}));
}

assertEquals(1, statement.executeUpdate());
}
Expand Down Expand Up @@ -545,13 +576,16 @@ public void testInsertWithParameters() throws SQLException {
assertArrayEquals(
new String[] {"string1", null, "string2"},
(String[]) resultSet.getArray(++index).getArray());
assertArrayEquals(
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
},
(String[]) resultSet.getArray(++index).getArray());
// TODO: Remove when the emulator supports casting to int4
if (!(isSimpleMode && IntegrationTest.isRunningOnEmulator())) {
assertArrayEquals(
new String[] {
"{\"key1\": \"value1\", \"key2\": \"value2\"}",
null,
"{\"key1\": \"value3\", \"key2\": \"value4\"}"
},
(String[]) resultSet.getArray(++index).getArray());
}

assertFalse(resultSet.next());
}
Expand Down Expand Up @@ -583,7 +617,12 @@ public void testUpdateWithParameters() throws SQLException {
statement.setBytes(++index, "updated".getBytes(StandardCharsets.UTF_8));
}
statement.setDouble(++index, 3.14d * 2d);
statement.setInt(++index, 2);
// TODO: Remove when the emulator supports casting to int4
if (isSimpleMode && IntegrationTest.isRunningOnEmulator()) {
statement.setLong(++index, 2);
} else {
statement.setInt(++index, 2);
}
statement.setBigDecimal(++index, new BigDecimal("10.0"));
// Note that PostgreSQL does not support nanosecond precision, so the JDBC driver therefore
// truncates this value before it is sent to PG.
Expand Down Expand Up @@ -727,7 +766,7 @@ public void testRelationNotFoundError() throws SQLException {
assertThrows(PSQLException.class, preparedStatement::executeQuery);
if (preferQueryMode.equals("simple")) {
assertEquals(
"ERROR: relation \"non_existing_table\" does not exist - Statement: 'select * from non_existing_table where id=1'",
"ERROR: relation \"non_existing_table\" does not exist - Statement: 'select * from non_existing_table where id=('1'::int8)'",
exception.getMessage());
} else {
assertEquals(
Expand Down

0 comments on commit 5e5131f

Please sign in to comment.