AsyncMultipleTopicsWithEachQueueTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\UseCase;
  7. class AsyncMultipleTopicsWithEachQueueTest extends QueueTestCaseAbstract
  8. {
  9. /**
  10. * @var string[]
  11. */
  12. protected $uniqueID;
  13. /**
  14. * @var \Magento\TestModuleAsyncAmqp\Model\AsyncTestData
  15. */
  16. protected $msgObject;
  17. /**
  18. * @var string[]
  19. */
  20. protected $consumers = ['queue.for.multiple.topics.test.y', 'queue.for.multiple.topics.test.z'];
  21. /**
  22. * @var string[]
  23. */
  24. private $topics = ['multi.topic.queue.topic.y', 'multi.topic.queue.topic.z'];
  25. /**
  26. * Verify that Queue Framework processes multiple asynchronous topics sent to the same queue.
  27. *
  28. * Current test is not test of Web API framework itself, it just utilizes its infrastructure to test Message Queue.
  29. */
  30. public function testAsyncMultipleTopicsPerQueue()
  31. {
  32. $this->msgObject = $this->objectManager->create(\Magento\TestModuleAsyncAmqp\Model\AsyncTestData::class);
  33. foreach ($this->topics as $topic) {
  34. $this->uniqueID[$topic] = md5(uniqid($topic));
  35. $this->msgObject->setValue($this->uniqueID[$topic] . "_" . $topic);
  36. $this->msgObject->setTextFilePath($this->logFilePath);
  37. $this->publisher->publish($topic, $this->msgObject);
  38. }
  39. $this->waitForAsynchronousResult(count($this->uniqueID), $this->logFilePath);
  40. //assertions
  41. foreach ($this->topics as $item) {
  42. $this->assertContains($this->uniqueID[$item] . "_" . $item, file_get_contents($this->logFilePath));
  43. }
  44. }
  45. }