Skip to content

Commit f4f82fe

Browse files
committed
test: add more tests
1 parent 20c3f50 commit f4f82fe

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AbstractMockServerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public abstract class AbstractMockServerTest {
110110
.setMetadata(SINGLE_COL_INT64_RESULTSET_METADATA)
111111
.build();
112112
public static final com.google.spanner.v1.ResultSet UPDATE_RETURNING_RESULTSET =
113-
com.google.spanner.v1.ResultSet.newBuilder()
113+
ResultSet.newBuilder()
114114
.setStats(ResultSetStats.newBuilder().setRowCountExact(1))
115115
.setMetadata(
116116
ResultSetMetadata.newBuilder()
@@ -121,6 +121,10 @@ public abstract class AbstractMockServerTest {
121121
.setName("col")
122122
.setType(Type.newBuilder().setCodeValue(TypeCode.INT64_VALUE))
123123
.build())))
124+
.addRows(
125+
ListValue.newBuilder()
126+
.addValues(Value.newBuilder().setStringValue("1").build())
127+
.build())
124128
.build();
125129

126130
protected static final ResultSet SELECT1_RESULTSET =

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/AutoDmlBatchMockServerTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public void testDmlWithReturningAfterDml() {
9797
// DML with a THEN RETURN clause cannot be batched. This therefore flushes the batch and
9898
// executes the INSERT ... THEN RETURN statement as a separate ExecuteSqlRequest.
9999
try (ResultSet resultSet = connection.executeQuery(INSERT_RETURNING_STATEMENT)) {
100+
assertTrue(resultSet.next());
101+
assertEquals(1L, resultSet.getLong(0));
100102
assertFalse(resultSet.next());
101103
}
102104

@@ -123,6 +125,8 @@ public void testDmlWithReturningAfterDml_usingExecute() {
123125
StatementResult result = connection.execute(INSERT_RETURNING_STATEMENT);
124126
assertEquals(ResultType.RESULT_SET, result.getResultType());
125127
try (ResultSet resultSet = result.getResultSet()) {
128+
assertTrue(resultSet.next());
129+
assertEquals(1L, resultSet.getLong(0));
126130
assertFalse(resultSet.next());
127131
}
128132

google-cloud-spanner/src/test/java/com/google/cloud/spanner/connection/TransactionMockServerTest.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.google.cloud.spanner.SpannerException;
3232
import com.google.cloud.spanner.Statement;
3333
import com.google.cloud.spanner.connection.ITAbstractSpannerTest.ITConnection;
34+
import com.google.cloud.spanner.connection.StatementResult.ResultType;
3435
import com.google.spanner.v1.BeginTransactionRequest;
3536
import com.google.spanner.v1.CommitRequest;
3637
import com.google.spanner.v1.ExecuteBatchDmlRequest;
@@ -357,5 +358,45 @@ public long nanoTime() {
357358
}
358359

359360
@Test
360-
public void testTransactionTimeoutInAutoCommit() {}
361+
public void testCanUseAllMethodsWithInternalRetriesDisabled() {
362+
// Verify that all query/update methods work as expected when internal retries have been
363+
// disabled.
364+
try (Connection connection = createConnection()) {
365+
connection.setAutocommit(false);
366+
connection.setRetryAbortsInternally(false);
367+
368+
try (ResultSet result = connection.executeQuery(SELECT1_STATEMENT)) {
369+
assertTrue(result.next());
370+
assertEquals(1L, result.getLong(0));
371+
assertFalse(result.next());
372+
}
373+
assertEquals(1, connection.executeUpdate(INSERT_STATEMENT));
374+
try (ResultSet result = connection.executeQuery(INSERT_RETURNING_STATEMENT)) {
375+
assertTrue(result.next());
376+
assertEquals(1L, result.getLong(0));
377+
assertFalse(result.next());
378+
}
379+
380+
StatementResult statementResult = connection.execute(SELECT1_STATEMENT);
381+
assertEquals(ResultType.RESULT_SET, statementResult.getResultType());
382+
try (ResultSet result = statementResult.getResultSet()) {
383+
assertTrue(result.next());
384+
assertEquals(1L, result.getLong(0));
385+
assertFalse(result.next());
386+
}
387+
388+
statementResult = connection.execute(INSERT_STATEMENT);
389+
assertEquals(ResultType.UPDATE_COUNT, statementResult.getResultType());
390+
assertEquals(1L, statementResult.getUpdateCount().longValue());
391+
392+
statementResult = connection.execute(INSERT_RETURNING_STATEMENT);
393+
assertEquals(ResultType.RESULT_SET, statementResult.getResultType());
394+
try (ResultSet result = statementResult.getResultSet()) {
395+
assertTrue(result.next());
396+
assertEquals(1L, result.getLong(0));
397+
assertFalse(result.next());
398+
}
399+
connection.commit();
400+
}
401+
}
361402
}

0 commit comments

Comments
 (0)