Пример #1
0
 public function testFindByMediaId()
 {
     $this->assertNull(CM_Model_StreamChannelArchive_Media::findByMediaId('foo'));
     /** @var CM_Model_StreamChannel_Media $streamChannel */
     $streamChannel = $streamChannel = CMTest_TH::createStreamChannel(null, null, 'foo');
     $this->assertEquals($streamChannel, CM_Model_StreamChannel_Media::findByMediaId($streamChannel->getMediaId()));
 }
Пример #2
0
 public function testCreateStreamChannel()
 {
     $repository = new CM_MediaStreams_StreamRepository(1);
     $mediaId = '444-bar';
     $channel = $repository->createStreamChannel('foo', CM_Model_StreamChannel_Media::getTypeStatic(), 2, $mediaId);
     $this->assertInstanceOf('CM_Model_StreamChannel_Media', $channel);
     CM_Model_StreamChannelArchive_Media::createStatic(['streamChannel' => $channel]);
     $exception = $this->catchException(function () use($repository, $mediaId) {
         $repository->createStreamChannel('bar', CM_Model_StreamChannel_Media::getTypeStatic(), 2, $mediaId);
     });
     $this->assertInstanceOf('CM_Exception_Invalid', $exception);
     /** @var CM_Exception_Invalid $exception */
     $this->assertSame('Channel archive with this mediaId already exists', $exception->getMessage());
     $this->assertSame(['mediaId' => $mediaId], $exception->getMetaInfo());
 }
Пример #3
0
 /**
  * @param string  $streamChannelMediaId
  * @param CM_File $archiveSource
  * @throws CM_Exception_Invalid
  */
 public function importArchive($streamChannelMediaId, CM_File $archiveSource)
 {
     $streamChannelMediaId = (string) $streamChannelMediaId;
     $streamChannelArchive = CM_Model_StreamChannelArchive_Media::findByMediaId($streamChannelMediaId);
     if (!$streamChannelArchive) {
         $streamChannel = CM_Model_StreamChannel_Media::findByMediaId($streamChannelMediaId);
         if ($streamChannel) {
             throw new CM_Exception_Invalid('Archive not created, please try again later', null, ['streamChannelMediaId' => $streamChannelMediaId]);
         }
         $exception = new CM_Exception_Invalid('Archive not found, stream channel not found, skipping', CM_Exception::WARN, ['streamChannelMediaId' => $streamChannelMediaId]);
         $context = new CM_Log_Context();
         $context->setException($exception);
         $this->getServiceManager()->getLogger()->warning('Archive creating error', $context);
         return;
     }
     $filename = $streamChannelArchive->getId() . '-' . $streamChannelArchive->getHash() . '-original.' . $archiveSource->getExtension();
     $archiveDestination = new CM_File_UserContent('streamChannels', $filename, $streamChannelArchive->getId());
     $archiveDestination->ensureParentDirectory();
     $archiveSource->copyToFile($archiveDestination);
     $streamChannelArchive->setFile($archiveDestination);
 }
Пример #4
0
 public function testPaging()
 {
     CMTest_TH::createStreamChannelVideoArchive();
     $archive = CMTest_TH::createStreamChannelVideoArchive();
     CMTest_TH::timeForward(30);
     CMTest_TH::createStreamChannelVideoArchive();
     /** @var CM_Model_StreamChannel_Media $streamChannel */
     $streamChannel = CMTest_TH::createStreamChannel();
     $mockBuilder = $this->getMockBuilder('CM_Model_StreamChannel_Media');
     $mockBuilder->setMethods(['getType']);
     $mockBuilder->setConstructorArgs([$streamChannel->getId()]);
     $streamChannelMock = $mockBuilder->getMock();
     $streamChannelMock->expects($this->any())->method('getType')->will($this->returnValue(3));
     CMTest_TH::createStreamChannelVideoArchive($streamChannelMock);
     $paging = new CM_Paging_StreamChannelArchiveMedia_Type(CM_Model_StreamChannel_Media::getTypeStatic());
     $this->assertSame(3, $paging->getCount());
     $paging = new CM_Paging_StreamChannelArchiveMedia_Type($streamChannelMock->getType());
     $this->assertSame(1, $paging->getCount());
     $paging = new CM_Paging_StreamChannelArchiveMedia_Type(CM_Model_StreamChannel_Media::getTypeStatic(), $archive->getCreated());
     $this->assertSame(2, $paging->getCount());
 }
