Skip to content

Commit

Permalink
fix: iterate over async result set in sync (#416)
Browse files Browse the repository at this point in the history
Iterating over an AsyncResultSet using a standard while (rs.next()) loop
would fail after the last row was consumed.
  • Loading branch information
olavloite committed Sep 9, 2020
1 parent af95630 commit 45d8419
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Expand Up @@ -559,7 +559,7 @@ public boolean next() throws SpannerException {
this.state = State.SYNC;
}
boolean res = delegateResultSet.next();
currentRow = delegateResultSet.getCurrentRowAsStruct();
currentRow = res ? delegateResultSet.getCurrentRowAsStruct() : null;
return res;
}

Expand Down
Expand Up @@ -225,6 +225,19 @@ public CallbackResponse cursorReady(AsyncResultSet resultSet) {
assertThat(rowCount.get()).isEqualTo(1);
}

@Test
public void singleUseAsyncWithoutCallback() throws Exception {
DatabaseClient client =
spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
int rowCount = 0;
try (AsyncResultSet rs = client.singleUse().executeQueryAsync(SELECT1)) {
while (rs.next()) {
rowCount++;
}
}
assertThat(rowCount).isEqualTo(1);
}

@Test
public void singleUseBound() {
DatabaseClient client =
Expand Down

0 comments on commit 45d8419

Please sign in to comment.