-
Notifications
You must be signed in to change notification settings - Fork 460
Expand file tree
/
Copy pathlock_test_process.php
More file actions
70 lines (55 loc) · 1.77 KB
/
lock_test_process.php
File metadata and controls
70 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace Google\Cloud\Spanner\Tests\Unit\Session;
use DG\BypassFinals;
use Exception;
use Google\Auth\Cache\FileSystemCacheItemPool;
use Google\Cloud\Spanner\Session\SessionCache;
use Google\Cloud\Spanner\V1\Client\SpannerClient;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
/**
* Runs a process which is designed to wait while a session is acquired.
*/
if (count($argv) !== 2) {
die('Usage: lock_test_process.php DATABASE_NAME' . PHP_EOL);
}
$spannerAutoload = __DIR__ . '/../../../vendor/autoload.php';
$googleCloudAutoload = __DIR__ . '/../../../../vendor/autoload.php';
if (file_exists($spannerAutoload) && file_exists($googleCloudAutoload)) {
throw new Exception('Both autoloaders exist, please remove one');
}
if (file_exists($spannerAutoload)) {
// google/cloud-spanner autoload
require $spannerAutoload;
} elseif (file_exists($googleCloudAutoload)) {
// google/cloud autoload
require $googleCloudAutoload;
} else {
throw new Exception('no autoloader found');
}
BypassFinals::enable();
[$_cmd, $databaseName] = $argv;
$acquireSession = new class($databaseName) {
use ProphecyTrait;
public function __construct(
private string $databaseName,
) {
}
public function run(): string
{
$spannerClient = $this->prophesize(SpannerClient::class);
$spannerClient->createSession(Argument::cetera())
->will(function () {
throw new \Exception('createSession called in child process - this shouldn\'t happen');
});
$sessionCache = new SessionCache(
$spannerClient->reveal(),
$this->databaseName
);
return $sessionCache->name();
}
public function registerFailureType()
{
}
};
echo $acquireSession->run();