@@ -50,6 +50,12 @@ class spannerTest extends TestCase
50
50
/** @var string lowCostInstanceId */
51
51
protected static $ lowCostInstanceId ;
52
52
53
+ /** @var string instancePartitionInstanceId */
54
+ protected static $ instancePartitionInstanceId ;
55
+
56
+ /** @var Instance instancePartitionInstance */
57
+ protected static $ instancePartitionInstance ;
58
+
53
59
/** @var string databaseId */
54
60
protected static $ databaseId ;
55
61
@@ -123,6 +129,8 @@ public static function setUpBeforeClass(): void
123
129
self ::$ autoscalingInstanceId = 'test- ' . time () . rand ();
124
130
self ::$ instanceId = 'test- ' . time () . rand ();
125
131
self ::$ lowCostInstanceId = 'test- ' . time () . rand ();
132
+ self ::$ instancePartitionInstanceId = 'test- ' . time () . rand ();
133
+ self ::$ instancePartitionInstance = $ spanner ->instance (self ::$ instancePartitionInstanceId );
126
134
self ::$ databaseId = 'test- ' . time () . rand ();
127
135
self ::$ encryptedDatabaseId = 'en-test- ' . time () . rand ();
128
136
self ::$ backupId = 'backup- ' . self ::$ databaseId ;
@@ -236,6 +244,33 @@ public function testListInstanceConfigOperations()
236
244
$ output );
237
245
}
238
246
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
+
239
274
/**
240
275
* @depends testCreateInstance
241
276
*/
@@ -1260,10 +1295,13 @@ public static function tearDownAfterClass(): void
1260
1295
$ database = self ::$ instance ->database (self ::$ databaseId );
1261
1296
$ database ->drop ();
1262
1297
}
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
+ }
1265
1302
self ::$ instance ->delete ();
1266
1303
self ::$ lowCostInstance ->delete ();
1304
+ self ::$ instancePartitionInstance ->delete ();
1267
1305
if (self ::$ customInstanceConfig ->exists ()) {
1268
1306
self ::$ customInstanceConfig ->delete ();
1269
1307
}
0 commit comments