6666use Patchlevel \EventSourcing \Subscription \Engine \DefaultSubscriptionEngine ;
6767use Patchlevel \EventSourcing \Subscription \Engine \SubscriptionEngine ;
6868use Patchlevel \EventSourcing \Subscription \Repository \RunSubscriptionEngineRepositoryManager ;
69+ use Patchlevel \EventSourcing \Subscription \RetryStrategy \ClockBasedRetryStrategy ;
70+ use Patchlevel \EventSourcing \Subscription \RetryStrategy \NoRetryStrategy ;
71+ use Patchlevel \EventSourcing \Subscription \RetryStrategy \RetryStrategy ;
72+ use Patchlevel \EventSourcing \Subscription \RetryStrategy \RetryStrategyRepository ;
6973use Patchlevel \EventSourcing \Subscription \Store \DoctrineSubscriptionStore ;
7074use Patchlevel \EventSourcing \Subscription \Store \InMemorySubscriptionStore ;
7175use Patchlevel \EventSourcing \Subscription \Store \SubscriptionStore ;
96100use Psr \EventDispatcher \EventDispatcherInterface ;
97101use Psr \Log \LoggerInterface ;
98102use Psr \SimpleCache \CacheInterface ;
99- use stdClass ;
100103use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
101104use Symfony \Component \DependencyInjection \Argument \TaggedIteratorArgument ;
102105use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -1129,8 +1132,7 @@ public function testAutoconfigureArgumentResolver(): void
11291132 $ container = new ContainerBuilder ();
11301133
11311134 $ container ->setDefinition (DummyArgumentResolver::class, new Definition (DummyArgumentResolver::class))
1132- ->setAutoconfigured (true )
1133- ;
1135+ ->setAutoconfigured (true );
11341136
11351137 $ this ->compileContainer (
11361138 $ container ,
@@ -1144,8 +1146,110 @@ public function testAutoconfigureArgumentResolver(): void
11441146 );
11451147
11461148 self ::assertTrue ($ container ->getDefinition (DummyArgumentResolver::class)->hasTag ('event_sourcing.argument_resolver ' ));
1147- self ::assertInstanceOf (TaggedIteratorArgument::class, $ container ->getDefinition (MetadataSubscriberAccessorRepository::class)->getArgument (2 ));
1148- self ::assertEquals ('event_sourcing.argument_resolver ' , $ container ->getDefinition (MetadataSubscriberAccessorRepository::class)->getArgument (2 )->getTag ());
1149+ self ::assertInstanceOf (TaggedIteratorArgument::class,
1150+ $ container ->getDefinition (MetadataSubscriberAccessorRepository::class)->getArgument (2 ));
1151+ self ::assertEquals ('event_sourcing.argument_resolver ' ,
1152+ $ container ->getDefinition (MetadataSubscriberAccessorRepository::class)->getArgument (2 )->getTag ());
1153+ }
1154+
1155+ public function testLegacyRetryStrategy (): void
1156+ {
1157+ $ container = new ContainerBuilder ();
1158+
1159+ $ this ->compileContainer (
1160+ $ container ,
1161+ [
1162+ 'patchlevel_event_sourcing ' => [
1163+ 'connection ' => [
1164+ 'service ' => 'doctrine.dbal.eventstore_connection ' ,
1165+ ],
1166+ 'subscription ' => [
1167+ 'retry_strategy ' => [
1168+ 'base_delay ' => 10 ,
1169+ 'delay_factor ' => 11 ,
1170+ 'max_attempts ' => 12 ,
1171+ ],
1172+ ],
1173+ ],
1174+ ]
1175+ );
1176+
1177+ $ repository = $ container ->get (RetryStrategyRepository::class);
1178+
1179+ self ::assertInstanceOf (RetryStrategyRepository::class, $ repository );
1180+ self ::assertInstanceOf (ClockBasedRetryStrategy::class, $ repository ->getDefaultRetryStrategy ());
1181+ self ::assertInstanceOf (ClockBasedRetryStrategy::class, $ repository ->get ('default ' ));
1182+ self ::assertInstanceOf (NoRetryStrategy::class, $ repository ->get ('no_retry ' ));
1183+ }
1184+
1185+ public function testRetryStrategy (): void
1186+ {
1187+ $ container = new ContainerBuilder ();
1188+
1189+ $ this ->compileContainer (
1190+ $ container ,
1191+ [
1192+ 'patchlevel_event_sourcing ' => [
1193+ 'connection ' => [
1194+ 'service ' => 'doctrine.dbal.eventstore_connection ' ,
1195+ ],
1196+ 'subscription ' => [
1197+ 'retry_strategies ' => [
1198+ 'default ' => [
1199+ 'type ' => 'clock_based ' ,
1200+ 'options ' => [
1201+ 'base_delay ' => 10 ,
1202+ 'delay_factor ' => 11 ,
1203+ 'max_attempts ' => 12 ,
1204+ ],
1205+ ],
1206+ 'no_retry ' => [
1207+ 'type ' => 'no_retry ' ,
1208+ ]
1209+ ]
1210+ ],
1211+ ],
1212+ ]
1213+ );
1214+
1215+ $ repository = $ container ->get (RetryStrategyRepository::class);
1216+
1217+ self ::assertInstanceOf (RetryStrategyRepository::class, $ repository );
1218+ self ::assertInstanceOf (ClockBasedRetryStrategy::class, $ repository ->getDefaultRetryStrategy ());
1219+ self ::assertInstanceOf (ClockBasedRetryStrategy::class, $ repository ->get ('default ' ));
1220+ self ::assertInstanceOf (NoRetryStrategy::class, $ repository ->get ('no_retry ' ));
1221+ }
1222+
1223+ public function testRetryStrategyCustom (): void
1224+ {
1225+ $ retryStrategy = $ this ->prophesize (RetryStrategy::class)->reveal ();
1226+
1227+ $ container = new ContainerBuilder ();
1228+ $ container ->set ('my_retry_strategy ' , $ retryStrategy );
1229+
1230+ $ this ->compileContainer (
1231+ $ container ,
1232+ [
1233+ 'patchlevel_event_sourcing ' => [
1234+ 'connection ' => [
1235+ 'service ' => 'doctrine.dbal.eventstore_connection ' ,
1236+ ],
1237+ 'subscription ' => [
1238+ 'retry_strategies ' => [
1239+ 'default ' => [
1240+ 'type ' => 'custom ' ,
1241+ 'service ' => 'my_retry_strategy '
1242+ ],
1243+ ]
1244+ ],
1245+ ],
1246+ ]
1247+ );
1248+
1249+ $ repository = $ container ->get (RetryStrategyRepository::class);
1250+
1251+ self ::assertInstanceOf (RetryStrategyRepository::class, $ repository );
1252+ self ::assertEquals ($ retryStrategy , $ repository ->getDefaultRetryStrategy ());
11491253 }
11501254
11511255 public function testSchemaMerge (): void
0 commit comments