MixSyncAndAsyncSingleQueueTest.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 MixSyncAndAsyncSingleQueueTest extends QueueTestCaseAbstract
  8. {
  9. /**
  10. * @var \Magento\TestModuleAsyncAmqp\Model\AsyncTestData
  11. */
  12. protected $msgObject;
  13. /**
  14. * {@inheritdoc}
  15. */
  16. protected $consumers = ['mixed.sync.and.async.queue.consumer'];
  17. /**
  18. * @var string[]
  19. */
  20. protected $messages = ['message1', 'message2', 'message3'];
  21. /**
  22. * @var int
  23. */
  24. protected $maxMessages = 4;
  25. public function testMixSyncAndAsyncSingleQueue()
  26. {
  27. $this->msgObject = $this->objectManager->create(\Magento\TestModuleAsyncAmqp\Model\AsyncTestData::class);
  28. // Publish asynchronous messages
  29. foreach ($this->messages as $item) {
  30. $this->msgObject->setValue($item);
  31. $this->msgObject->setTextFilePath($this->logFilePath);
  32. $this->publisher->publish('multi.topic.queue.topic.c', $this->msgObject);
  33. }
  34. // Publish synchronous message to the same queue
  35. $input = 'Input value';
  36. $response = $this->publisher->publish('sync.topic.for.mixed.sync.and.async.queue', $input);
  37. $this->assertEquals($input . ' processed by RPC handler', $response);
  38. $this->waitForAsynchronousResult(count($this->messages), $this->logFilePath);
  39. // Verify that asynchronous messages were processed
  40. foreach ($this->messages as $item) {
  41. $this->assertContains($item, file_get_contents($this->logFilePath));
  42. }
  43. }
  44. }