-
Notifications
You must be signed in to change notification settings - Fork 43
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: added regional endpoint sample for datastore #1043
base: main
Are you sure you want to change the base?
Conversation
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
samples/snippets/src/main/java/com/example/datastore/QuickstartSample.java
Outdated
Show resolved
Hide resolved
samples/snippets/src/test/java/com/example/datastore/RegionalEndpointIT.java
Outdated
Show resolved
Hide resolved
samples/snippets/src/test/java/com/example/datastore/RegionalEndpointIT.java
Outdated
Show resolved
Hide resolved
samples/snippets/src/main/java/com/example/datastore/RegionalEndpoint.java
Outdated
Show resolved
Hide resolved
|
||
public Datastore createClient() throws Exception { | ||
// Instantiates a client | ||
// [START datastore_regional_endpoint] |
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.
nit: current best practice is to include import
statements and the sample class inside the region tags.
See:
https://googlecloudplatform.github.io/samples-style-guide/#region-tags
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.
|
||
@After | ||
public void tearDown() { | ||
System.setOut(null); |
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.
issue: Remove this. If you use the SystemsOutRule
, you don't need to change or restore what goes pipes to stdout.
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.
// Saves the entity | ||
datastoreWithEndpoint.put(task); | ||
|
||
System.out.printf("Saved %s: %s%n", task.getKey().getName(), task.getString("description")); |
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.
nit: Remove print statements. Tests are most commonly run in a CI/CD environment where output is written to logs.
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.
|
||
System.out.printf("Retrieved %s: %s%n", taskKey.getName(), retrieved.getString("description")); | ||
|
||
systemsOutRule.assertContains("Saved sampletask1: Buy milk"); |
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.
issue: it looks like this test is upserting an entity and then querying the Datastore for the same entity. You don't need to do a string comparison here. Instead just compare the Entity
you upsert to the Entity
you receive.
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.
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.
PTAL
- Also, if I'm a listed reviewer and I haven't responded in a few days, feel free to ping me.
// The kind for the new entity | ||
String kind = "Task"; | ||
// The name/ID for the new entity | ||
String name = "sampletask1"; |
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.
These are created in a common project, and many of these tests can be run at least 4x simultaneously. You should strongly consider using a UUID as name, possibly with a common prefix to tell you which test created, but failed before deleting the object.
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.
Updated to an identifiable ID. Thank you.
Use an identifiable name for the test entity.
d610131
to
dc41325
Compare
// The kind for the new entity | ||
String kind = "Task"; | ||
// The name/ID for the new entity | ||
String name = "regionalEndpointClient50720906"; |
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.
Not quite what I had in mind. See https://docs.oracle.com/javase/8/docs/api/java/util/UUID.html
You probably want to create one once and use it in both the testRegionalEndpoint()
and deleteTestEntity()
methods.
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 for explaining. Updated to use UUID. Does a UUID.randomUUID() make sense here?
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
@telpirion are there any other changes pending or can this PR be merged? |
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> ☕️
If you write sample code, please follow the samples format.