public function testCheckCreateMessageOptions() { $options = new CreateMessageOptions(); $this->assertNull($options->getTimeout(), 'Default CreateMessageOptions->getTimeout'); $this->assertNull($options->getTimeToLiveInSeconds(), 'Default CreateMessageOptions->getTimeToLiveInSeconds'); $this->assertNull($options->getVisibilityTimeoutInSeconds(), 'Default CreateMessageOptions->getVisibilityTimeoutInSeconds'); $options->setTimeout(self::INT_MAX_VALUE); $options->setTimeToLiveInSeconds(0); $options->setVisibilityTimeoutInSeconds(self::INT_MIN_VALUE); $this->assertEquals(self::INT_MAX_VALUE, $options->getTimeout(), 'Set CreateMessageOptions->getTimeout'); $this->assertEquals(0, $options->getTimeToLiveInSeconds(), 'Set CreateMessageOptions->getTimeToLiveInSeconds'); $this->assertEquals(self::INT_MIN_VALUE, $options->getVisibilityTimeoutInSeconds(), 'Set CreateMessageOptions->getVisibilityTimeoutInSeconds'); }
/** * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::clearMessages * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::createMessage * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::listMessages */ private function clearMessagesWorker($options) { self::println('Trying $options: ' . self::tmptostring($options)); $queue = QueueServiceFunctionalTestData::$testQueueNames; $queue = $queue[0]; $this->restProxy->clearMessages($queue); // Put three messages into the queue. $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText()); $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText()); $this->restProxy->createMessage($queue, QueueServiceFunctionalTestData::getSimpleMessageText()); // Wait a bit to make sure the messages are there. sleep(1); // Make sure the messages are there, and use a short visibility timeout to make sure the are visible again later. $opts = new ListMessagesOptions(); $opts->setVisibilityTimeoutInSeconds(1); $opts->setNumberOfMessages(32); $lmr = $this->restProxy->listMessages($queue, $opts); $this->assertEquals(3, count($lmr->getQueueMessages()), 'getQueueMessages() count'); sleep(2); try { if (is_null($options)) { $this->restProxy->clearMessages($queue); } else { $this->restProxy->clearMessages($queue, $options); } if (is_null($options)) { $options = new CreateMessageOptions(); } else { if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertTrue(false, 'Expect negative timeouts in $options to throw'); } } // Wait 2 seconds to make sure the messages would be visible again. $opts = new ListMessagesOptions(); $opts->setVisibilityTimeoutInSeconds(1); $opts->setNumberOfMessages(32); $lmr = $this->restProxy->listMessages($queue, $opts); $this->assertEquals(0, count($lmr->getQueueMessages()), 'getQueueMessages() count'); } catch (ServiceException $e) { if (is_null($options)) { $options = new CreateMessageOptions(); } if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode'); } else { throw $e; } } $this->restProxy->clearMessages($queue); }
public static function getSimpleCreateMessageOptions() { $ret = new CreateMessageOptions(); $ret->setTimeout(4); $ret->setTimeToLiveInSeconds(1000); $ret->setVisibilityTimeoutInSeconds(self::INTERESTING_TTL); return $ret; }
/** * Adds a message to the queue and optionally sets a visibility timeout * for the message. * * @param string $queueName The name of the queue. * @param string $messageText The message contents. * @param CreateMessageOptions $options The optional parameters. * * @return none */ public function createMessage($queueName, $messageText, $options = null) { Validate::isString($queueName, 'queueName'); Validate::notNullOrEmpty($queueName, 'queueName'); Validate::isString($messageText, 'messageText'); $method = Resources::HTTP_POST; $headers = array(); $postParams = array(); $queryParams = array(); $path = $queueName . '/messages'; $body = Resources::EMPTY_STRING; $statusCode = Resources::STATUS_CREATED; $message = new QueueMessage(); $message->setMessageText($messageText); $body = $message->toXml($this->dataSerializer); if (is_null($options)) { $options = new CreateMessageOptions(); } $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE); $visibility = $options->getVisibilityTimeoutInSeconds(); $timeToLive = $options->getTimeToLiveInSeconds(); $timeout = $options->getTimeout(); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $timeout); $this->addOptionalQueryParam($queryParams, Resources::QP_VISIBILITY_TIMEOUT, $visibility); $this->addOptionalQueryParam($queryParams, Resources::QP_MESSAGE_TTL, $timeToLive); $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body); }
/** * @covers MicrosoftAzure\Storage\Queue\Models\CreateMessageOptions::setTimeToLiveInSeconds */ public function testSetTimeToLiveInSeconds() { // Setup $createMessageOptions = new CreateMessageOptions(); $expected = 20; // Test $createMessageOptions->setTimeToLiveInSeconds($expected); // Assert $actual = $createMessageOptions->getTimeToLiveInSeconds(); $this->assertEquals($expected, $actual); }