File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,34 @@ def create_instance(instance_id):
6262# [END spanner_create_instance]
6363
6464
65+ # [START spanner_create_instance_with_processing_units]
66+ def create_instance_with_processing_units (instance_id , processing_units ):
67+ """Creates an instance."""
68+ spanner_client = spanner .Client ()
69+
70+ config_name = "{}/instanceConfigs/regional-us-central1" .format (
71+ spanner_client .project_name
72+ )
73+
74+ instance = spanner_client .instance (
75+ instance_id ,
76+ configuration_name = config_name ,
77+ display_name = "This is a display name." ,
78+ processing_units = processing_units ,
79+ )
80+
81+ operation = instance .create ()
82+
83+ print ("Waiting for operation to complete..." )
84+ operation .result (120 )
85+
86+ print ("Created instance {} with {} processing units" .format (
87+ instance_id , instance .processing_units ))
88+
89+
90+ # [END spanner_create_instance_with_processing_units]
91+
92+
6593# [START spanner_create_database]
6694def create_database (instance_id , database_id ):
6795 """Creates a database and tables for sample data."""
Original file line number Diff line number Diff line change @@ -53,6 +53,7 @@ def cleanup_old_instances(spanner_client):
5353
5454
5555INSTANCE_ID = unique_instance_id ()
56+ LCI_INSTANCE_ID = unique_instance_id ()
5657DATABASE_ID = unique_database_id ()
5758CMEK_DATABASE_ID = unique_database_id ()
5859
@@ -81,6 +82,14 @@ def test_create_instance(spanner_instance):
8182 spanner_instance .reload ()
8283
8384
85+ def test_create_instance_with_processing_units (capsys ):
86+ processing_units = 500
87+ snippets .create_instance_with_processing_units (LCI_INSTANCE_ID , processing_units )
88+ out , _ = capsys .readouterr ()
89+ assert LCI_INSTANCE_ID in out
90+ assert "{} processing units" .format (processing_units ) in out
91+
92+
8493def test_create_database (database ):
8594 # Reload will only succeed if the database exists.
8695 database .reload ()
You can’t perform that action at this time.
0 commit comments