-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from aligent/feature/remove-batchdatamapper-hack
Remove plugin hack
- Loading branch information
Showing
8 changed files
with
160 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
|
||
namespace Aligent\AsyncEvents\Test\Integration; | ||
|
||
use Aligent\AsyncEvents\Helper\QueueMetadataInterface; | ||
use Aligent\AsyncEvents\Model\Config; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\Framework\MessageQueue\PublisherInterface; | ||
use Magento\Framework\Serialize\Serializer\Json; | ||
use Magento\TestFramework\Helper\Amqp; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\TestFramework\MessageQueue\EnvironmentPreconditionException; | ||
use Magento\TestFramework\MessageQueue\PreconditionFailedException; | ||
use Magento\TestFramework\MessageQueue\PublisherConsumerController; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class EventRetryTest extends TestCase | ||
{ | ||
/** @var Amqp|null */ | ||
private ?Amqp $helper; | ||
|
||
/** @var PublisherInterface|null */ | ||
private ?PublisherInterface $publisher; | ||
|
||
/** @var PublisherConsumerController|null */ | ||
private ?PublisherConsumerController $publisherConsumerController; | ||
|
||
/** @var Json|null */ | ||
private ?Json $json; | ||
|
||
protected function setUp(): void | ||
{ | ||
Bootstrap::getObjectManager()->configure([ | ||
'preferences' => [ | ||
Config::class => TestConfig::class | ||
] | ||
]); | ||
|
||
$this->helper = Bootstrap::getObjectManager()->create(Amqp::class); | ||
$this->publisher = Bootstrap::getObjectManager()->create(PublisherInterface::class); | ||
$this->json = Bootstrap::getObjectManager()->create(Json::class); | ||
$this->connection = Bootstrap::getObjectManager()->get(ResourceConnection::class); | ||
|
||
if (!$this->helper->isAvailable()) { | ||
$this->fail('This test relies on RabbitMQ Management Plugin.'); | ||
} | ||
} | ||
|
||
/** | ||
* Test event retries | ||
* | ||
* Disable database isolation because the transactions need to be committed so that the consumer can | ||
* retrieve the subscriptions from database in a separate consumer process. | ||
* | ||
* @magentoDataFixture Aligent_AsyncEvents::Test/_files/http_async_events.php | ||
* @magentoDbIsolation disabled | ||
* @magentoConfigFixture default/system/async_events/max_deaths 3 | ||
*/ | ||
public function testRetry() | ||
{ | ||
$this->publisher->publish( | ||
QueueMetadataInterface::EVENT_QUEUE, | ||
[ | ||
'example.event', | ||
$this->json->serialize([ | ||
'countryId' => 'AU' | ||
]), | ||
] | ||
); | ||
|
||
$this->publisherConsumerController = Bootstrap::getObjectManager()->create( | ||
PublisherConsumerController::class, | ||
[ | ||
'consumers' => ['event.trigger.consumer', 'event.retry.consumer'], | ||
'logFilePath' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt", | ||
'maxMessages' => 10, | ||
'appInitParams' => Bootstrap::getInstance()->getAppInitParams() | ||
] | ||
); | ||
|
||
try { | ||
$this->publisherConsumerController->startConsumers(); | ||
sleep(16); | ||
} catch (EnvironmentPreconditionException $e) { | ||
$this->markTestSkipped($e->getMessage()); | ||
} catch (PreconditionFailedException $e) { | ||
$this->fail( | ||
$e->getMessage() | ||
); | ||
} finally { | ||
$this->publisherConsumerController->stopConsumers(); | ||
} | ||
|
||
$table = $this->connection->getTableName('async_event_subscriber_log'); | ||
$connection = $this->connection->getConnection(); | ||
$select = $connection->select() | ||
->from($table, 'uuid') | ||
->columns(['events' => new \Zend_Db_Expr('COUNT(*)')]) | ||
->group('uuid'); | ||
|
||
$events = $connection->fetchAll($select); | ||
|
||
foreach ($events as $event) { | ||
// An uuid batch should be retired for 3 times after the first attempt. 1 + 3 | ||
$this->assertEquals(4, $event['events']); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Aligent\AsyncEvents\Test\Integration; | ||
|
||
use Aligent\AsyncEvents\Model\Config; | ||
use Magento\Directory\Api\CountryInformationAcquirerInterface; | ||
|
||
class TestConfig extends Config | ||
{ | ||
public function get(string $key): array | ||
{ | ||
return [ | ||
"class" => CountryInformationAcquirerInterface::class, | ||
"method" => "getCountryInfo", | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
<?php | ||
|
||
use Aligent\AsyncEvents\Api\Data\AsyncEventInterface; | ||
use Aligent\AsyncEvents\Api\Data\AsyncEventInterfaceFactory; | ||
use Magento\Framework\App\ResourceConnection; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
|
||
$asyncEventFactory = $objectManager->get(AsyncEventInterfaceFactory::class); | ||
$resource = $objectManager->get(ResourceConnection::class); | ||
$connection = $resource->getConnection(); | ||
|
||
$asyncEventRepository = $objectManager->get(\Aligent\AsyncEvents\Api\AsyncEventRepositoryInterface::class); | ||
|
||
/** @var AsyncEventInterface $asyncEvent */ | ||
$asyncEvent = $asyncEventFactory->create( | ||
[ | ||
'data' => [ | ||
'event' => 'example.event', | ||
'recipient_url' => 'http://host.docker.internal:3001/failable', | ||
'verification_token' => 'supersecret', | ||
'status' => 1 | ||
] | ||
] | ||
); | ||
$asyncEvent->setEventName('example.event'); | ||
$asyncEventRepository->save($asyncEvent); | ||
$connection->insertOnDuplicate('async_event_subscriber', [ | ||
'subscription_id' => 1, | ||
'event_name' => 'example.event', | ||
'recipient_url' => 'https://mock.codes/500', | ||
'status' => 1, | ||
'metadata' => 'http', | ||
'verification_token' => 'secret', | ||
'subscribed_at' => (new DateTime())->format(DateTimeInterface::ATOM) | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters