Skip to content
Draft
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",
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 @@ -218,6 +218,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 +229 to +233

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()");

}

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