Skip to content

Commit

Permalink
After first polling projection, module stops registering (#142)
Browse files Browse the repository at this point in the history
After first polling projection, module stops registering and other polling were not registered anymore. Resolves #141
  • Loading branch information
unixslayer authored Jun 5, 2023
1 parent bfe7874 commit 0319d14
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private function registerProjections(ServiceConfiguration $serviceConfiguration,
->withEndpointId($projectionSetupConfiguration->getProjectionName())
);

return;
continue;
}

/** Projection will be called sync or async triggered by Event Bus. In that case we need to connect them to event related channels */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Test\Ecotone\EventSourcing\Fixture\ProductsProjection;

use Ecotone\EventSourcing\Attribute\Projection;
use Ecotone\Modelling\Attribute\EventHandler;
use Ecotone\Modelling\Attribute\QueryHandler;
use Test\Ecotone\EventSourcing\Fixture\Basket\Basket;
use Test\Ecotone\EventSourcing\Fixture\Basket\Event\ProductWasAddedToBasket;

#[Projection(self::PROJECTION_NAME, Basket::BASKET_STREAM)]
final class Products
{
public const PROJECTION_NAME = 'products';
private array $products = [];

#[EventHandler(ProductWasAddedToBasket::EVENT_NAME)]
public function when(ProductWasAddedToBasket $event): void
{
if (array_key_exists($event->getProductName(), $this->products)) {
++$this->products[$event->getProductName()];
}
$this->products[$event->getProductName()] = 1;
}

#[QueryHandler('getALlProducts')]
public function getAllProducts(): array
{
return $this->products;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Test\Ecotone\EventSourcing\Fixture\ProductsProjection;

use Ecotone\EventSourcing\ProjectionRunningConfiguration;
use Ecotone\Messaging\Attribute\ServiceContext;
use Ecotone\Messaging\Endpoint\PollingMetadata;

final class ProductsConfiguration
{
#[ServiceContext]
public function setMaximumOneRunForProjections(): PollingMetadata
{
return PollingMetadata::create(Products::PROJECTION_NAME)
->setExecutionAmountLimit(3)
->setExecutionTimeLimitInMilliseconds(300);
}

#[ServiceContext]
public function enablePollingProjection(): ProjectionRunningConfiguration
{
return ProjectionRunningConfiguration::createPolling(Products::PROJECTION_NAME);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
use Ecotone\Lite\EcotoneLite;
use Ecotone\Messaging\Config\ServiceConfiguration;
use Ecotone\Messaging\Endpoint\ExecutionPollingMetadata;
use Ecotone\Messaging\Endpoint\PollingMetadata;
use PHPUnit\Framework\TestCase;
use Test\Ecotone\EventSourcing\Fixture\Basket\BasketEventConverter;
use Test\Ecotone\EventSourcing\Fixture\Basket\Command\AddProduct;
use Test\Ecotone\EventSourcing\Fixture\Basket\Command\CreateBasket;
use Test\Ecotone\EventSourcing\Fixture\BasketListProjection\BasketList;
use Test\Ecotone\EventSourcing\Fixture\BasketListProjection\BasketListConfiguration;
use Test\Ecotone\EventSourcing\Fixture\ProductsProjection\Products;
use Test\Ecotone\EventSourcing\Fixture\ProductsProjection\ProductsConfiguration;

final class PollingProjectionTest extends TestCase
{
public function test_running_polling_projection(): void
{
$ecotoneLite = EcotoneLite::bootstrapFlowTestingWithEventStore(
classesToResolve: [BasketListConfiguration::class, BasketList::class],
containerOrAvailableServices: [new BasketList(), new BasketEventConverter()],
classesToResolve: [BasketListConfiguration::class, BasketList::class, ProductsConfiguration::class, Products::class],
containerOrAvailableServices: [new BasketList(), new Products(), new BasketEventConverter()],
configuration: ServiceConfiguration::createWithDefaults()
->withNamespaces(['Test\Ecotone\EventSourcing\Fixture\Basket']),
pathToRootCatalog: __DIR__ . '/../../'
Expand All @@ -31,10 +32,14 @@ classesToResolve: [BasketListConfiguration::class, BasketList::class],
$ecotoneLite->run(BasketList::PROJECTION_NAME, ExecutionPollingMetadata::createWithTestingSetup(maxExecutionTimeInMilliseconds: 1000));

self::assertEquals(['1000' => []], $ecotoneLite->sendQueryWithRouting('getALlBaskets'));
self::assertEquals([], $ecotoneLite->sendQueryWithRouting('getALlProducts'));

$ecotoneLite->sendCommand(new AddProduct('1000', 'milk'));

$ecotoneLite->run(BasketList::PROJECTION_NAME, ExecutionPollingMetadata::createWithTestingSetup(maxExecutionTimeInMilliseconds: 1000));
$ecotoneLite->run(Products::PROJECTION_NAME, ExecutionPollingMetadata::createWithTestingSetup(maxExecutionTimeInMilliseconds: 1000));

self::assertEquals(['1000' => ['milk']], $ecotoneLite->sendQueryWithRouting('getALlBaskets'));
self::assertEquals(['milk' => 1], $ecotoneLite->sendQueryWithRouting('getALlProducts'));
}
}

0 comments on commit 0319d14

Please sign in to comment.