-
Notifications
You must be signed in to change notification settings - Fork 316
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
Conversation
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
This reverts commit 919c081.
...pubsub-sample-polling-receiver/src/test/java/com/example/PollingReceiverIntegrationTest.java
Show resolved
Hide resolved
This reverts commit 3b26b94.
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()); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Kudos, SonarCloud Quality Gate passed! |
In preparation for #2007.
This PR refactors the
spring-cloud-gcp-samples/spring-cloud-gcp-integration-pubsub-sample
sample.