Skip to content
Permalink
Browse files
feat: add sample for low cost instances (#392)
  • Loading branch information
zoercai committed Jul 5, 2021
1 parent c37bf21 commit 3f4f93f75f5585a82047bf8d83a24622ad776ecb
Showing with 37 additions and 0 deletions.
  1. +28 −0 samples/samples/snippets.py
  2. +9 −0 samples/samples/snippets_test.py
@@ -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."""
@@ -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()

@@ -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()

0 comments on commit 3f4f93f

Please sign in to comment.