Skip to content
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

feat: add stream methods for Page #1425

Merged
merged 25 commits into from Apr 11, 2023
Merged

feat: add stream methods for Page #1425

merged 25 commits into from Apr 11, 2023

Conversation

JoeWang1127
Copy link
Collaborator

@JoeWang1127 JoeWang1127 commented Feb 27, 2023

Fixes #1426 ☕️

@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Feb 27, 2023
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Feb 27, 2023
@sonarcloud
Copy link

sonarcloud bot commented Feb 28, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@JoeWang1127 JoeWang1127 marked this pull request as ready for review February 28, 2023 15:25
@JoeWang1127 JoeWang1127 requested a review from a team as a code owner February 28, 2023 15:25
@JoeWang1127 JoeWang1127 added the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 28, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Feb 28, 2023
@JoeWang1127 JoeWang1127 marked this pull request as draft February 28, 2023 19:34
@JoeWang1127
Copy link
Collaborator Author

Convert to draft for adding integration tests.

@JoeWang1127 JoeWang1127 marked this pull request as ready for review March 6, 2023 15:30
@JoeWang1127 JoeWang1127 added the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 6, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Mar 6, 2023
@suztomo
Copy link
Member

suztomo commented Mar 6, 2023

Don't merge this yet. We want to control when to introduce this new feature.

@suztomo suztomo added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 6, 2023
@JoeWang1127
Copy link
Collaborator Author

I'll merge main branch into this branch when it's ready to merge.

@sonarcloud
Copy link

sonarcloud bot commented Mar 6, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

Comment on lines +7 to +8
<className>com/google/api/gax/paging/Page</className>
<method>* stream*(*)</method>
Copy link
Member

Choose a reason for hiding this comment

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

It's strange that CLIRR is complaining the change. Adding default method in interface shouldn't cause a breaking changes.

Copy link
Member

@suztomo suztomo Mar 24, 2023

Choose a reason for hiding this comment

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

@JoeWang1127 Just in case, would you build this gax-java locally (with -SNAPSHOT version) and try to use in java-storage to see anything breaks? You ran some storage samples (https://github.com/JoeWang1127/storage-demo) that you used to understand the request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In Specifying ignored differences of Clirr Maven Plugin doc, 7012 has the following definition:

7012 (Method Added to Interface): className, method

So adding a method to interface, default or not, is a breaking change to this rule.

Also, there's 7013:

7013 (Abstract Method Added to Class): className, method

which is not complain.

Copy link
Contributor

Choose a reason for hiding this comment

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

Clirr isn't aware of java 8 default methods. It is looking at the bytecode from the perspective of java7 binary compatibility. When adding a default method it is safe to specify an ignore rule.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@BenWhitehead Thanks for the clarification.

@JoeWang1127
Copy link
Collaborator Author

@suztomo I've verified the change in the demo project (on branch use-stream).

@JoeWang1127 JoeWang1127 changed the title feat: add stream methods feat: add stream methods for Page Mar 24, 2023
@suztomo
Copy link
Member

suztomo commented Mar 24, 2023

Thank you.

* fetched whenever the elements of any particular page are exhausted.
*/
default Stream<ResourceT> streamAll() {
return StreamSupport.stream(iterateAll().spliterator(), false);
Copy link
Member

Choose a reason for hiding this comment

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

@BenWhitehead Would you elaborate what's not ideal? Parallel Stream.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is great for a first step of getting it on the api and saving our customers from having to do the same hoop jumping.

In the case of future improvements, right now this approach will not allow of parallel processing the same way a natively parallel friendly stream would. In all actuality, Page isn't fully parallelizable due to the fact that each page contains the nextPageToken necessary in order to fetch the next page. But, Page could be more parallel friendly where processing of the actual resources can happen on a thread separate from the thread performing the actual get.

Copy link
Member

@suztomo suztomo Mar 29, 2023

Choose a reason for hiding this comment

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

@JoeWang1127 Do you have question or comment about parallelism? (I don't think of an implementation as of now and don't think we need to implement it right now)

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, parallelism does not need to block this PR and can be an additional improvement in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@suztomo I'm not understand about the separate thread in Ben's comment:

Page could be more parallel friendly where processing of the actual resources can happen on a thread separate from the thread performing the actual get.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the reference.

I don't have a question about it.

@suztomo suztomo removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Apr 11, 2023
@@ -133,6 +133,54 @@ public void pagedByPage() {
Truth.assertThat(requestCapture.getAllValues()).containsExactly(0, 2, 4).inOrder();
}

@Test
public void streamedByPage() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we update the test names based on the best practices and a recent TotT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@sonarcloud
Copy link

sonarcloud bot commented Apr 11, 2023

[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@sonarcloud
Copy link

sonarcloud bot commented Apr 11, 2023

[java_showcase_integration_tests] SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@sonarcloud
Copy link

sonarcloud bot commented Apr 11, 2023

[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@JoeWang1127 JoeWang1127 merged commit cf0e01a into main Apr 11, 2023
18 of 19 checks passed
@JoeWang1127 JoeWang1127 deleted the feat/add-stream-methods branch April 11, 2023 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page do not easily support Java Streams
4 participants