@@ -50,6 +50,12 @@ class spannerTest extends TestCase
5050 /** @var string lowCostInstanceId */
5151 protected static $ lowCostInstanceId ;
5252
53+ /** @var string instancePartitionInstanceId */
54+ protected static $ instancePartitionInstanceId ;
55+
56+ /** @var Instance instancePartitionInstance */
57+ protected static $ instancePartitionInstance ;
58+
5359 /** @var string databaseId */
5460 protected static $ databaseId ;
5561
@@ -123,6 +129,8 @@ public static function setUpBeforeClass(): void
123129 self ::$ autoscalingInstanceId = 'test- ' . time () . rand ();
124130 self ::$ instanceId = 'test- ' . time () . rand ();
125131 self ::$ lowCostInstanceId = 'test- ' . time () . rand ();
132+ self ::$ instancePartitionInstanceId = 'test- ' . time () . rand ();
133+ self ::$ instancePartitionInstance = $ spanner ->instance (self ::$ instancePartitionInstanceId );
126134 self ::$ databaseId = 'test- ' . time () . rand ();
127135 self ::$ encryptedDatabaseId = 'en-test- ' . time () . rand ();
128136 self ::$ backupId = 'backup- ' . self ::$ databaseId ;
@@ -236,6 +244,33 @@ public function testListInstanceConfigOperations()
236244 $ output );
237245 }
238246
247+ public function testCreateInstancePartition ()
248+ {
249+ $ spanner = new SpannerClient ([
250+ 'projectId ' => self ::$ projectId ,
251+ ]);
252+ $ instanceConfig = $ spanner ->instanceConfiguration ('regional-us-central1 ' );
253+ $ operation = $ spanner ->createInstance (
254+ $ instanceConfig ,
255+ self ::$ instancePartitionInstanceId ,
256+ [
257+ 'displayName ' => 'Instance partitions test. ' ,
258+ 'nodeCount ' => 1 ,
259+ 'labels ' => [
260+ 'cloud_spanner_samples ' => true ,
261+ ]
262+ ]
263+ );
264+ $ operation ->pollUntilComplete ();
265+ $ output = $ this ->runAdminFunctionSnippet ('create_instance_partition ' , [
266+ 'project_id ' => self ::$ projectId ,
267+ 'instance_id ' => self ::$ instancePartitionInstanceId ,
268+ 'instance_partition_id ' => 'my-instance-partition '
269+ ]);
270+ $ this ->assertStringContainsString ('Waiting for operation to complete... ' , $ output );
271+ $ this ->assertStringContainsString ('Created instance partition my-instance-partition ' , $ output );
272+ }
273+
239274 /**
240275 * @depends testCreateInstance
241276 */
@@ -1260,10 +1295,13 @@ public static function tearDownAfterClass(): void
12601295 $ database = self ::$ instance ->database (self ::$ databaseId );
12611296 $ database ->drop ();
12621297 }
1263- $ database = self ::$ multiInstance ->database (self ::$ databaseId );
1264- $ database ->drop ();
1298+ if (self ::$ multiInstance ->exists ()) {//Clean up database
1299+ $ database = self ::$ multiInstance ->database (self ::$ databaseId );
1300+ $ database ->drop ();
1301+ }
12651302 self ::$ instance ->delete ();
12661303 self ::$ lowCostInstance ->delete ();
1304+ self ::$ instancePartitionInstance ->delete ();
12671305 if (self ::$ customInstanceConfig ->exists ()) {
12681306 self ::$ customInstanceConfig ->delete ();
12691307 }
0 commit comments