Ejemplo n.º 1
0
        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++;
            }
        }
Ejemplo n.º 2
0
        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++;
            }
        }
Ejemplo n.º 3
0
        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>);
        }
Ejemplo n.º 4
0
        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>);
        }