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

chore: refactor Spring Integration Pub/Sub Sample tests to use unique resources #2085

Merged
merged 11 commits into from
Aug 4, 2023

Conversation

mpeddada1
Copy link
Contributor

In preparation for #2007.
This PR refactors the spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-sample sample.

@mpeddada1 mpeddada1 marked this pull request as ready for review July 31, 2023 13:56
@mpeddada1 mpeddada1 requested a review from a team as a code owner July 31, 2023 13:56
Copy link
Member

@meltsufin meltsufin left a comment

Choose a reason for hiding this comment

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

I'm just wondering if reconfiguring the unique resources can be done through application.properties.

@@ -46,11 +47,16 @@ public static void main(String[] args) {
SpringApplication.run(PollingReceiverApplication.class, args);
}

@Bean
public String subscription() {
return "exampleSubscription";
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered just using a property and the @Value annotation to inject it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a nice idea. Tried this out in 919c081. However, the problem with using @Value and ${random.uuid} in application.properties is that the value doesn't stay consistent and the random uuid get regenerated every time the @Value annotation is used. In our particular case, the subscriptionName is subscription-name-51bb5af5-354b-4b03-9aa9-297b31b30b88 in the TestConfiguration class and subscription-name-12f7f591-7955-4453-98b3-2f91372c1ef6 in the PollerReceiverApplication, therefore resulting our test failing with the RESOURCE_NOT_FOUND error.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense, but can you just use @Value once for subscriptionName?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, tested with running integration test and sample locally.

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking more along these lines: #2103

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah thank you! Sorry, I thought we wanted to avoid using a bean all together. The example really helped! Made the change.

Comment on lines 35 to 39
private static final String TEST_TOPIC =
String.format("pubsub-spring-integration-sample-receiver-exampleTopic-%s", UUID.randomUUID());
private static final String TEST_SUBSCRIPTION =
String.format(
"pubsub-spring-integration-sample-receiver-exampleSubscription-%s", UUID.randomUUID());
Copy link
Member

Choose a reason for hiding this comment

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

Should these also be using application.properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, thanks! Applied for other samples as well.

@sonarcloud
Copy link

sonarcloud bot commented Aug 4, 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

No Coverage information No Coverage information
No Duplication information No Duplication information

@mpeddada1 mpeddada1 merged commit cf13a1c into main Aug 4, 2023
29 checks passed
@mpeddada1 mpeddada1 deleted the pubsub-integration-parallel branch August 4, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants