예제 #1
0
 public InMemorySnapshotStore(EngineConfiguration config)
     : base(config)
 {
     string key = _config.GetSnapshotPath(makeAbsolute:false);
     if (!_states.ContainsKey(key)) _states.Add(key, new InMemorySnapshotStoreState());
     _state = _states[key];
 }
예제 #2
0
 public StreamJournalWriter(IStore storage, EngineConfiguration config)
 {
     _config = config;
     _storage = storage;
     _journalFormatter = config.CreateFormatter(FormatterUsage.Journal);
     _rolloverStrategy = _config.CreateRolloverStrategy();
 }
예제 #3
0
 public void FileStorageIsDefault()
 {
     var config = new EngineConfiguration().WithRandomLocation();
     var storage = config.CreateStore();
     Assert.IsTrue(storage is FileStore);
     Directory.Delete(config.Location.OfJournal, true);
 }
예제 #4
0
        public void PurgeTimer()
        {
            var config = new EngineConfiguration().ForIsolatedTest();
            var engine = Engine.Create<RedisModel>(config);
            var redis = engine.GetProxy();

            var mre = new ManualResetEvent(false);

            engine.CommandExecuted += (sender, args) =>
            {
                if (args.Command is PurgeExpiredKeysCommand) mre.Set();
            };
            const string key = "key";
            redis.Set(key, "1");
            redis.Set("key2", "2");
            var expires = DateTime.Now;
            redis.Expire(key, expires);

            var signaled = mre.WaitOne(TimeSpan.FromSeconds(5));
            Assert.IsTrue(signaled, "No PurgeExpiredKeysCommand within time limit 5s");

            Assert.AreEqual(redis.KeyCount(), 1);
            engine.Close();

            engine = Engine.Load<RedisModel>(config);
            redis = engine.GetProxy();
            Assert.AreEqual(redis.KeyCount(), 1);
            engine.Close();
        }
예제 #5
0
 public InMemorySnapshotStore(EngineConfiguration config)
     : base(config)
 {
     string key = _config.Location.OfSnapshots;
     if (!_states.ContainsKey(key)) _states.Add(key, new InMemorySnapshotStoreState());
     _state = _states[key];
 }
예제 #6
0
        public void SmokeTest()
        {
            const string aQueue = "myqueue";
            const string aTopic = "mytopic";
            const string aGreeting = "Hello world!";
            var aMessage = new TextMessage(aGreeting);

            var config = new EngineConfiguration().ForIsolatedTest();
            config.Isolation.Commands = CloneStrategy.Never;
            config.Isolation.ReturnValues = CloneStrategy.Never;
            var broker = Db.For<MessageBroker>(config);

            //create/write/read queue
            broker.CreateQueue(aQueue);
            broker.Enqueue(aQueue, aMessage);
            var message = (TextMessage) broker.Dequeue(aQueue);
            Assert.IsNotNull(message);
            Assert.AreEqual(aGreeting, message.Body);

            //if queue is empty null is returned
            message = (TextMessage) broker.Dequeue(aQueue);
            Assert.IsNull(message);

            broker.CreateBus(aTopic);

            //no op, no subscribers
            broker.Publish(aTopic, aMessage);

            var aSubscriber = Guid.NewGuid();
            broker.Subscribe(aSubscriber, aTopic);

            broker.Publish(aTopic, aMessage);
            broker.Publish(aTopic, aMessage);

            var messages = broker.Poll(aSubscriber, aTopic);
            Assert.AreEqual(messages.Length, 2);

            //Messages are immutable so we should get same instances back!
            Assert.AreSame(messages[0], aMessage);

            Guid[] subscribers = broker.GetSubscribers(aTopic);
            Assert.AreEqual(subscribers.Length, 1);
            Assert.AreEqual(aSubscriber, subscribers[0]);

            broker.Enqueue(aQueue, aMessage);
            broker.Enqueue(aQueue, aMessage);
            broker.Enqueue(aQueue, aMessage);
            broker.Publish(aTopic, aMessage);

            var status = broker.GetStatus();
            Assert.AreEqual(status.Queues.Count, 1);
            Assert.AreEqual(status.Buses.Count, 1);

            Assert.AreEqual(status.Queues[aQueue], 3);
            Assert.AreEqual(status.Buses[aTopic].Count, 1, "Expected one subscriber");
            Assert.AreEqual(1, status.Buses[aTopic][aSubscriber]);

            broker.Unsubscribe(aSubscriber, aTopic);
            Assert.AreEqual(broker.GetSubscribers(aTopic).Length, 0);
        }
