Skip to content

Commit 4b41855

Browse files
committed
Add noop test
1 parent 30220c6 commit 4b41855

3 files changed

Lines changed: 139 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: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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\Processor\SendEmailProcessor;
23+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Profile;
24+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
25+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\NoopProjector;
26+
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\ProfileProjector;
27+
use Patchlevel\EventSourcing\Tests\DbalManager;
28+
use PhpBench\Attributes as Bench;
29+
30+
#[Bench\BeforeMethods('setUp')]
31+
final class NoopSubscriptionEngineBench
32+
{
33+
private Store $store;
34+
private Repository $repository;
35+
36+
private SubscriptionEngine $subscriptionEngine;
37+
38+
private AggregateRootId $id;
39+
40+
public function setUp(): void
41+
{
42+
$connection = DbalManager::createConnection();
43+
44+
$this->store = new DoctrineDbalStore(
45+
$connection,
46+
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
47+
);
48+
49+
$this->repository = new DefaultRepository($this->store, Profile::metadata());
50+
51+
$subscriptionStore = new DoctrineSubscriptionStore($connection);
52+
53+
$schemaDirector = new DoctrineSchemaDirector(
54+
$connection,
55+
new ChainDoctrineSchemaConfigurator([
56+
$this->store,
57+
$subscriptionStore,
58+
]),
59+
);
60+
61+
$schemaDirector->create();
62+
63+
$this->id = ProfileId::generate();
64+
65+
$profile = Profile::create($this->id, 'Peter');
66+
67+
for ($i = 1; $i <= 10_000; $i++) {
68+
$profile->changeEmail('peter' . $i . '@example.com');
69+
$profile->changeName('Peter ' . $i);
70+
}
71+
72+
$this->repository->save($profile);
73+
74+
$subscriberAccessorRepository = new MetadataSubscriberAccessorRepository(
75+
[
76+
new NoopProjector(),
77+
],
78+
);
79+
80+
$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
81+
new EventFilteredStoreMessageLoader(
82+
$this->store,
83+
new AttributeEventMetadataFactory(),
84+
$subscriberAccessorRepository,
85+
),
86+
$subscriptionStore,
87+
$subscriberAccessorRepository,
88+
));
89+
}
90+
91+
#[Bench\Revs(10)]
92+
public function benchHandle10000Events(): void
93+
{
94+
$this->subscriptionEngine->setup();
95+
$this->subscriptionEngine->boot();
96+
$this->subscriptionEngine->remove();
97+
}
98+
}

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)