Skip to content

test: cleanup AsyncResultSetImplTest #3696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 18, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void tryNextNotAllowed() {
new AsyncResultSetImpl(
mockedProvider, mock(ResultSet.class), AsyncResultSetImpl.DEFAULT_BUFFER_SIZE)) {
rs.setCallback(mock(Executor.class), mock(ReadyCallback.class));
IllegalStateException e = assertThrows(IllegalStateException.class, () -> rs.tryNext());
IllegalStateException e = assertThrows(IllegalStateException.class, rs::tryNext);
assertThat(e.getMessage()).contains("tryNext may only be called from a DataReady callback.");
}
}
Expand Down Expand Up @@ -152,7 +152,7 @@ public void toListAsync() throws InterruptedException, ExecutionException {
}

@Test
public void toListAsyncPropagatesError() throws InterruptedException {
public void toListAsyncPropagatesError() {
ExecutorService executor = Executors.newFixedThreadPool(1);
ResultSet delegate = mock(ResultSet.class);
when(delegate.next())
Expand Down Expand Up @@ -326,10 +326,7 @@ public void testCallbackIsNotCalledWhilePaused() throws InterruptedException, Ex
@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
row++;
if (row > simulatedRows) {
return false;
}
return true;
return row <= simulatedRows;
}
});
when(delegate.getCurrentRowAsStruct()).thenReturn(mock(Struct.class));
Expand All @@ -345,17 +342,17 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
assertFalse(paused.get());
callbackCounter.incrementAndGet();
try {
while (true) {
switch (resultSet.tryNext()) {
case OK:
paused.set(true);
queue.put(new Object());
return CallbackResponse.PAUSE;
case DONE:
return CallbackResponse.DONE;
case NOT_READY:
return CallbackResponse.CONTINUE;
}
switch (resultSet.tryNext()) {
case OK:
paused.set(true);
queue.put(new Object());
return CallbackResponse.PAUSE;
case DONE:
return CallbackResponse.DONE;
case NOT_READY:
return CallbackResponse.CONTINUE;
default:
throw new IllegalStateException();
}
} catch (InterruptedException e) {
throw SpannerExceptionFactory.propagateInterrupt(e);
Expand Down Expand Up @@ -384,9 +381,8 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
}

@Test
public void testCallbackIsNotCalledWhilePausedAndCanceled()
throws InterruptedException, ExecutionException {
Executor executor = Executors.newSingleThreadExecutor();
public void testCallbackIsNotCalledWhilePausedAndCanceled() {
ExecutorService executor = Executors.newSingleThreadExecutor();
StreamingResultSet delegate = mock(StreamingResultSet.class);

final AtomicInteger callbackCounter = new AtomicInteger();
Expand Down Expand Up @@ -414,6 +410,8 @@ public void testCallbackIsNotCalledWhilePausedAndCanceled()
SpannerException exception = assertThrows(SpannerException.class, () -> get(callbackResult));
assertEquals(ErrorCode.CANCELLED, exception.getErrorCode());
assertEquals(1, callbackCounter.get());
} finally {
executor.shutdown();
}
}

Expand Down
Loading