static void Main(string[] args) { var repoType = eRepositoryType.AzureBlob; if (args.Length > 0) { if (args[0].Equals("sql", StringComparison.OrdinalIgnoreCase)) { repoType = eRepositoryType.Sql; } } var eventsPerAggregate = 10; var aggregatesToMake = 10; if (args.Length > 1) { aggregatesToMake = Convert.ToInt32(args[1]); } var history = new ConcurrentBag <Tuple <Guid, ConcurrentBag <int> > >(); var startTime = DateTime.UtcNow; var options = new ParallelOptions() { MaxDegreeOfParallelism = Math.Min(15, aggregatesToMake / 5 + 5) }; Parallel.For(0, aggregatesToMake, options, (i) => { var aggregateId = Guid.NewGuid(); var values = new ConcurrentBag <int>(); Stopwatch sw = new Stopwatch(); sw.Start(); var repo = new TestRepository(repoType); Stopwatch creationTimer = new Stopwatch(); creationTimer.Start(); values.Add(42); Thread.Sleep(new Random().Next(0, 1000)); var aggy = SimpleAggregate.CreateNew(DateTime.Now, aggregateId, 42); while (true) { try { _log.Trace("TRYING TO CREATE AGG WITH ID [{0}]", aggy.Id); repo.Save(aggy, Guid.NewGuid(), null); break; } catch (Exception ex) { _log.Error(string.Format("Will retry, but failed to create aggregate with id [{0}], [{1}]", aggy.Id, ex.Message)); } } creationTimer.Stop(); _log.Trace("Created aggy in [{0}]", creationTimer.Elapsed); Random random = new Random(); var commitOptions = new ParallelOptions() { MaxDegreeOfParallelism = 10 }; Parallel.For(0, eventsPerAggregate, options, (j) => { try { values.Add(RetryWhileConcurrent(repoType, aggy.Id, j)); } catch (Exception ex) { _log.Error("error iteration {0}-{1}, {2}", i, j, ex.ToString()); } }); SnapshotAggregate(repoType, aggy.Id); // now add some more stuff... this will be used to verify our snapshot is working as expected Parallel.For(0, eventsPerAggregate, options, (j) => { try { values.Add(RetryWhileConcurrent(repoType, aggy.Id, j)); } catch (Exception ex) { _log.Error("error iteration {0}-{1}, {2}", i, j, ex.ToString()); } }); history.Add(new Tuple <Guid, ConcurrentBag <int> >(aggregateId, values)); _log.Trace(string.Format("Iteration [{0}] took me [{1}] ms", i, sw.ElapsedMilliseconds)); }); var totalTime = DateTime.UtcNow.Subtract(startTime); _log.Info("checking aggregates for errors"); Parallel.ForEach(history, (historyItem) => { var repository = new TestRepository(repoType); CheckAggregate(repository, historyItem.Item1, historyItem.Item2); }); _log.Info("Took [{0}] to source all aggregates", totalTime); }