Skip to content
Open
Show file tree
Hide file tree
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 @@ -84,6 +84,10 @@ ApiFuture<ObjectReadSession> readSession(
req.getReadRangesList().isEmpty(),
"ranges included in the initial request are not supported");
checkArgument(fastOpenConfigs.size() <= 1, "at most one fast open read is supported");
checkArgument(
fastOpenConfigs.stream().allMatch(c -> c.getType() == ProjectionType.STREAM_READ),
"a fast open read must be asFutureBytes(), asFutureByteString() or asChannel(), but was %s",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Consider c != null && c.getType() == ProjectionType.STREAM_READ so a null element fails cleanly instead of throwing an NPE inside the lambda. Also, aligned with my naming comment on PR #14789, "an initial read must be..." might be clearer than "a fast open read..." when these precondition messages surface to external callers of Storage.blobReadSession.

fastOpenConfigs);
ObjectReadSessionState state = new ObjectReadSessionState(ctx, req);

ZeroCopyBidiStreamingCallable<BidiReadObjectRequest, BidiReadObjectResponse> callable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,24 @@ public void readSession_withMoreThanOneFastOpenConfig_isRejected() throws Except
assertThat(requestsReceived).isEmpty();
}

@Test
public void readSession_withASeekableChannelConfig_isRejected() throws Exception {
FakeStorage server = fakeServer(ImmutableMap.of());

try (FakeServer fakeServer = FakeServer.of(server);
Storage storage = fakeServer.getGrpcStorageOptions().getService()) {
StorageDataClient dataClient = maybeGetStorageDataClient(storage);

assertThrows(
IllegalArgumentException.class,
() ->
dataClient.readSession(
OPEN, CTX, ImmutableList.of(ReadProjectionConfigs.asSeekableChannel())));
Comment on lines +279 to +283

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When asserting that an exception is thrown, it is best practice to also verify the exception message. Since readSession has multiple checkArgument validations that throw IllegalArgumentException, asserting on the message ensures that the test fails for the expected reason rather than a different validation failure.

      IllegalArgumentException exception = assertThrows(
          IllegalArgumentException.class,
          () ->
              dataClient.readSession(
                  OPEN, CTX, ImmutableList.of(ReadProjectionConfigs.asSeekableChannel())));
      assertThat(exception)
          .hasMessageThat()
          .contains("a fast open read must be asFutureBytes(), asFutureByteString() or asChannel()");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: +1 to the gemini-code-assist comment — since readSession has multiple checkArgument checks throwing IllegalArgumentException, asserting on thrown.getMessage() ensures we hit the STREAM_READ check.

}

assertThat(requestsReceived).isEmpty();
}

/**
* A fake server that answers each request in {@code responses} and adds it to {@link
* #requestsReceived}. Any other request is answered with an error.
Expand Down
Loading