Пример #1
0
        public void RolledBackCommandsAreSkipped(Tuple<List<JournalEntry>, string> testCase)
        {
            IStore target = new InMemoryStore(EngineConfiguration.Create().ForIsolatedTest());

            string failureMessage = testCase.Item2;
            var testEntries = testCase.Item1;

            //Act
            var actualCommandEntries = StoreExtensions.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++;
            }
        }
Пример #2
0
        public void RollbackMarkerIsWrittenOnRollback()
        {
            //Arrange
            var config = EngineConfiguration.Create().ForIsolatedTest();
            var store = new InMemoryStore(config);
            store.Init();
            var target = new JournalAppender(1, new StreamJournalWriter(store, config));

            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>);
        }