protected override void DoSetUp() { _seqNos.Clear(); var database = MongoHelper.InitializeTestDatabase(); _source = new MongoDbEventStore(database, "EventSrc"); _destination = new MongoDbEventStore(database, "EventDst"); _replicator = new EventReplicator(_source, _destination); RegisterForDisposal(_replicator); _replicator.Start(); }
protected override void DoSetUp() { CirqusLoggerFactory.Current = new ConsoleLoggerFactory(Logger.Level.Warn); var mongoDatabase = MongoHelper.InitializeTestDatabase(); var aalborgEventStore = new MongoDbEventStore(mongoDatabase, "AalborgEvents"); var hongKongEventStore = new MongoDbEventStore(mongoDatabase, "HongKongEvents"); CreateCommandProcessor(aalborgEventStore, aalborgEventStore); _hongKongViewManager = new MongoDbViewManager<CountingRootView>(mongoDatabase); _hongKongCommandProcessor = CreateCommandProcessor(aalborgEventStore, hongKongEventStore, _hongKongViewManager); var replicationDelay = TimeSpan.FromSeconds(5); CreateAndStartReplication(aalborgEventStore, hongKongEventStore, replicationDelay); }
public void IndexSpeedTest(bool useIndexes, int numberOfQueries, int numberOfEvents) { var sequenceNumbers = new Dictionary<string, long>(); var serializer = new JsonDomainEventSerializer(); try { var database = MongoHelper.InitializeTestDatabase(); database.Drop(); var eventStore = new MongoDbEventStore(database, "events", automaticallyCreateIndexes: useIndexes); var random = new Random(DateTime.Now.GetHashCode()); var aggregateRootIds = Enumerable.Range(0, 1000).Select(i => i.ToString()).ToArray(); Func<string, long> getNextSequenceNumber = id => !sequenceNumbers.ContainsKey(id) ? (sequenceNumbers[id] = 0) : ++sequenceNumbers[id]; Func<string> randomAggregateRootId = () => aggregateRootIds[random.Next(aggregateRootIds.Length)]; var events = Enumerable.Range(1, numberOfEvents) .Select(i => Event(getNextSequenceNumber, randomAggregateRootId())) .ToList(); TakeTime("Insert " + events.Count + " events", () => { foreach (var e in events) { eventStore.Save(Guid.NewGuid(), new[] { serializer.Serialize(e) }); } }); TakeTime("Execute " + numberOfQueries + " queries", () => numberOfQueries.Times(() => eventStore.Load(randomAggregateRootId()).ToList())); } finally { Console.WriteLine(@"This is how far we got: {0}", string.Join(Environment.NewLine, sequenceNumbers.Select(kvp => string.Format(" {0}: {1}", kvp.Key, kvp.Value)))); } }
protected override void DoSetUp() { _listLoggerFactory = new ListLoggerFactory(); CirqusLoggerFactory.Current = _listLoggerFactory; _seqNos.Clear(); var database = MongoHelper.InitializeTestDatabase(); _source = new MongoDbEventStore(database, "EventSrc"); _destination = new MongoDbEventStore(database, "EventDst"); var source = new ThrowsAnErrorOnceInAWhile(_source, 0.5); var destination = new ThrowsAnErrorOnceInAWhile(_destination, 0.5); _replicator = new EventReplicator(source, destination) { TimeToPauseOnError = TimeSpan.Zero //< don't wait in this test }; RegisterForDisposal(_replicator); _replicator.Start(); }
void SaveEvents(int numberOfCommandsToProcess, string aggregateRootId) { var eventStore = new MongoDbEventStore(_database, "Events"); var serializer = new JsonDomainEventSerializer(); var typeNameMapper = new DefaultDomainTypeNameMapper(); Enumerable.Range(0, numberOfCommandsToProcess) .ToList() .ForEach(number => { var domainEvents = new[] { new RootGotNewNumber(number) { Meta = { {DomainEvent.MetadataKeys.AggregateRootId, aggregateRootId}, {DomainEvent.MetadataKeys.SequenceNumber, number.ToString()}, {DomainEvent.MetadataKeys.TimeUtc, Time.UtcNow().ToString("u")}, {DomainEvent.MetadataKeys.Type, typeNameMapper.GetName(typeof(RootGotNewNumber))}, {DomainEvent.MetadataKeys.Owner, typeNameMapper.GetName(typeof(Root))}, } } }; eventStore.Save(Guid.NewGuid(), domainEvents.Select(e => serializer.Serialize(e))); }); }
CommandProcessingResult GetLastResult() { var eventStore = new MongoDbEventStore(_database, "Events"); var nextGlobalSequenceNumber = eventStore.GetNextGlobalSequenceNumber(); var lastGlobalSequenceNumber = nextGlobalSequenceNumber - 1; return CommandProcessingResult.WithNewPosition(lastGlobalSequenceNumber); }
public MongoDbEventStoreFactory() { _eventStore = new MongoDbEventStore(MongoHelper.InitializeTestDatabase(), "events"); }
protected override void DoSetUp() { _mongoDatabase = MongoHelper.InitializeTestDatabase(); _eventStore = new MongoDbEventStore(_mongoDatabase, "Events"); }