Skip to content
Permalink
Browse files
fix: iterate over async result set in sync (#416)
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 45d8419250c904b2f785d6cc5abacf098e5781de
@@ -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;
}

@@ -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 =

0 comments on commit 45d8419

Please sign in to comment.