This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 693
Test support module #2357
Draft
dmitry-s
wants to merge
24
commits into
main
Choose a base branch
from
spanner-emulator
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Test support module #2357
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
af58b0c
GcpEmulator parent class
dmitry-s 616fd6c
create GcpEmulator parent class
dmitry-s c97d2a5
run all necessary setup, working test
elefeint e760570
refactored to allow killing arbitrary commands
elefeint ddd4fb7
refactor to be independent from junit and spring
elefeint 6e9f411
break travis config with a TODO
elefeint 2a51055
rename test module
elefeint 2ac9f78
fixed incorrect default project ID making it into spanner object
elefeint 9f848dc
unbreak travis
elefeint 4a80876
PR comments
dmitry-s ef720e0
add docs and clean up the code
dmitry-s fe11788
sonar feedback
elefeint 7b119e7
Massive refactoring with Dmitry and Elena
meltsufin 8af2f8a
add gating properties and improve docs
dmitry-s 9d0f694
add tests
dmitry-s d043c0e
address sonarqube issues
dmitry-s 946914a
address sonarqube issues
dmitry-s df4c69c
Apply suggestions from code review
dmitry-s aa31b9d
PR comments
dmitry-s dab420e
Apply suggestions from code review
dmitry-s 4d9fd10
PR comments
dmitry-s e5e49b7
Merge branch 'spanner-emulator' of github.com:spring-cloud/spring-clo…
dmitry-s 36cbc62
PR comments
dmitry-s 10a1019
remove unused imports
dmitry-s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
== Emulators support | ||
Our tools simplify starting and stopping Cloud Pub/Sub and Cloud Spanner emulators when you test your applications locally. | ||
|
||
In order to use it, you need to add this dependency into your `pom.xml` file: | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-gcp-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
---- | ||
|
||
Also, you need to have `gcloud` CLI and the emulators installed and configured, as described later. | ||
|
||
=== JUnit 4 Class Rule | ||
The rule starts the emulator process before the tests run and stops it afterwards. | ||
You just need to add a rule into your test class to enable it. | ||
|
||
[source,java] | ||
---- | ||
import org.springframework.cloud.gcp.test.EmulatorRule; | ||
import org.springframework.cloud.gcp.test.pubsub.PubSubEmulator; | ||
|
||
public class PubSubTests { | ||
@ClassRule | ||
public static EmulatorRule emulator = new EmulatorRule(new PubSubEmulator()); | ||
|
||
//your tests | ||
} | ||
---- | ||
|
||
NOTE: The class rule doesn't work for `SpannerEmulator`. | ||
See <<Spring Configuration>> section instead. | ||
|
||
=== Utility class | ||
If you prefer controlling the emulator manually, you can use the `EmulatorDriver`. | ||
|
||
[source,java] | ||
---- | ||
EmulatorDriver emulatorDriver = new EmulatorDriver(new PubSubEmulator()); | ||
|
||
emulatorDriver.startEmulator(); | ||
|
||
//your code | ||
|
||
emulatorDriver.shutdownEmulator(); | ||
---- | ||
|
||
=== Cloud Pub/Sub Emulator | ||
In order to use our Cloud Pub/Sub Emulator helper tools, you would need to install the emulator first. | ||
Follow the https://cloud.google.com/pubsub/docs/emulator[installation instructions]. | ||
|
||
Use `new PubSubEmulator()` as an argument to `EmulatorDriver` and `EmulatorRule`. | ||
|
||
=== Cloud Spanner Emulator | ||
In order to use our Cloud Spanner Emulator helper tools, you would need to install the emulator first. | ||
Follow the https://cloud.google.com/spanner/docs/emulator[installation instructions]. | ||
Make sure you also create an https://cloud.google.com/spanner/docs/emulator#using_the_gcloud_cli_with_the_emulator[emulator configuration] and call it `emulator`. | ||
|
||
Use `new SpannerEmulator()` as an argument to `EmulatorDriver`. | ||
|
||
==== Spanner Emulator Spring Configuration | ||
If you are testing your Spring application, you can use our configuration class. | ||
It provides a bean of type `Spanner`, which starts the emulator before creating a client. | ||
This configuration also stops the emulator when the Spring context is shut down. | ||
|
||
In order to use it, you need to add the `SpannerEmulatorSpringConfiguration.class` to your configuration classes list in `@ContextConfiguration`. | ||
|
||
[source,java] | ||
---- | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.cloud.gcp.test.SpannerEmulatorSpringConfiguration; | ||
|
||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = {SpannerEmulatorSpringConfiguration.class, YourSpringConfiguration.class}) | ||
public class SpannerTemplateEmulatorTests { | ||
//your tests | ||
} | ||
---- |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
266 changes: 0 additions & 266 deletions
266
...nder/src/test/java/org/springframework/cloud/gcp/stream/binder/pubsub/PubSubEmulator.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 we mention the workaround of setting up a custom Spanner bean and setting its destroy method to ""?
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.
It looks like implementation details to me. @meltsufin what do you think?