public void CompositeIsDefault() { var config = EngineConfiguration.Create(); var strategy = config.CreateRolloverStrategy(); Assert.IsInstanceOf <CompositeRolloverStrategy>(strategy); }
public void RolledBackCommandsAreSkipped(Tuple <List <JournalEntry>, string> testCase) { ICommandStore target = new InMemoryCommandStore(EngineConfiguration.Create().ForIsolatedTest()); string failureMessage = testCase.Item2; var testEntries = testCase.Item1; //Act var actualCommandEntries = CommandStore.CommittedCommandEntries(() => testEntries).ToArray(); ulong[] rolledBackIds = testEntries.OfType <JournalEntry <RollbackMarker> >().Select(e => e.Id).ToArray(); int expectedNumberOfCommandEntries = testEntries.Count - rolledBackIds.Length * 2; //Assert Assert.AreEqual(expectedNumberOfCommandEntries, actualCommandEntries.Length, failureMessage); ulong sequentialId = 1; foreach (JournalEntry <Command> journalEntry in actualCommandEntries) { if (!rolledBackIds.Contains(sequentialId)) { //TODO: Maybe we should return no-op commands instead of skipping rolled back ulong expectedId = sequentialId + (ulong)rolledBackIds.Count(id => id < journalEntry.Id); Assert.AreEqual(expectedId, journalEntry.Id, failureMessage); } sequentialId++; } }
public void Engine_self_configures_for_immutability_model() { var config = EngineConfiguration.Create().ForImmutability(); Assert.AreEqual(Kernels.Immutability, config.Kernel); Assert.AreEqual(SynchronizationMode.None, config.Synchronization); }
public void RevisionIsIncrementedWithEachCommand() { var config = EngineConfiguration.Create().ForIsolatedTest(); var target = Db.For <TestModel>(config); Assert.AreEqual(0, target.Revision); target.AddCustomer("Homer"); Assert.AreEqual(1, target.Revision); }
public void Corrupting_command_effects_ignored() { var config = EngineConfiguration.Create().ForIsolatedTest(); config.Kernel = Kernels.RoyalFoodTaster; var db = Engine.For <MyModel>(config).GetProxy(); Assert.Catch(db.MutateAndThrow); Assert.AreEqual(ExpectedState, db.GetState()); }
public void CanGetModelReference() { var config = EngineConfiguration.Create().ForIsolatedTest(); var engine = Engine.Create <TestModel>(config); engine.Execute(new TestCommandWithoutResult()); var model = engine.GetModel(); Assert.IsInstanceOfType(model, typeof(TestModel)); }
public void ImmutabilityEngineSmokeTest() { var config = EngineConfiguration.Create().ForImmutability().ForIsolatedTest(); var engine = Engine.Create <ImmutableModel>(config); int actual = engine.Execute(new AppendNumberAndGetSumCommand(42)); Assert.AreEqual(42, actual); engine.Execute(new AppendNumberCommand(58)); actual = engine.Execute(new NumberSumQuery()); Assert.AreEqual(actual, 42 + 58); }
public void Setup() { var cfg = EngineConfiguration.Create().ForIsolatedTest(); _engine = Engine.Create <ProxyExceptionTestModel>(cfg); _proxy = _engine.GetProxy(); _callsToExecutÃng = 0; _callsToExecuted = 0; _engine.CommandExecuting += (sender, args) => _callsToExecutÃng++; _engine.CommandExecuted += (sender, args) => _callsToExecuted++; }
public void CommandExecuting_can_cancel() { var config = EngineConfiguration.Create().ForImmutability().ForIsolatedTest(); var engine = Engine.Create <ImmutableModel>(config); engine.CommandExecuting += (s, e) => { e.Cancel = true; }; engine.Execute(new AppendNumberCommand(42)); Config.Engines.CloseAll(); }
public void Timestamp_preserved_on_restore() { var command = new SetTimeCommand(); var config = EngineConfiguration.Create().ForIsolatedTest(); var engine = Engine.Create <TestModel>(config); engine.Execute(command); var store = config.CreateCommandStore(); var entry = store.CommandEntries().Single(); Assert.AreEqual(entry.Created, entry.Item.Timestamp); Assert.AreEqual(command.Timestamp, entry.Created); }
public void CommandExecuting_is_fired() { var config = EngineConfiguration.Create().ForImmutability().ForIsolatedTest(); var engine = Engine.Create <ImmutableModel>(config); bool wasFired = false; engine.CommandExecuting += (s, e) => { wasFired = true; }; engine.Execute(new AppendNumberCommand(42)); Assert.AreEqual(true, wasFired); Config.Engines.CloseAll(); }
public void MyTestInitialize() { Directory.CreateDirectory(_path); _config = EngineConfiguration.Create(); _config.Location.OfJournal = _path; _config.MaxEntriesPerJournalSegment = 10; _store = new FileCommandStore(_config); _store.Initialize(); var writer = _store.CreateJournalWriter(0); for (ulong i = 0; i < 30; i++) { writer.Write(new JournalEntry <Command>(i + 1, new TestCommandWithoutResult())); } writer.Close(); }
public void Snapshots_are_numbered_correctly() { var config = EngineConfiguration.Create().ForImmutability().ForIsolatedTest(); var engine = Engine.Create <ImmutableModel>(config); engine.Execute(new AppendNumberCommand(42)); engine.Execute(new AppendNumberCommand(42)); engine.Execute(new AppendNumberCommand(42)); engine.Execute(new AppendNumberCommand(42)); engine.CreateSnapshot(); var store = config.CreateSnapshotStore(); Assert.AreEqual(4, store.Snapshots.First().Revision); Assert.AreEqual(1, store.Snapshots.Count()); }
public void ImmutabilityKernelSmokeTest() { var config = EngineConfiguration.Create().ForImmutability(); config.Location.OfJournal = Guid.NewGuid().ToString(); var model = new ImmutableModel(); config.SetCommandStoreFactory(cfg => new InMemoryCommandStore(cfg)); var kernel = new ImmutabilityKernel(config, model); int actual = (int)kernel.ExecuteCommand(new AppendNumberAndGetSumCommand(42)); Assert.AreEqual(42, actual); kernel.ExecuteCommand(new AppendNumberCommand(58)); actual = kernel.ExecuteQuery(new NumberSumQuery()); Assert.AreEqual(actual, 42 + 58); }
public void SnapshotPerTransactionCreatesSnapshotsAndNoJournalEntries() { var config = EngineConfiguration.Create().ForIsolatedTest().ForImmutability(); config.PersistenceMode = PersistenceMode.SnapshotPerTransaction; var engine = Engine.Create <ImmutableModel>(config); engine.Execute(new AppendNumberCommand(2)); engine.Execute(new AppendNumberCommand(42)); engine.Execute(new AppendNumberCommand(12)); engine.Close(); var commandStore = config.CreateCommandStore(); var snapshotStore = config.CreateSnapshotStore(); Assert.AreEqual(3, snapshotStore.Snapshots.Count()); Assert.AreEqual(0, commandStore.GetJournalEntries().OfType <JournalEntry <Command> >().Count()); }
public void CanLoadAndCreateRepeatedly() { var config = EngineConfiguration.Create().WithRandomLocation(); try { var engine = Engine.LoadOrCreate <TestModel>(config); engine.Execute(new TestCommandWithResult()); engine.Close(); engine = Engine.LoadOrCreate <TestModel>(config); engine.Close(); } finally { if (config.CreateCommandStore() is FileCommandStore) { Directory.Delete(config.Location.OfJournal, true); } } }
public void EitherMaxTriggersRollover() { var config = EngineConfiguration.Create(); var strategy = config.CreateRolloverStrategy(); var maxBytes = config.MaxBytesPerJournalSegment; var maxEntries = config.MaxEntriesPerJournalSegment; bool triggered = strategy.Rollover(maxBytes, 0); Assert.AreEqual(true, triggered); triggered = strategy.Rollover(0, maxEntries); Assert.AreEqual(true, triggered); triggered = strategy.Rollover(maxBytes - 1, maxEntries - 1); Assert.AreEqual(false, triggered); triggered = strategy.Rollover(maxBytes, maxEntries); Assert.IsTrue(triggered); }
public void ManualSnaphots() { var config = EngineConfiguration.Create().ForIsolatedTest().ForImmutability(); config.PersistenceMode = PersistenceMode.ManualSnapshots; var engine = Engine.Create <ImmutableModel>(config); engine.Execute(new AppendNumberCommand(2)); engine.Execute(new AppendNumberCommand(42)); engine.CreateSnapshot(); engine.Execute(new AppendNumberCommand(12)); engine.Close(); var store = config.CreateSnapshotStore(); Assert.AreEqual(1, store.Snapshots.Count()); engine = Engine.Load <ImmutableModel>(config); var sum = engine.Execute(new NumberSumQuery()); Assert.AreEqual(44, sum); }
public void DomainEventsAreDispatched() { var config = EngineConfiguration.Create().ForIsolatedTest(); var engine = Engine.Create <TestModel>(config); var @event = new Event(); var events = new List <IEvent[]>(); engine.CommandExecuted += (s, e) => events.Add(e.Events); engine.Execute(new EventEmittingCommand(@event)); engine.Execute(new EventEmittingCommand(@event, 0)); engine.Execute(new EventEmittingCommand(@event, 2)); engine.Execute(new EventEmittingCommand(@event, 4)); //each invocation should produce an array of events Assert.AreEqual(4, events.Count); CollectionAssert.AllItemsAreInstancesOfType(events, typeof(IEvent[])); Assert.AreEqual(1, events[0].Count()); Assert.AreEqual(0, events[1].Count()); Assert.AreEqual(2, events[2].Count()); Assert.AreEqual(4, events[3].Count()); Assert.IsTrue(events.SelectMany(e => e).All(e => e == @event)); }
public void Commands_executed_event_contains_sequential_entry_ids() { var config = EngineConfiguration.Create() .ForImmutability() .ForIsolatedTest(); var engine = Engine.Create <ImmutableModel>(config); var sequence = new List <ulong>(); engine.CommandExecuted += (s, e) => sequence.Add(e.JournalEntryId); for (int i = 1; i <= 100; i++) { engine.Execute(new AppendNumberCommand(i)); } foreach (var entryId in sequence) { Console.WriteLine(entryId); } var sum = engine.Execute((ImmutableModel m) => m.Numbers().Sum()); Assert.AreEqual((decimal)sum, sequence.Sum <ulong>(n => (decimal)n)); }
public void RollbackMarkerIsWrittenOnRollback() { //Arrange var config = EngineConfiguration.Create().ForIsolatedTest(); var store = new InMemoryCommandStore(config); store.Initialize(); var target = new JournalAppender(1, new StreamJournalWriter(config, store.CreateJournalWriterStream)); var command = new ACommand(); command.Timestamp = DateTime.Now; target.Append(command); target.Append(command); //Act target.AppendRollbackMarker(); //Assert Assert.AreEqual(3, store.GetJournalEntries().Count()); Assert.AreEqual(1, store.GetJournalEntries().OfType <JournalEntry <RollbackMarker> >().Count()); Assert.IsTrue(store.GetJournalEntries().Last() is JournalEntry <RollbackMarker>); }
public void JournalingIsDefault() { var config = EngineConfiguration.Create(); Assert.AreEqual(config.PersistenceMode, PersistenceMode.Journaling); }
public EngineConfiguration CreateConfig() { return(EngineConfiguration .Create().ForIsolatedTest()); }
private EngineConfiguration Config() { return(EngineConfiguration.Create().ForIsolatedTest()); }
public void Init() { _config = EngineConfiguration.Create().ForIsolatedTest().ForImmutability(); _commandStore = new InMemoryCommandStore(_config); _commandStore.Initialize(); }