Skip to content

Commit 1d1e5b9

Browse files
committed
Add noop test
1 parent 30220c6 commit 1d1e5b9

3 files changed

Lines changed: 137 additions & 6 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection;
6+
7+
use Patchlevel\EventSourcing\Attribute\Projector;
8+
use Patchlevel\EventSourcing\Attribute\Setup;
9+
use Patchlevel\EventSourcing\Attribute\Subscribe;
10+
use Patchlevel\EventSourcing\Attribute\Teardown;
11+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\NameChanged;
12+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Events\ProfileCreated;
13+
14+
#[Projector('noop_profile')]
15+
final class NoopProjector
16+
{
17+
#[Setup]
18+
public function create(): void
19+
{
20+
}
21+
22+
#[Teardown]
23+
public function drop(): void
24+
{
25+
}
26+
27+
#[Subscribe(ProfileCreated::class)]
28+
public function onProfileCreated(ProfileCreated $profileCreated): void
29+
{
30+
}
31+
32+
#[Subscribe(NameChanged::class)]
33+
public function onNameChanged(NameChanged $nameChanged): void
34+
{
35+
}
36+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\EventSourcing\Tests\Benchmark;
6+
7+
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
8+
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory;
9+
use Patchlevel\EventSourcing\Repository\DefaultRepository;
10+
use Patchlevel\EventSourcing\Repository\Repository;
11+
use Patchlevel\EventSourcing\Schema\ChainDoctrineSchemaConfigurator;
12+
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
13+
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
14+
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
15+
use Patchlevel\EventSourcing\Store\Store;
16+
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
17+
use Patchlevel\EventSourcing\Subscription\Engine\EventFilteredStoreMessageLoader;
18+
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
19+
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
20+
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
21+
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
22+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Profile;
23+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
24+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\NoopProjector;
25+
use Patchlevel\EventSourcing\Tests\DbalManager;
26+
use PhpBench\Attributes as Bench;
27+
28+
#[Bench\BeforeMethods('setUp')]
29+
final class NoopSubscriptionEngineBench
30+
{
31+
private Store $store;
32+
private Repository $repository;
33+
34+
private SubscriptionEngine $subscriptionEngine;
35+
36+
private AggregateRootId $id;
37+
38+
public function setUp(): void
39+
{
40+
$connection = DbalManager::createConnection();
41+
42+
$this->store = new DoctrineDbalStore(
43+
$connection,
44+
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
45+
);
46+
47+
$this->repository = new DefaultRepository($this->store, Profile::metadata());
48+
49+
$subscriptionStore = new DoctrineSubscriptionStore($connection);
50+
51+
$schemaDirector = new DoctrineSchemaDirector(
52+
$connection,
53+
new ChainDoctrineSchemaConfigurator([
54+
$this->store,
55+
$subscriptionStore,
56+
]),
57+
);
58+
59+
$schemaDirector->create();
60+
61+
$this->id = ProfileId::generate();
62+
63+
$profile = Profile::create($this->id, 'Peter');
64+
65+
for ($i = 1; $i <= 10_000; $i++) {
66+
$profile->changeEmail('peter' . $i . '@example.com');
67+
$profile->changeName('Peter ' . $i);
68+
}
69+
70+
$this->repository->save($profile);
71+
72+
$subscriberAccessorRepository = new MetadataSubscriberAccessorRepository(
73+
[
74+
new NoopProjector(),
75+
],
76+
);
77+
78+
$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
79+
new EventFilteredStoreMessageLoader(
80+
$this->store,
81+
new AttributeEventMetadataFactory(),
82+
$subscriberAccessorRepository,
83+
),
84+
$subscriptionStore,
85+
$subscriberAccessorRepository,
86+
));
87+
}
88+
89+
#[Bench\Revs(10)]
90+
public function benchHandle10000Events(): void
91+
{
92+
$this->subscriptionEngine->setup();
93+
$this->subscriptionEngine->boot();
94+
$this->subscriptionEngine->remove();
95+
}
96+
}

tests/Benchmark/SubscriptionEngineBench.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
1717
use Patchlevel\EventSourcing\Subscription\Engine\EventFilteredStoreMessageLoader;
1818
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
19+
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
1920
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
2021
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
2122
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor\SendEmailProcessor;
@@ -46,9 +47,7 @@ public function setUp(): void
4647

4748
$this->repository = new DefaultRepository($this->store, Profile::metadata());
4849

49-
$subscriptionStore = new DoctrineSubscriptionStore(
50-
$connection,
51-
);
50+
$subscriptionStore = new DoctrineSubscriptionStore($connection);
5251

5352
$schemaDirector = new DoctrineSchemaDirector(
5453
$connection,
@@ -64,7 +63,7 @@ public function setUp(): void
6463

6564
$profile = Profile::create($this->id, 'Peter');
6665

67-
for ($i = 1; $i < 10_000; $i++) {
66+
for ($i = 1; $i <= 10_000; $i++) {
6867
$profile->changeEmail('peter' . $i . '@example.com');
6968
$profile->changeName('Peter ' . $i);
7069
}
@@ -78,15 +77,15 @@ public function setUp(): void
7877
],
7978
);
8079

81-
$this->subscriptionEngine = new DefaultSubscriptionEngine(
80+
$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
8281
new EventFilteredStoreMessageLoader(
8382
$this->store,
8483
new AttributeEventMetadataFactory(),
8584
$subscriberAccessorRepository,
8685
),
8786
$subscriptionStore,
8887
$subscriberAccessorRepository,
89-
);
88+
));
9089
}
9190

9291
#[Bench\Revs(10)]

0 commit comments

Comments
 (0)