Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Added
- Added `Connection::runDdlBatch` which runs DDLs in batch synchronously. (#86)
- Added emulator support for `Connection::listSessions`. (#88)

Fixed
- Fixed bug where running `Connection::statement` with DDLs was not logging and was not triggering events. (#86)
Expand Down
12 changes: 11 additions & 1 deletion src/Concerns/ManagesSessionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Colopl\Spanner\Session\DeleteOperation;
use Colopl\Spanner\Session\SessionInfo;
use Google\Auth\FetchAuthTokenInterface;
use Google\Cloud\Core\EmulatorTrait;
use Google\Cloud\Spanner\Connection\ConnectionInterface;
use Google\Cloud\Spanner\Connection\Grpc;
use Google\Cloud\Spanner\Database;
Expand All @@ -36,6 +37,8 @@
*/
trait ManagesSessionPool
{
use EmulatorTrait;

/**
* @return void
*/
Expand Down Expand Up @@ -82,7 +85,14 @@ public function warmupSessionPool(): int
public function listSessions(): Collection
{
$databaseName = $this->getSpannerDatabase()->name();
$response = (new ProtobufSpannerClient())->listSessions($databaseName);

$emulatorHost = getenv('SPANNER_EMULATOR_HOST');
$config = $emulatorHost
? $this->emulatorGapicConfig($emulatorHost)
: [];

$response = (new ProtobufSpannerClient($config))->listSessions($databaseName);

return collect($response->iterateAllElements())->map(function ($session) {
assert($session instanceof ProtobufSpannerSession);
return new SessionInfo($session);
Expand Down
4 changes: 0 additions & 4 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ public function test_clearSessionPool(): void

public function test_listSessions(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

$conn = $this->getDefaultConnection();
$conn->select('SELECT 1');

Expand Down
20 changes: 0 additions & 20 deletions tests/Console/SessionsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ public function test_no_args(): void

public function test_with_args(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

foreach (['main', 'alternative'] as $name) {
$conn = $this->getConnection($name);
assert($conn instanceof Connection);
Expand All @@ -89,10 +85,6 @@ public function test_with_args(): void

public function test_no_sessions_shows_no_table(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

$this->artisan('spanner:sessions', ['connections' => 'main'])
->expectsOutputToContain('main contains 0 session(s).')
->doesntExpectOutputToContain('Name')
Expand All @@ -102,10 +94,6 @@ public function test_no_sessions_shows_no_table(): void

public function test_sort(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

$conn = $this->getDefaultConnection();
$this->setUpDatabaseOnce($conn);
$this->createSessions($conn, 2);
Expand All @@ -127,10 +115,6 @@ public function test_sort(): void

public function test_sort_order(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

$conn = $this->getDefaultConnection();
$this->setUpDatabaseOnce($conn);
$this->createSessions($conn, 2);
Expand All @@ -152,10 +136,6 @@ public function test_sort_order(): void

public function test_sort_patterns(): void
{
if (getenv('SPANNER_EMULATOR_HOST')) {
$this->markTestSkipped('Cannot list sessions on emulator');
}

$conn = $this->getDefaultConnection();
$this->setUpDatabaseOnce($conn);
$this->createSessions($conn, 1);
Expand Down