@Test void testEntityInitializationIsThreadSafe() { for (int i = 0; i < 100; i++) { AggregateModel<PolyMorphAggregate> inspector = AnnotatedAggregateMetaModelFactory.inspectAggregate(PolyMorphAggregate.class); PolyMorphAggregate instance1 = new PolyMorphAggregate(); PolyMorphAggregate instance2 = new PolyMorphAggregate(); AtomicLong counter = new AtomicLong(); ForkJoinTask<?> task1 = ForkJoinPool.commonPool() .submit(() -> inspector.publish(asEventMessage(counter), instance1)); ForkJoinTask<?> task2 = ForkJoinPool.commonPool() .submit(() -> inspector.publish(asEventMessage(counter), instance2)); task1.join(); task2.join(); assertEquals(2, counter.get(), "Concurrency issue detected after " + i + " attempts."); } }
public static <T> AggregateModel<T> inspectAggregate(Class<T> aggregateType) { return new AnnotatedAggregateMetaModelFactory().createModel(aggregateType); }
AnnotatedAggregateMetaModelFactory implements AggregateMetaModelFactory { public static <T> AggregateModel<T> inspectAggregate(Class<T> aggregateType) { return new AnnotatedAggregateMetaModelFactory().createModel(aggregateType); } }
AnnotatedAggregateMetaModelFactory implements AggregateMetaModelFactory { public static <T> AggregateModel<T> inspectAggregate(Class<T> aggregateType) { return new AnnotatedAggregateMetaModelFactory().createModel(aggregateType); } AnnotatedAggregateMetaModelFactory();  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory);  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory,
                                              HandlerDefinition handlerDefinition); }
AnnotatedAggregateMetaModelFactory implements AggregateMetaModelFactory { public static <T> AggregateModel<T> inspectAggregate(Class<T> aggregateType) { return new AnnotatedAggregateMetaModelFactory().createModel(aggregateType); } AnnotatedAggregateMetaModelFactory();  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory);  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory,
                                              HandlerDefinition handlerDefinition); static AggregateModel<T> inspectAggregate(Class<T> aggregateType); static AggregateModel<T> inspectAggregate(Class<T> aggregateType, Set<Class<? extends T>> subtypes); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory,
                                                         HandlerDefinition handlerDefinition); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory,
                                                         HandlerDefinition handlerDefinition,
                                                         Set<Class<? extends T>> subtypes); @Override AnnotatedAggregateModel<T> createModel(Class<? extends T> aggregateType,
                                                      Set<Class<? extends T>> subtypes); }
AnnotatedAggregateMetaModelFactory implements AggregateMetaModelFactory { public static <T> AggregateModel<T> inspectAggregate(Class<T> aggregateType) { return new AnnotatedAggregateMetaModelFactory().createModel(aggregateType); } AnnotatedAggregateMetaModelFactory();  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory);  AnnotatedAggregateMetaModelFactory(ParameterResolverFactory parameterResolverFactory,
                                              HandlerDefinition handlerDefinition); static AggregateModel<T> inspectAggregate(Class<T> aggregateType); static AggregateModel<T> inspectAggregate(Class<T> aggregateType, Set<Class<? extends T>> subtypes); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory,
                                                         HandlerDefinition handlerDefinition); static AggregateModel<T> inspectAggregate(Class<T> aggregateType,
                                                         ParameterResolverFactory parameterResolverFactory,
                                                         HandlerDefinition handlerDefinition,
                                                         Set<Class<? extends T>> subtypes); @Override AnnotatedAggregateModel<T> createModel(Class<? extends T> aggregateType,
                                                      Set<Class<? extends T>> subtypes);  }