예제 #7
0
 public void InjectedAuthorizerIsResolved()
 {
     var config = new EngineConfiguration();
     var expected = new TypeBasedPermissionSet();
     config.SetAuthorizerFactory((c) => expected);
     var actual = config.CreateAuthorizer();
     Assert.AreSame(expected,actual);
 }
예제 #8
0
 private static EngineConfiguration CreateConfig()
 {
     var config = new EngineConfiguration();
     config.Kernel = Kernels.Immutability;
     config.EnsureSafeResults = false;
     config.Synchronization = SynchronizationMode.None;
     return config;
 }
예제 #9
0
파일: EngineTest.cs 프로젝트: avgx/OrigoDB
 public void CanGetModelReference()
 {
     var config = new EngineConfiguration().ForIsolatedTest();
     var engine = Engine.Create<TestModel>(config);
     engine.Execute(new TestCommandWithoutResult());
     var model = engine.GetModel();
     Assert.IsInstanceOf(typeof(TestModel), model);
 }
예제 #10
0
 public void Corrupting_command_effects_ignored()
 {
     var config = new EngineConfiguration().ForIsolatedTest();
     config.Kernel = Kernels.RoyalFoodTaster;
     var db = Engine.For<MyModel>(config).GetProxy();
     Assert.Catch(db.MutateAndThrow);
     Assert.AreEqual(ExpectedState, db.GetState());
 }
예제 #11
0
 public void InjectedSynchronizerIsResolved()
 {
     var config = new EngineConfiguration();
     var expected = new NullSynchronizer();
     config.SetSynchronizerFactory((c) => expected);
     var actual = config.CreateSynchronizer();
     Assert.AreSame(expected,actual);
 }
예제 #12
0
 public SqlCommandStore(EngineConfiguration config)
     : base(config)
 {
     _settings = config.SqlSettings;
     _settings.ResolveConnectionString();
     _providerFactory = DbProviderFactories.GetFactory(_settings.ProviderName);
     _statements = _settings.Statements ?? ProviderStatements[_settings.ProviderName];
 }
예제 #13
0
        public InMemoryCommandStore(EngineConfiguration config)
            : base(config)
        {
            if (_config.HasAlternativeSnapshotPath()) throw new NotSupportedException("SnapshotPath must be same as JournalPath");

            string key = _config.JournalPath;
            if (!_states.ContainsKey(key)) _states.Add(key, new InMemoryCommandStoreState());
            _state = _states[key];
        }
예제 #14
0
        public InMemoryCommandStore(EngineConfiguration config)
            : base(config)
        {
            if (_config.Location.HasAlternativeSnapshotLocation) throw new NotSupportedException();

            string key = _config.Location.OfJournal;
            if (!_states.ContainsKey(key)) _states.Add(key, new InMemoryCommandStoreState());
            _state = _states[key];
        }
예제 #15
0
 public void InjectedFormatterIsResolved()
 {
     var config = new EngineConfiguration();
     config.PacketOptions = null;
     var expected = new BinaryFormatter();
     config.SetFormatterFactory((c,f) => expected);
     var actual = config.CreateFormatter(FormatterUsage.Default);
     Assert.AreSame(expected, actual);
 }
예제 #16
0
 public void AsyncJournalingYieldsAsyncWriter()
 {
     var config = new EngineConfiguration(Guid.NewGuid().ToString());
     config.AsyncronousJournaling = true;
     config.SetStoreFactory(c => new InMemoryStore(c));
     var store = config.CreateStore();
     var writer = store.CreateJournalWriter(1);
     Assert.IsTrue(writer is AsynchronousJournalWriter);
 }
예제 #17
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);
 }
예제 #18
0
 public void Run(EngineConfiguration config)
 {
     if (m_AlreadyRunning)
     {
         return;
     }
     m_AlreadyRunning = true;
     CurrentConfig    = config;
     m_OnStart();
 }
예제 #19
0
        public void TestEngineExecuteEmptyFieldMaps()
        {
            EngineConfiguration ec = host.Services.GetRequiredService <EngineConfiguration>();

            ec.Processors.Clear();
            ec.FieldMaps.Clear();
            IMigrationEngine me = host.Services.GetRequiredService <IMigrationEngine>();

            me.Run();
        }
예제 #20
0
        public void CanGetModelReference()
        {
            var config = new EngineConfiguration().ForIsolatedTest();
            var engine = Engine.Create <TestModel>(config);

            engine.Execute(new TestCommandWithoutResult());
            var model = engine.GetModel();

            Assert.IsInstanceOf(typeof(TestModel), model);
        }
