Skip to content

Commit

Permalink
feat: add sample for low cost instances (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoercai authored Jul 5, 2021
1 parent c37bf21 commit 3f4f93f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions samples/samples/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ def create_instance(instance_id):
# [END spanner_create_instance]


# [START spanner_create_instance_with_processing_units]
def create_instance_with_processing_units(instance_id, processing_units):
"""Creates an instance."""
spanner_client = spanner.Client()

config_name = "{}/instanceConfigs/regional-us-central1".format(
spanner_client.project_name
)

instance = spanner_client.instance(
instance_id,
configuration_name=config_name,
display_name="This is a display name.",
processing_units=processing_units,
)

operation = instance.create()

print("Waiting for operation to complete...")
operation.result(120)

print("Created instance {} with {} processing units".format(
instance_id, instance.processing_units))


# [END spanner_create_instance_with_processing_units]


# [START spanner_create_database]
def create_database(instance_id, database_id):
"""Creates a database and tables for sample data."""
Expand Down
9 changes: 9 additions & 0 deletions samples/samples/snippets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def cleanup_old_instances(spanner_client):


INSTANCE_ID = unique_instance_id()
LCI_INSTANCE_ID = unique_instance_id()
DATABASE_ID = unique_database_id()
CMEK_DATABASE_ID = unique_database_id()

Expand Down Expand Up @@ -81,6 +82,14 @@ def test_create_instance(spanner_instance):
spanner_instance.reload()


def test_create_instance_with_processing_units(capsys):
processing_units = 500
snippets.create_instance_with_processing_units(LCI_INSTANCE_ID, processing_units)
out, _ = capsys.readouterr()
assert LCI_INSTANCE_ID in out
assert "{} processing units".format(processing_units) in out


def test_create_database(database):
# Reload will only succeed if the database exists.
database.reload()
Expand Down

0 comments on commit 3f4f93f

Please sign in to comment.