-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSubscriptionEngineBench.php
More file actions
98 lines (79 loc) · 3.48 KB
/
Copy pathSubscriptionEngineBench.php
File metadata and controls
98 lines (79 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
declare(strict_types=1);
namespace Patchlevel\EventSourcing\Tests\Benchmark;
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\ChainDoctrineSchemaConfigurator;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Store\Store;
use Patchlevel\EventSourcing\Subscription\Engine\DefaultSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\EventFilteredStoreMessageLoader;
use Patchlevel\EventSourcing\Subscription\Engine\SubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Engine\ThrowOnErrorSubscriptionEngine;
use Patchlevel\EventSourcing\Subscription\Store\DoctrineSubscriptionStore;
use Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessorRepository;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Processor\SendEmailProcessor;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Profile;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\ProfileId;
use Patchlevel\EventSourcing\Tests\Benchmark\BasicImplementation\Projection\ProfileProjector;
use Patchlevel\EventSourcing\Tests\DbalManager;
use PhpBench\Attributes as Bench;
#[Bench\BeforeMethods('setUp')]
final class SubscriptionEngineBench
{
private Store $store;
private Repository $repository;
private SubscriptionEngine $subscriptionEngine;
private AggregateRootId $id;
public function setUp(): void
{
$connection = DbalManager::createConnection();
$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
);
$this->repository = new DefaultRepository($this->store, Profile::metadata());
$subscriptionStore = new DoctrineSubscriptionStore($connection);
$schemaDirector = new DoctrineSchemaDirector(
$connection,
new ChainDoctrineSchemaConfigurator([
$this->store,
$subscriptionStore,
]),
);
$schemaDirector->create();
$this->id = ProfileId::generate();
$profile = Profile::create($this->id, 'Peter');
for ($i = 1; $i <= 10_000; $i++) {
$profile->changeEmail('peter' . $i . '@example.com');
$profile->changeName('Peter ' . $i);
}
$this->repository->save($profile);
$subscriberAccessorRepository = new MetadataSubscriberAccessorRepository(
[
new ProfileProjector($connection),
new SendEmailProcessor(),
],
);
$this->subscriptionEngine = new ThrowOnErrorSubscriptionEngine(new DefaultSubscriptionEngine(
new EventFilteredStoreMessageLoader(
$this->store,
new AttributeEventMetadataFactory(),
$subscriberAccessorRepository,
),
$subscriptionStore,
$subscriberAccessorRepository,
));
}
#[Bench\Revs(10)]
public function benchHandle10000Events(): void
{
$this->subscriptionEngine->setup();
$this->subscriptionEngine->boot();
$this->subscriptionEngine->remove();
}
}