3131 */
3232class BatchTest extends SystemTestCase
3333{
34+ const TABLE_NAME = 'BatchTest ' ;
3435 use SystemTestCaseTrait;
3536 use DatabaseRoleTrait;
3637
37- private static $ tableName ;
38+
3839 private static $ isSetup = false ;
3940
4041 /**
4142 * @beforeClass
4243 */
4344 public static function setUpTestFixtures (): void
4445 {
45- if (self ::$ isSetup ) {
46- return ;
47- }
4846 self ::setUpTestDatabase ();
49-
50- self ::$ tableName = uniqid (self ::TESTING_PREFIX );
51-
52- self ::$ database ->updateDdl (sprintf (
53- 'CREATE TABLE %s (
54- id INT64 NOT NULL,
55- decade INT64 NOT NULL
56- ) PRIMARY KEY (id) ' ,
57- self ::$ tableName
58- ))->pollUntilComplete ();
59-
60- if (self ::$ database ->info ()['databaseDialect ' ] == DatabaseDialect::GOOGLE_STANDARD_SQL ) {
61- $ statements = [];
62-
63- if (!self ::isEmulatorUsed ()) {
64- $ statements [] = sprintf (
65- 'GRANT SELECT(id) ON TABLE %s TO ROLE %s ' ,
66- self ::$ tableName ,
67- self ::$ restrictiveDbRole
68- );
69- }
70-
71- $ statements [] = sprintf (
72- 'GRANT SELECT ON TABLE %s TO ROLE %s ' ,
73- self ::$ tableName ,
74- self ::$ dbRole
75- );
76-
77- self ::$ database ->updateDdlBatch ($ statements )->pollUntilComplete ();
78- }
79-
80- self ::seedTable ();
81- self ::$ isSetup = true ;
82- }
83-
84- private static function seedTable ()
85- {
86- $ decades = [1950 , 1960 , 1970 , 1980 , 1990 , 2000 ];
87- for ($ i = 0 ; $ i < 250 ; $ i ++) {
88- self ::$ database ->insert (self ::$ tableName , [
89- 'id ' => self ::randId (),
90- 'decade ' => array_rand ($ decades )
91- ], [
92- 'timeoutMillis ' => 50000
93- ]);
94- }
9547 }
9648
9749 public function testBatch ()
9850 {
9951 $ query = 'SELECT
10052 id,
10153 decade
102- FROM ' . self ::$ tableName . '
54+ FROM ' . self ::TABLE_NAME . '
10355 WHERE
10456 decade > @earlyBound
10557 AND
@@ -131,7 +83,7 @@ public function testBatch()
13183 ]
13284 ]);
13385
134- $ partitions = $ snapshot ->partitionRead (self ::$ tableName , $ keySet , ['id ' , 'decade ' ]);
86+ $ partitions = $ snapshot ->partitionRead (self ::TABLE_NAME , $ keySet , ['id ' , 'decade ' ]);
13587 $ this ->assertEquals (count ($ resultSet ), $ this ->executePartitions ($ batch , $ snapshot , $ partitions ));
13688 }
13789
@@ -146,7 +98,7 @@ public function testBatchWithDbRole($dbRole, $expected)
14698 $ query = 'SELECT
14799 id,
148100 decade
149- FROM ' . self ::$ tableName . '
101+ FROM ' . self ::TABLE_NAME . '
150102 WHERE
151103 decade > @earlyBound
152104 AND
0 commit comments