/**
  * @param array $data
  * @return array
  */
 public function run(array $data)
 {
     switch ($data['adapter']) {
         case 'mysql':
             $connection = DriverManager::getConnection($data['options']);
             $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             $adapter = new DoctrineEventStoreAdapter($connection, new FQCNMessageFactory(), new NoOpMessageConverter(), new JsonPayloadSerializer());
             break;
         case 'postgres':
             $connection = DriverManager::getConnection($data['options']);
             $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             $adapter = new DoctrineEventStoreAdapter($connection, new FQCNMessageFactory(), new NoOpMessageConverter(), new JsonPayloadSerializer());
             break;
         case 'mongodb':
             $connection = new \MongoClient($data['options']['server']);
             $connection->selectDB('event_store_adapter_benchmarks')->selectCollection('user_stream')->drop();
             $adapter = new MongoDbEventStoreAdapter(new FQCNMessageFactory(), new NoOpMessageConverter(), $connection, $data['options']['db_name']);
             break;
         default:
             throw new \InvalidArgumentException('invalid adapter given');
             break;
     }
     $eventStore = new EventStore($adapter, new ProophActionEventEmitter());
     $result = [];
     foreach ($data['batchSizes'] as $batchSize) {
         for ($i = 0; $i < $this->repeats; $i++) {
             $events = [];
             $start = microtime(true);
             for ($b = 1; $b <= $batchSize * 2; $b++) {
                 $v1 = $b;
                 $b++;
                 $v2 = $b;
                 $events[] = UserCreated::with(['name' => 'Max Mustermann ' . $i . '-' . $b, 'email' => 'contact' . $i . '-' . $b . '@prooph.de'], $v1);
                 $events[] = UsernameChanged::with(['name' => 'John Doe ' . $i . '-' . $b], $v2);
             }
             $eventStore->beginTransaction();
             $eventStore->create(new Stream(new StreamName('user_stream'), new \ArrayIterator($events)));
             $eventStore->commit();
             $end = microtime(true);
             if ($connection instanceof Connection) {
                 $connection->executeQuery('DROP TABLE IF EXISTS user_stream');
             } else {
                 $connection->selectDB('event_store_adapter_benchmarks')->selectCollection('user_stream')->drop();
             }
             $diff = $end - $start;
             $result[$data['adapter'] . ' with batch size ' . $batchSize] = $diff;
         }
     }
     return $result;
 }
 */
require __DIR__ . '/../vendor/autoload.php';
use Prooph\Common\Event\ProophActionEventEmitter;
use Prooph\Common\Messaging\FQCNMessageFactory;
use Prooph\Common\Messaging\NoOpMessageConverter;
use Prooph\EventStore\Adapter\Flywheel\FlywheelEventStoreAdapter;
use Prooph\EventStore\EventStore;
use Prooph\EventStore\Stream\Stream;
use Prooph\EventStore\Stream\StreamName;
use ProophTest\EventStore\Mock\UserCreated;
use ProophTest\EventStore\Mock\UsernameChanged;
$rootDir = __DIR__ . '/event_store';
$adapter = new FlywheelEventStoreAdapter($rootDir, new FQCNMessageFactory(), new NoOpMessageConverter());
$actionEmitter = new ProophActionEventEmitter();
$eventStore = new EventStore($adapter, $actionEmitter);
$streamName = new StreamName('event_stream');
$stream = new Stream($streamName, new \ArrayIterator([]));
//
// Persist some events in the event store
//
$eventStore->beginTransaction();
$eventStore->create($stream);
$eventStore->appendTo($streamName, new \ArrayIterator([UserCreated::with(['name' => 'Max Mustermann'], 1)->withAddedMetadata('tag', 'person'), UsernameChanged::with(['name' => 'John Doe'], 2)->withAddedMetadata('tag', 'person')]));
$eventStore->commit();
//
// Load all the stored events
//
$persistedEventStream = $eventStore->load($streamName);
foreach ($persistedEventStream->streamEvents() as $event) {
    echo $event->payload()['name'] . PHP_EOL;
}
 /**
  * @return Stream
  */
 private function getTestStream()
 {
     $streamEvent = UserCreated::with(['name' => 'Alex', 'email' => '*****@*****.**'], 1);
     return new Stream(new StreamName('user'), new ArrayIterator([$streamEvent]));
 }
 /**
  * @return Stream
  */
 private function createStream()
 {
     $streamEvent = UserCreated::withPayloadAndSpecifiedCreatedAt(['name' => 'Max Mustermann', 'email' => '*****@*****.**'], 1, new \DateTimeImmutable('30 seconds ago', new \DateTimeZone('UTC')));
     $streamEvent = $streamEvent->withAddedMetadata('tag', 'person');
     return new Stream(new StreamName('user_stream'), new \ArrayIterator([$streamEvent]));
 }
 /**
  * @return Stream
  */
 private function getTestStream()
 {
     $streamEvent = UserCreated::with(['name' => 'Max Mustermann', 'email' => '*****@*****.**'], 1);
     $streamEvent = $streamEvent->withAddedMetadata('tag', 'person');
     return new Stream(new StreamName('Prooph\\Model\\User'), new \ArrayIterator([$streamEvent]));
 }