Skip to content

chore: upgrade media-livestream tests to new surface #1992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2024
Merged
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
62 changes: 49 additions & 13 deletions media/livestream/test/livestreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@
use Google\ApiCore\ApiException;
use Google\Cloud\TestUtils\EventuallyConsistentTestTrait;
use Google\Cloud\TestUtils\TestTrait;
use Google\Cloud\Video\LiveStream\V1\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\Client\LivestreamServiceClient;
use Google\Cloud\Video\LiveStream\V1\DeleteAssetRequest;
use Google\Cloud\Video\LiveStream\V1\DeleteChannelRequest;
use Google\Cloud\Video\LiveStream\V1\DeleteEventRequest;
use Google\Cloud\Video\LiveStream\V1\DeleteInputRequest;
use Google\Cloud\Video\LiveStream\V1\GetChannelRequest;
use Google\Cloud\Video\LiveStream\V1\GetInputRequest;
use Google\Cloud\Video\LiveStream\V1\GetPoolRequest;
use Google\Cloud\Video\LiveStream\V1\ListAssetsRequest;
use Google\Cloud\Video\LiveStream\V1\ListChannelsRequest;
use Google\Cloud\Video\LiveStream\V1\ListEventsRequest;
use Google\Cloud\Video\LiveStream\V1\ListInputsRequest;
use Google\Cloud\Video\LiveStream\V1\StopChannelRequest;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -107,7 +119,9 @@ public function testUpdateInput()
self::$location,
self::$inputId
);
$input = $livestreamClient->getInput($formattedName);
$getInputRequest = (new GetInputRequest())
->setName($formattedName);
$input = $livestreamClient->getInput($getInputRequest);
$this->assertTrue($input->getPreprocessingConfig()->hasCrop());
}

Expand Down Expand Up @@ -198,7 +212,9 @@ public function testUpdateChannel()
self::$location,
self::$channelId
);
$channel = $livestreamClient->getChannel($formattedName);
$getChannelRequest = (new GetChannelRequest())
->setName($formattedName);
$channel = $livestreamClient->getChannel($getChannelRequest);
$inputAttachments = $channel->getInputAttachments();
foreach ($inputAttachments as $inputAttachment) {
$this->assertStringContainsString('updated-input', $inputAttachment->getKey());
Expand Down Expand Up @@ -476,15 +492,19 @@ public function testUpdatePool()
self::$location,
self::$poolId
);
$pool = $livestreamClient->getPool($formattedName);
$getPoolRequest = (new GetPoolRequest())
->setName($formattedName);
$pool = $livestreamClient->getPool($getPoolRequest);
$this->assertEquals($pool->getNetworkConfig()->getPeeredNetwork(), '');
}

private static function deleteOldInputs(): void
{
$livestreamClient = new LivestreamServiceClient();
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
$response = $livestreamClient->listInputs($parent);
$listInputsRequest = (new ListInputsRequest())
->setParent($parent);
$response = $livestreamClient->listInputs($listInputsRequest);
$inputs = $response->iterateAllElements();

$currentTime = time();
Expand All @@ -498,7 +518,9 @@ private static function deleteOldInputs(): void

if ($currentTime - $timestamp >= $oneHourInSecs) {
try {
$livestreamClient->deleteInput($input->getName());
$deleteInputRequest = (new DeleteInputRequest())
->setName($input->getName());
$livestreamClient->deleteInput($deleteInputRequest);
} catch (ApiException $e) {
// Cannot delete inputs that are added to channels
if ($e->getStatus() === 'FAILED_PRECONDITION') {
Expand All @@ -515,7 +537,9 @@ private static function deleteOldChannels(): void
{
$livestreamClient = new LivestreamServiceClient();
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
$response = $livestreamClient->listChannels($parent);
$listChannelsRequest = (new ListChannelsRequest())
->setParent($parent);
$response = $livestreamClient->listChannels($listChannelsRequest);
$channels = $response->iterateAllElements();

$currentTime = time();
Expand All @@ -529,18 +553,24 @@ private static function deleteOldChannels(): void

if ($currentTime - $timestamp >= $oneHourInSecs) {
// Must delete channel events before deleting the channel
$response = $livestreamClient->listEvents($channel->getName());
$listEventsRequest = (new ListEventsRequest())
->setParent($channel->getName());
$response = $livestreamClient->listEvents($listEventsRequest);
$events = $response->iterateAllElements();
foreach ($events as $event) {
try {
$livestreamClient->deleteEvent($event->getName());
$deleteEventRequest = (new DeleteEventRequest())
->setName($event->getName());
$livestreamClient->deleteEvent($deleteEventRequest);
} catch (ApiException $e) {
printf('Channel event delete failed: %s.' . PHP_EOL, $e->getMessage());
}
}

try {
$livestreamClient->stopChannel($channel->getName());
$stopChannelRequest = (new StopChannelRequest())
->setName($channel->getName());
$livestreamClient->stopChannel($stopChannelRequest);
} catch (ApiException $e) {
// Cannot delete channels that are running, but
// channel may already be stopped
Expand All @@ -552,7 +582,9 @@ private static function deleteOldChannels(): void
}

try {
$livestreamClient->deleteChannel($channel->getName());
$deleteChannelRequest = (new DeleteChannelRequest())
->setName($channel->getName());
$livestreamClient->deleteChannel($deleteChannelRequest);
} catch (ApiException $e) {
// Cannot delete inputs that are added to channels
if ($e->getStatus() === 'FAILED_PRECONDITION') {
Expand All @@ -569,7 +601,9 @@ private static function deleteOldAssets(): void
{
$livestreamClient = new LivestreamServiceClient();
$parent = $livestreamClient->locationName(self::$projectId, self::$location);
$response = $livestreamClient->listAssets($parent);
$listAssetsRequest = (new ListAssetsRequest())
->setParent($parent);
$response = $livestreamClient->listAssets($listAssetsRequest);
$assets = $response->iterateAllElements();

$currentTime = time();
Expand All @@ -583,7 +617,9 @@ private static function deleteOldAssets(): void

if ($currentTime - $timestamp >= $oneHourInSecs) {
try {
$livestreamClient->deleteAsset($asset->getName());
$deleteAssetRequest = (new DeleteAssetRequest())
->setName($asset->getName());
$livestreamClient->deleteAsset($deleteAssetRequest);
} catch (ApiException $e) {
printf('Asset delete failed: %s.' . PHP_EOL, $e->getMessage());
}
Expand Down
Loading