예제 #21
0
        public void InjectedSynchronizerIsResolved()
        {
            var config   = new EngineConfiguration();
            var expected = new NullSynchronizer();

            config.SetSynchronizerFactory((c) => expected);
            var actual = config.CreateSynchronizer();

            Assert.AreSame(expected, actual);
        }
        public void TestSeraliseToJson()
        {
            string json = JsonConvert.SerializeObject(EngineConfiguration.GetDefault(),
                                                      new FieldMapConfigJsonConverter(),
                                                      new ProcessorConfigJsonConverter());
            StreamWriter sw = new StreamWriter("configuration.json");

            sw.WriteLine(json);
            sw.Close();
        }
예제 #23
0
 public void Setup()
 {
     var cfg = new EngineConfiguration().ForIsolatedTest();
     _engine = Engine.Create<ProxyExceptionTestModel>(cfg);
     _proxy = _engine.GetProxy();
     _callsToExecuting = 0;
     _callsToExecuted = 0;
     _engine.CommandExecuting += (sender, args) => _callsToExecuting++;
     _engine.CommandExecuted += (sender, args) => _callsToExecuted++;
 }
예제 #24
0
    protected void import_directive(
        EngineConfiguration conf
        ) //throws RecognitionException, TokenStreamException
    {
        Token i = null;

        String          ns;
        String          assemblyName;
        ImportDirective import = null;


        try {              // for error handling
            i = LT(1);
            match(IMPORT);
            ns = identifier();

            import = new ImportDirective(ToLexicalInfo(i), ns);
            conf.Imports.Add(import);

            {
                switch (LA(1))
                {
                case IN:
                {
                    match(IN);
                    assemblyName = identifier();

                    import.AssemblyReference = new AssemblyReference(ToLexicalInfo(i), assemblyName);

                    break;
                }

                case EOF:
                case ASPECT:
                case IMPORT:
                case MIXINS:
                case INTERCEPTORS:
                {
                    break;
                }

                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                }
            }
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            consume();
            consumeUntil(tokenSet_1_);
        }
    }
예제 #25
0
    /// <inheritdoc />
    public override void Setup(BuildOptions options)
    {
        base.Setup(options);

        if (EngineConfiguration.WithCSharp(options))
        {
            options.PublicDependencies.Add("mono");
        }

        options.PrivateDependencies.Add("Utilities");
    }
예제 #26
0
 public MigrationEngineCore(IHost host, ILogger <MigrationEngineCore> log, ITelemetryLogger telemetry, IEngineConfigurationBuilder configBuilder)
 {
     _Host          = host;
     _Log           = log;
     _Telemetry     = telemetry;
     _Config        = configBuilder.BuildFromFile();
     _witdContainer = _Host.Services.GetRequiredService <TypeDefinitionMapContainer>();
     _pContainer    = _Host.Services.GetRequiredService <ProcessorContainer>();
     _grmContainer  = _Host.Services.GetRequiredService <GitRepoMapContainer>();
     ProcessConfiguration();
 }
예제 #27
0
        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);
        }
예제 #28
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();
        }
예제 #29
0
        private void CarMapping()
        {
            var ec = new EngineConfiguration {
                ModelNumber = "1A", ModelYear = 2013
            };
            var cs = new CarSetup {
                Configuration = ec, VIN = "123"
            };

            var info = Mapper.Map <CarSetup, CarInfo>(cs);
        }
예제 #30
0
        public void Setup()
        {
            var cfg = new EngineConfiguration().ForIsolatedTest();

            _engine                   = Engine.Create <ProxyExceptionTestModel>(cfg);
            _proxy                    = _engine.GetProxy();
            _callsToExecuting         = 0;
            _callsToExecuted          = 0;
            _engine.CommandExecuting += (sender, args) => _callsToExecuting++;
            _engine.CommandExecuted  += (sender, args) => _callsToExecuted++;
        }
        public void RegisterType_TypeAlreadyRegistered_Throws_Exception()
        {
            EngineConfiguration configuration = new EngineConfiguration();

            configuration.RegisterType(typeof(SimpleUser));

            Assert.Throws <ArgumentException>(() =>
            {
                configuration.RegisterType(typeof(SimpleUser));
            });
        }
예제 #32
0
        public EngineConfiguration Load()
        {
            // For now I want to force the a restart of the Engine to refresh the config settings... To enable this dynamically can cause serious
            // issues with the operation of the Engine because queues might be added or removed and that could lead to data loss...
            if (EngineConfiguration == null)
            {
                EngineConfiguration = ConfigurationManager.GetSection(HermesConfigurationSectionName) as EngineConfiguration;
            }

            return(EngineConfiguration);
        }
예제 #33
0
        // *** WINBOARD ENGINE SUPPORT *** //

        #region TryCreateAdaptor
        public override EngineGameAdaptor TryCreateAdaptor(EngineConfiguration config)
        {
            if (config.SupportedVariants.Contains("normal") &&
                config.SupportedFeatures.Contains("setboard"))
            {
                EngineGameAdaptor adaptor = new EngineGameAdaptor("normal");
                adaptor.IssueSetboard = true;
                return(adaptor);
            }
            return(null);
        }
예제 #34
0
        public void SetupConfiguration()
        {
            Configuration = new EngineConfiguration();
            IEngineConventionProvider conventionProvider = new EngineConventionConfiguration();

            PopulateConfiguration();
            GenerationSessionFactory factory = new GenerationSessionFactory(
                this.Configuration, conventionProvider);

            this.GenerationSession = factory.CreateSession();
        }
예제 #35
0
        public InMemorySnapshotStore(EngineConfiguration config)
            : base(config)
        {
            string key = _config.Location.OfSnapshots;

            if (!_states.ContainsKey(key))
            {
                _states.Add(key, new InMemorySnapshotStoreState());
            }
            _state = _states[key];
        }
예제 #36
0
        public object GetEngineMetric(string metric)
        {
            if (string.CompareOrdinal("GlobalVisualizersDirectory", metric) == 0)
            {
                string openDebugPath = EngineConfiguration.GetAdapterDirectory();

                return(Path.Combine(openDebugPath, "Visualizers"));
            }

            return(null);
        }
예제 #37
0
        public InMemorySnapshotStore(EngineConfiguration config)
            : base(config)
        {
            string key = _config.GetSnapshotPath(makeAbsolute: false);

            if (!_states.ContainsKey(key))
            {
                _states.Add(key, new InMemorySnapshotStoreState());
            }
            _state = _states[key];
        }
 private static IEngine FindCachedConfiguration(string name)
 {
     if (configurations.ContainsKey(name))
     {
         Engine engine = new Engine(name);
         EngineConfiguration configuration = (EngineConfiguration)configurations[name];
         engine.Configuration = configuration;
         return(engine);
     }
     return(null);
 }
예제 #39
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);
        }
예제 #40
0
        private void HelperCreateDefaultConfigFile()
        {
            var ecb = CreateEngine();
            EngineConfiguration ec = ecb.BuildDefault();
            string json            = JsonConvert.SerializeObject(ecb.BuildDefault(),
                                                                 new FieldMapConfigJsonConverter(),
                                                                 new ProcessorConfigJsonConverter());
            StreamWriter sw = new StreamWriter("configuration.json");

            sw.WriteLine(json);
            sw.Close();
        }
예제 #41
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);
        }
        public void TestDeseraliseFromJson2()
        {
            TestSeraliseToJson2();
            StreamReader sr = new StreamReader("configuration2.json");
            string       configurationjson = sr.ReadToEnd();

            sr.Close();
            EngineConfiguration ec = NewtonsoftHelpers.DeserializeObject <EngineConfiguration>(configurationjson);

            Assert.AreEqual(10, ec.FieldMaps.Count);
            Assert.AreEqual(12, ec.Processors.Count);
        }
예제 #43
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);
        }
예제 #44
0
        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();
        }
예제 #45
0
        public void ValidInterceptor()
        {
            String content = " " +
                             "interceptors \r\n" +
                             "[" +
                             "\"customer\" : AspectSharp.Lang.Tests.Types.Interceptors.DummyInterceptor in AspectSharp.Lang.Tests" +
                             "]";

            EngineConfiguration conf = ProcessContent(content);

            Assert.IsFalse(_context.HasErrors);
        }
예제 #46
0
        public virtual void OnEngineConfiguration(EngineConfiguration conf)
        {
            if (EnterEngineConfiguration(conf))
            {
                conf.Imports.Accept(this);
                conf.Mixins.Accept(this);
                conf.Interceptors.Accept(this);
                conf.Aspects.Accept(this);

                LeaveEngineConfiguration(conf);
            }
        }
예제 #47
0
        public void Setup()
        {
            _expected = new EngineConfiguration();
            _expected.LockTimeout = TimeSpan.FromSeconds(30);
            _expected.Kernel = Kernels.RoyalFoodTaster;
            _expected.MaxBytesPerJournalSegment = 8192*1024;

            _configDictionary = new ConfigDictionary();
            _configDictionary.Set("kernel", _expected.Kernel);
            _configDictionary.Set("engineconfiguration.locktimeout", _expected.LockTimeout);
            _configDictionary.Set("EngineConfiguration.MaxbytesPerJournalSegment", _expected.MaxBytesPerJournalSegment);
        }
예제 #48
0
		public virtual void OnEngineConfiguration(EngineConfiguration conf)
		{
			if (EnterEngineConfiguration(conf))
			{
				conf.Imports.Accept(this);
				conf.Mixins.Accept(this);
				conf.Interceptors.Accept(this);
				conf.Aspects.Accept(this);
				
				LeaveEngineConfiguration(conf);
			}
		}
예제 #49
0
        public void CommandExecuting_can_cancel()
        {
            var config = new EngineConfiguration().ForImmutability().ForIsolatedTest();
            var engine = Engine.Create<ImmutableModel>(config);

            engine.CommandExecuting += (s, e) =>
            {
                e.Cancel = true;
            };
            engine.Execute(new AppendNumberCommand(42));
            Config.Engines.CloseAll();
        }
예제 #50
0
        public void Setup()
        {
            _expected             = new EngineConfiguration();
            _expected.LockTimeout = TimeSpan.FromSeconds(30);
            _expected.Kernel      = Kernels.RoyalFoodTaster;
            _expected.MaxBytesPerJournalSegment = 8192 * 1024;

            _configDictionary = new ConfigDictionary();
            _configDictionary.Set("kernel", _expected.Kernel);
            _configDictionary.Set("engineconfiguration.locktimeout", _expected.LockTimeout);
            _configDictionary.Set("EngineConfiguration.MaxbytesPerJournalSegment", _expected.MaxBytesPerJournalSegment);
        }
예제 #51
0
        public void InjectedFormatterIsResolved()
        {
            var config = new EngineConfiguration();

            config.PacketOptions = null;
            var expected = new BinaryFormatter();

            config.SetFormatterFactory((c, f) => expected);
            var actual = config.CreateFormatter(FormatterUsage.Default);

            Assert.AreSame(expected, actual);
        }
예제 #52
0
        public void CommandExecuting_is_fired()
        {
            var config = new EngineConfiguration().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();
        }
예제 #53
0
        public void CommandExecuted_event_contains_sequential_entry_ids()
        {
            var config = new EngineConfiguration()
                .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));
            var sum = engine.Execute(m => m.Numbers().Sum());
            Assert.AreEqual(sum, sequence.Sum(n => (decimal) n));
        }
예제 #54
0
        public void Snapshots_are_numbered_correctly()
        {
            var config = new EngineConfiguration().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());
        }
예제 #55
0
        public void SetUp()
        {
            Directory.CreateDirectory(_path);
            _config = new EngineConfiguration();
            _config.JournalPath = _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();
        }
예제 #56
0
 public void MsSqlProviderIntegrationTest()
 {
     var config = new EngineConfiguration();
     config.JournalStorage = StorageType.Sql;
     config.SqlSettings.ConnectionString = "Data Source=.;Initial Catalog=fish;Integrated Security=True;";
     config.SqlSettings.ProviderName = "System.Data.SqlClient";
     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);
     (engine as LocalEngineClient<TestModel>).Engine.Close();
     engine = Engine.For<TestModel>(config);
     actual = engine.Execute(new TestCommandWithResult());
     Assert.AreEqual(initial + 3, actual);
 }
예제 #57
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());
        }
예제 #58
0
        public void ManualSnaphots()
        {
            var config = new EngineConfiguration().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);
        }
예제 #59
0
        public void EitherMaxTriggersRollover()
        {
            var config = new EngineConfiguration();
            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);
        }
예제 #60
0
        public void MsSqlCommandStoreWriteReadEntries()
        {
            var config = new EngineConfiguration();
            var settings = config.SqlSettings;
            settings.ConnectionString = "Data Source=.;Initial Catalog=fish;Integrated Security=True";
            settings.ProviderName = "System.Data.SqlClient";
            settings.TableName = "[test-" + Guid.NewGuid() + "]";
            var commandStore = new SqlCommandStore(config);
            commandStore.Initialize();
            var formatter = new BinaryFormatter();
            var writer = new SqlJournalWriter(formatter, commandStore);
            writer.Write(JournalEntry.Create(1UL, DateTime.Now, new ModelCreated(typeof (TestModel))));
            writer.Write(JournalEntry.Create(2UL, DateTime.Now.AddSeconds(1), new AppendNumberCommand(42)));
            writer.Write(JournalEntry.Create(3UL, DateTime.Now.AddSeconds(2), new AppendNumberCommand(64)));

            foreach (var entry in commandStore.GetJournalEntriesFrom(1))
            {
                Trace.WriteLine(entry);
            }
            writer.Dispose();
        }