Пример #5
0
 public function testGetStreamChannelMedia()
 {
     $streamChannel = CMTest_TH::createStreamChannel(CM_Model_StreamChannel_Media::getTypeStatic());
     $params = new CM_Params(['channel' => $streamChannel]);
     $this->assertEquals($streamChannel, $params->getStreamChannelMedia('channel'));
 }
Пример #6
0
 public function jsonSerialize()
 {
     $array = parent::jsonSerialize();
     $array['connectionDescription'] = $this->getConnectionDescription();
     return $array;
 }
Пример #7
0
 /**
  * @param string $mediaId
  * @return CM_Model_StreamChannel_Media|null
  */
 public static function findByMediaId($mediaId)
 {
     $row = CM_Db_Db::exec("SELECT t1.id, t2.type FROM cm_streamChannel_media t1 JOIN cm_streamChannel t2 USING(id) WHERE t1.mediaId = ?", [(string) $mediaId])->fetch();
     if (!$row) {
         return null;
     }
     $streamChannelId = $row['id'];
     $streamChannelType = $row['type'];
     return CM_Model_StreamChannel_Media::factory($streamChannelId, $streamChannelType);
 }
Пример #8
0
 /**
  * @expectedException CM_Exception_Invalid
  * @expectedExceptionMessage Unexpected instance
  */
 public function testFactoryInvalidInstance()
 {
     $messageStreamChannel = CM_Model_StreamChannel_Message::createStatic(array('key' => 'message-stream-channel', 'adapterType' => CM_MessageStream_Adapter_SocketRedis::getTypeStatic()));
     CM_Model_StreamChannel_Media::factory($messageStreamChannel->getId());
 }
Пример #9
0
 /**
  * @param int|null    $type
  * @param int|null    $adapterType
  * @param string|null $mediaId
  * @return CM_Model_StreamChannel_Abstract
  */
 public static function createStreamChannel($type = null, $adapterType = null, $mediaId = null)
 {
     if (null === $type) {
         $type = CM_Model_StreamChannel_Media::getTypeStatic();
     }
     if (null === $adapterType) {
         $adapterType = CM_Janus_Service::getTypeStatic();
     }
     $data = array('key' => rand(1, 10000) . '_' . rand(1, 100));
     $className = CM_Model_Abstract::getClassName($type);
     if ('CM_Model_StreamChannel_Media' === $className || is_subclass_of($className, 'CM_Model_StreamChannel_Media')) {
         $mediaId = null !== $mediaId ? (string) $mediaId : null;
         $data['width'] = 480;
         $data['height'] = 720;
         $data['serverId'] = 1;
         $data['adapterType'] = $adapterType;
         $data['mediaId'] = $mediaId;
     }
     return CM_Model_StreamChannel_Abstract::createType($type, $data);
 }
Пример #10
0
 public function testDeleteOlder()
 {
     $archivesDeleted = [];
     $archivesNotDeleted = [];
     for ($i = 0; $i < 2; $i++) {
         $archive = CMTest_TH::createStreamChannelVideoArchive();
         $archivesDeleted[] = $archive;
     }
     $streamChannel = CMTest_TH::createStreamChannel();
     $mockBuilder = $this->getMockBuilder('CM_Model_StreamChannel_Media');
     $mockBuilder->setMethods(['getType']);
     $mockBuilder->setConstructorArgs([$streamChannel->getId()]);
     $streamChannelMock = $mockBuilder->getMock();
     $streamChannelMock->expects($this->any())->method('getType')->will($this->returnValue(3));
     $archive = CMTest_TH::createStreamChannelVideoArchive($streamChannelMock);
     $archivesNotDeleted[] = $archive;
     CMTest_TH::timeForward(20);
     for ($i = 0; $i < 3; $i++) {
         $archive = CMTest_TH::createStreamChannelVideoArchive();
         $archivesNotDeleted[] = $archive;
     }
     $this->assertCount(6, new CM_Paging_StreamChannelArchiveMedia_All());
     CM_Model_StreamChannelArchive_Media::deleteOlder(10, CM_Model_StreamChannel_Media::getTypeStatic());
     $this->assertCount(4, new CM_Paging_StreamChannelArchiveMedia_All());
     foreach ($archivesNotDeleted as $archive) {
         $exception = $this->catchException(function () use($archive) {
             CMTest_TH::reinstantiateModel($archive);
         });
         $this->assertNull($exception, 'Deleted archive that was too young or the wrong type');
     }
     foreach ($archivesDeleted as $archive) {
         $exception = $this->catchException(function () use($archive) {
             CMTest_TH::reinstantiateModel($archive);
         });
         $this->assertInstanceOf('CM_Exception_Nonexistent', $exception, 'Didn\'t delete old archive');
     }
 }