Exemplo n.º 1
0
        public void Initstatement_is_idempotent(SqlSettings settings)
        {
            var config = new EngineConfiguration();

            config.JournalStorage        = StorageType.Sql;
            config.SqlSettings           = settings;
            config.SqlSettings.TableName = "test-" + Guid.NewGuid();

            config.CreateCommandStore();
            config.CreateCommandStore();
        }
Exemplo n.º 2
0
 public void FileStorageIsDefault()
 {
     var config = new EngineConfiguration().WithRandomLocation();
     var storage = config.CreateCommandStore();
     Assert.IsTrue(storage is FileCommandStore);
     Directory.Delete(config.Location.OfJournal, true);
 }
Exemplo n.º 3
0
        public void FileStorageIsDefault()
        {
            var config  = new EngineConfiguration().WithRandomLocation();
            var storage = config.CreateCommandStore();

            Assert.IsTrue(storage is FileCommandStore);
            Directory.Delete(config.Location.OfJournal, true);
        }
Exemplo n.º 4
0
 public void AsyncJournalingYieldsAsyncWriter()
 {
     var config = new EngineConfiguration(Guid.NewGuid().ToString());
     config.AsynchronousJournaling = true;
     config.SetCommandStoreFactory(c => new InMemoryCommandStore(c));
     var store = config.CreateCommandStore();
     var writer = store.CreateJournalWriter(1);
     Assert.IsTrue(writer is AsynchronousJournalWriter);
 }
Exemplo n.º 5
0
 public void InjectedStorageIsResolved()
 {
     var config = new EngineConfiguration()
         .WithRandomLocation();
     var expected = new FileCommandStore(config);
     config.SetCommandStoreFactory((c) => expected);
     var actual = config.CreateCommandStore();
     Assert.AreSame(expected, actual);
     Directory.Delete(config.Location.OfJournal, true);
 }
Exemplo n.º 6
0
        public void SyncJournalingYieldsSyncWriter()
        {
            var config = new EngineConfiguration(Guid.NewGuid().ToString());

            config.AsynchronousJournaling = false;
            config.SetCommandStoreFactory(c => new InMemoryCommandStore(c));
            var store  = config.CreateCommandStore();
            var writer = store.CreateJournalWriter(1);

            Assert.IsTrue(writer is StreamJournalWriter);
        }
Exemplo n.º 7
0
        public void InjectedStorageIsResolved()
        {
            var config = new EngineConfiguration()
                         .WithRandomLocation();
            var expected = new FileCommandStore(config);

            config.SetCommandStoreFactory((c) => expected);
            var actual = config.CreateCommandStore();

            Assert.AreSame(expected, actual);
            Directory.Delete(config.Location.OfJournal, true);
        }
Exemplo n.º 8
0
        public void Journal_file_rolls_over_after_snapshot()
        {
            var config = new EngineConfiguration().ForIsolatedTest();
            var engine = Engine.Create <TestModel>(config);
            var store  = (InMemoryCommandStore)config.CreateCommandStore();

            engine.Execute(new TestCommandWithResult());
            int segmentsBefore = store.JournalSegments;

            engine.CreateSnapshot();
            Assert.AreEqual(segmentsBefore + 1, store.JournalSegments);
        }
Exemplo n.º 9
0
        public void SnapshotPerTransactionCreatesSnapshotsAndNoJournalEntries()
        {
            var config = new EngineConfiguration().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());
        }
Exemplo n.º 10
0
        public void Journal_is_truncated_after_snapshot()
        {
            var config = new EngineConfiguration().ForIsolatedTest();

            config.TruncateJournalOnSnapshot = true;
            var engine = Engine.Create <TestModel>(config);
            var store  = config.CreateCommandStore();

            engine.Execute(new TestCommandWithResult());

            engine.CreateSnapshot();
            ulong revision = engine.GetModel().Revision;

            engine.Execute(new TestCommandWithResult());
            Assert.AreEqual(1, store.CommandEntries().Count(), "Expected single command in store after truncate");
            Assert.AreEqual(revision + 1, store.CommandEntries().First().Id);
        }
Exemplo n.º 11
0
        public void SnapshotPerTransactionCreatesSnapshotsAndNoJournalEntries()
        {
            var config = new EngineConfiguration().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());
        }
Exemplo n.º 12
0
        public void CanLoadAndCreateRepeatedly()
        {
            var config = new EngineConfiguration().WithRandomLocation();

            try
            {
                var engine = Engine.LoadOrCreate <TestModel>(config);
                engine.Execute(new TestCommandWithResult());
                engine.Close();
                engine = Engine.LoadOrCreate <TestModel>(config);
                engine.Close();
            }
            finally
            {
                Thread.Sleep(40);
                if (config.CreateCommandStore() is FileCommandStore)
                {
                    Directory.Delete(config.JournalPath, true);
                }
            }
        }
Exemplo n.º 13
0
        public void SqlProviderIntegrationTest(SqlSettings settings)
        {
            var config = new EngineConfiguration();

            config.JournalStorage        = StorageType.Sql;
            config.SqlSettings           = settings;
            config.SqlSettings.TableName = "test-" + Guid.NewGuid();

            config.SnapshotPath = Guid.NewGuid().ToString();
            config.TruncateJournalOnSnapshot = true;
            var engine  = Engine.For <TestModel>(config);
            int initial = engine.Execute(new DelegateQuery <TestModel, int>(m => m.CommandsExecuted));

            engine.Execute(new TestCommandWithoutResult());
            int actual = engine.Execute(new TestCommandWithResult());

            Assert.AreEqual(initial + 2, actual);
            Config.Engines.CloseAll();
            engine = Engine.For <TestModel>(config);
            actual = engine.Execute(new TestCommandWithResult());
            Assert.AreEqual(initial + 3, actual);
            Config.Engines.All.First().CreateSnapshot();

            var store = config.CreateCommandStore();

            Assert.AreEqual(0, store.CommandEntries().Count(), "journal should be empty after snapshot");
            Config.Engines.CloseAll();
            engine = Engine.For <TestModel>(config);
            int commandsExecuted = engine.Execute(new DelegateQuery <TestModel, int>(m => m.CommandsExecuted));

            Assert.AreEqual(commandsExecuted, actual, "state should be same after close and reload");
            Config.Engines.CloseAll();

            //cleanup
            Directory.Delete(config.SnapshotPath, true);
        }
Exemplo n.º 14
0
 public ModelLoader(EngineConfiguration config, ICommandStore commandStore = null, ISnapshotStore snapshotStore = null)
 {
     _commandStore  = commandStore ?? config.CreateCommandStore();
     _snapshotStore = snapshotStore ?? config.CreateSnapshotStore();
 }
Exemplo n.º 15
0
 public ModelLoader(EngineConfiguration config, ICommandStore commandStore = null, ISnapshotStore snapshotStore = null)
 {
     _commandStore = commandStore ?? config.CreateCommandStore();
     _snapshotStore = snapshotStore ?? config.CreateSnapshotStore();
 }