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: added regional endpoint sample for datastore #1043

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

shweta345
Copy link

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> ☕️

If you write sample code, please follow the samples format.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Apr 10, 2023
@snippet-bot
Copy link

snippet-bot bot commented Apr 10, 2023

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@product-auto-label product-auto-label bot added api: datastore Issues related to the googleapis/java-datastore API. samples Issues that are directly related to samples. labels Apr 10, 2023
@kolea2 kolea2 added kokoro:force-run Add this label to force Kokoro to re-run the tests. and removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Apr 12, 2023
@kolea2 kolea2 added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Apr 12, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Apr 12, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Apr 12, 2023
@gcf-owl-bot gcf-owl-bot bot requested review from a team as code owners April 12, 2023 19:32

public Datastore createClient() throws Exception {
// Instantiates a client
// [START datastore_regional_endpoint]
Copy link
Contributor

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

Copy link
Contributor

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);
Copy link
Contributor

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.

Copy link
Contributor

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"));
Copy link
Contributor

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.

Copy link
Contributor

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");
Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@lesv lesv left a 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.

Comment on lines 56 to 59
// The kind for the new entity
String kind = "Task";
// The name/ID for the new entity
String name = "sampletask1";
Copy link
Contributor

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.

Copy link
Contributor

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.
// The kind for the new entity
String kind = "Task";
// The name/ID for the new entity
String name = "regionalEndpointClient50720906";
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

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

Done

@shweta345
Copy link
Author

@telpirion are there any other changes pending or can this PR be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/java-datastore API. samples Issues that are directly related to samples. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants