AsyncMultipleHandlersTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. use Magento\TestModuleAsyncAmqp\Model\AsyncTestData;
  8. class AsyncMultipleHandlersTest extends QueueTestCaseAbstract
  9. {
  10. /**
  11. * @var string
  12. */
  13. protected $expectedMessages;
  14. /**
  15. * @var string[]
  16. */
  17. protected $consumers = [
  18. 'mtmh.queue.1.consumer',
  19. 'mtmh.queue.2.consumer',
  20. ];
  21. /**
  22. * @var string[]
  23. */
  24. private $topicValueMap = [
  25. 'mtmh.topic.1' => 'mtmh.topic.1',
  26. 'mtmh.topic.2' => ['mtmh.topic.2-1', 'mtmh.topic.2-2']
  27. ];
  28. /**
  29. * @var string[]
  30. */
  31. private $expectedValues = [
  32. 'string-mtmh.topic.1',
  33. 'mixed-mtmh.topic.1',
  34. 'array-mtmh.topic.2-1',
  35. 'array-mtmh.topic.2-2',
  36. 'mixed-mtmh.topic.2-1',
  37. 'mixed-mtmh.topic.2-2'
  38. ];
  39. /**
  40. * Verify that Queue Framework supports multiple topics per queue.
  41. *
  42. * Current test is not test of Web API framework itself,
  43. * it just utilizes its infrastructure to test Message Queue.
  44. */
  45. public function testAsynchronousRpcCommunication()
  46. {
  47. foreach ($this->topicValueMap as $topic => $data) {
  48. $message = null;
  49. if (is_array($data)) {
  50. foreach ($data as $key => $value) {
  51. /** @var AsyncTestData $testObject */
  52. $testObject = $this->objectManager->create(AsyncTestData::class);
  53. $testObject->setValue($value);
  54. $testObject->setTextFilePath($this->logFilePath);
  55. $message[$key] = $testObject;
  56. }
  57. } else {
  58. $testObject = $this->objectManager->create(AsyncTestData::class);
  59. $testObject->setValue($data);
  60. $testObject->setTextFilePath($this->logFilePath);
  61. $message = $testObject;
  62. }
  63. $this->publisher->publish($topic, $message);
  64. }
  65. $this->waitForAsynchronousResult(count($this->expectedValues), $this->logFilePath);
  66. //assertions
  67. foreach ($this->expectedValues as $item) {
  68. $this->assertContains($item, file_get_contents($this->logFilePath));
  69. }
  70. }
  71. }