示例#1
1
 public function testCreateQueue()
 {
     $queueName = 'test_queue';
     $db = DriverManager::getConnection(['driver' => 'pdo_mysql', 'host' => SYRUP_DATABASE_HOST, 'dbname' => SYRUP_DATABASE_NAME, 'user' => SYRUP_DATABASE_USER, 'password' => SYRUP_DATABASE_PASSWORD, 'port' => SYRUP_DATABASE_PORT]);
     $db->query("DELETE FROM queues WHERE id='{$queueName}'")->execute();
     $command = $this->application->find('syrup:queue:create');
     $commandTester = new CommandTester($command);
     $commandTester->execute(['name' => $queueName, '--register' => null, '--no-watch' => null]);
     $this->assertEquals(0, $commandTester->getStatusCode());
     $factory = new QueueFactory($db, ['db_table' => 'queues'], SYRUP_APP_NAME);
     $dbQueue = $factory->get($queueName);
     $queueUrlArr = explode('/', $dbQueue->getUrl());
     $this->assertEquals($queueName, array_pop($queueUrlArr));
     $sqsClient = new SqsClient(['version' => '2012-11-05', 'region' => 'us-east-1']);
     $sqsClient->deleteQueue(['QueueUrl' => $dbQueue->getUrl()]);
 }
示例#2
0
 /**
  * @covers \Keboola\Syrup\Service\Queue\QueueFactory::__construct
  * @covers \Keboola\Syrup\Service\Queue\QueueFactory::get
  * @covers \Keboola\Syrup\Service\Queue\QueueService::enqueue
  * @covers \Keboola\Syrup\Service\Queue\QueueService::receive
  * @covers \Keboola\Syrup\Service\Queue\QueueService::deleteMessage
  */
 public function testQueue()
 {
     $db = \Doctrine\DBAL\DriverManager::getConnection(['driver' => 'pdo_mysql', 'host' => SYRUP_DATABASE_HOST, 'dbname' => SYRUP_DATABASE_NAME, 'user' => SYRUP_DATABASE_USER, 'password' => SYRUP_DATABASE_PASSWORD, 'port' => SYRUP_DATABASE_PORT]);
     $queueFactory = new QueueFactory($db, ['db_table' => 'queues'], SYRUP_APP_NAME);
     $queueService = $queueFactory->get();
     // clear queue first
     $queueNotEmpty = true;
     do {
         $messages = $queueService->receive(10);
         if (count($messages)) {
             foreach ($messages as $message) {
                 $queueService->deleteMessage($message);
             }
         } else {
             $queueNotEmpty = false;
         }
     } while ($queueNotEmpty);
     $jobId = rand(0, 128);
     $messageId = $queueService->enqueue($jobId, ['test' => 'test']);
     $this->assertNotNull($messageId);
     $result = $queueService->receive();
     $this->assertGreaterThan(0, $result);
     foreach ($result as $message) {
         $queueService->deleteMessage($message);
     }
     // assert that test did not fail
     $this->assertTrue(true);
 }
示例#3
0
 public function testCreate()
 {
     $db = DriverManager::getConnection(['driver' => 'pdo_mysql', 'host' => SYRUP_DATABASE_HOST, 'dbname' => SYRUP_DATABASE_NAME, 'user' => SYRUP_DATABASE_USER, 'password' => SYRUP_DATABASE_PASSWORD, 'port' => SYRUP_DATABASE_PORT]);
     $factory = new QueueFactory($db, ['db_table' => 'queues'], SYRUP_APP_NAME);
     $sqsQueue = $factory->create('test');
     $queueUrlArr = explode('/', $sqsQueue->get('QueueUrl'));
     $this->assertEquals('test', array_pop($queueUrlArr));
     // delete the queue from AWS
     $sqsClient = new SqsClient(['version' => '2012-11-05', 'region' => 'us-east-1']);
     $sqsClient->deleteQueue(['QueueUrl' => $sqsQueue->get('QueueUrl')]);
 }