FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

chore: add BidiUploadStreamingStream by BenWhitehead · Pull Request #3223 · googleapis/java-storage · GitHub

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (9) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ abstract class BidiUploadState {
// seal this class to extension
private BidiUploadState() {}

@VisibleForTesting
BidiUploadState(String testName) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Seems odd to need a visible-for-testing constructor of an abstract class, but presumably it'll make sense further down.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is here to facilitate validating some of the behavioral interactions from the BidiStream to the State where getting into a specific state would otherwise be difficult with the actual concrete implementation.

For example, in this test

void updateFromRedirect(@NonNull BidiWriteObjectRedirectedError r) {
assertThat(beforeRedirectCalled.get()).isTrue();
assertThat(r).isEqualTo(redirect);
updateFromRedirectCalled.set(true);
}
we are verifying that the redirect is routed to the state by the response observer, whereas doing that same validation with the concrete class would require more involved setup and validation.

// some runtime enforcement that this constructor is only called from a test
// if we had java9+ we could seal this all the way without this hack
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
boolean isJunitTest =
Arrays.stream(stackTrace).anyMatch(ste -> ste.getClassName().startsWith("org.junit"));

checkState(isJunitTest, "not a junit test", testName);
}

protected final StorageException err(
UploadFailureScenario scenario, BidiWriteObjectResponse response) {
BidiWriteObjectRequest t = peekLast();
Expand Down
Loading
Loading

Back | FazBrowse Home | New Git URL