Example #1
0
        protected override GridDomainNode CreateGridDomainNode(AkkaConfiguration akkaConf)
        {
            var conf = new CustomContainerConfiguration(c =>
            {
                c.RegisterType <ITestDependency, TestDependencyImplementation>();
                // c.RegisterInstance<IUnityContainer>(c);
                c.RegisterInstance <IQuartzConfig>(new InMemoryQuartzConfig());
                c.RegisterAggregate <TestAggregate, TestAggregatesCommandHandler>();
            });

            return(new GridDomainNode(conf, new TestRouteMap(), () => Sys));
        }
Example #2
0
        public async Task When_settings_are_customized_it_is_used_by_grid_node()
        {
            var node = new GridDomainNode(CustomContainerConfiguration.Empty(), new BalanceRouteMap(), () => ActorSystem.Create("test"));
            await node.Start();

            var ext = DomainEventsJsonSerializationExtensionProvider.Provider.Get(node.System);

            ext.Settings = new MyJsonSettings();

            var serializer = new DomainEventsJsonAkkaSerializer(node.System as ExtendedActorSystem);

            Assert.IsInstanceOf <MyJsonSettings>(serializer.Serializer.Value.JsonSerializerSettings);
        }
Example #3
0
        private static GridDomainNode StartSampleDomainNode()
        {
            var unityContainer = new UnityContainer();

            unityContainer.Register(new SampleDomainContainerConfiguration());

            var cfg = new CustomContainerConfiguration(
                c => c.Register(new SampleDomainContainerConfiguration()),
                c => c.RegisterType <IPersistentChildsRecycleConfiguration, InsertOptimazedBulkConfiguration>(),
                c => c.RegisterType <IQuartzConfig, PersistedQuartzConfig>());

            Func <ActorSystem[]> actorSystemFactory = () => new[] { new StressTestAkkaConfiguration().CreateSystem() };

            var node = new GridDomainNode(cfg, new SampleRouteMap(unityContainer), actorSystemFactory);

            node.Start().Wait();
            return(node);
        }
Example #4
0
        private static void RawCommandExecution(int totalAggregateScenariosCount, int aggregateScenarioPackSize, int aggregateChangeAmount)
        {
            var dbCfg = new AutoTestAkkaConfiguration();

            using (var connection = new SqlConnection(dbCfg.Persistence.JournalConnectionString))
            {
                connection.Open();
                var sqlText    = @"TRUNCATE TABLE Journal";
                var cmdJournal = new SqlCommand(sqlText, connection);
                cmdJournal.ExecuteNonQuery();

                var sqlText1     = @"TRUNCATE TABLE Snapshots";
                var cmdSnapshots = new SqlCommand(sqlText, connection);
                cmdSnapshots.ExecuteNonQuery();
            }

            var unityContainer = new UnityContainer();

            unityContainer.Register(new SampleDomainContainerConfiguration());

            var cfg = new CustomContainerConfiguration(
                c => c.Register(new SampleDomainContainerConfiguration()),
                c => c.RegisterType <IPersistentChildsRecycleConfiguration, InsertOptimazedBulkConfiguration>(),
                c => c.RegisterType <IQuartzConfig, PersistedQuartzConfig>());

            Func <ActorSystem[]> actorSystemFactory = () => new[] { new StressTestAkkaConfiguration().CreateSystem() };

            var node = new GridDomainNode(cfg, new SampleRouteMap(unityContainer), actorSystemFactory);

            node.Start().Wait();

            var timer = new Stopwatch();

            timer.Start();

            int timeoutedCommads     = 0;
            var random               = new Random();
            var commandsInScenario   = aggregateScenarioPackSize * (aggregateChangeAmount + 1);
            var totalCommandsToIssue = commandsInScenario * totalAggregateScenariosCount;


            for (int i = 0; i < totalAggregateScenariosCount; i++)
            {
                var packTimer = new Stopwatch();
                packTimer.Start();
                var tasks = Enumerable.Range(0, aggregateScenarioPackSize)
                            .Select(t => WaitAggregateCommands(aggregateChangeAmount, random, node))
                            .ToArray();
                try
                {
                    Task.WhenAll(tasks).Wait();
                }
                catch
                {
                    timeoutedCommads += tasks.Count(t => t.IsCanceled || t.IsFaulted);
                }

                packTimer.Stop();
                var speed    = (decimal)(commandsInScenario / packTimer.Elapsed.TotalSeconds);
                var timeLeft = TimeSpan.FromSeconds((double)((totalCommandsToIssue - i * commandsInScenario) / speed));

                Console.WriteLine($"speed :{speed} cmd/sec," +
                                  $"total errors: {timeoutedCommads}, " +
                                  $"total commands executed: {i*commandsInScenario}/{totalCommandsToIssue}," +
                                  $"approx time remaining: {timeLeft}");
            }


            timer.Stop();
            node.Stop().Wait();

            var speedTotal = (decimal)(totalCommandsToIssue / timer.Elapsed.TotalSeconds);

            Console.WriteLine(
                $"Executed {totalAggregateScenariosCount} batches = {totalCommandsToIssue} commands in {timer.Elapsed}");
            Console.WriteLine($"Average speed was {speedTotal} cmd/sec");

            using (var connection = new SqlConnection(dbCfg.Persistence.JournalConnectionString))
            {
                connection.Open();
                var sqlText    = @"SELECT COUNT(*) FROM Journal";
                var cmdJournal = new SqlCommand(sqlText, connection);
                var count      = (int)cmdJournal.ExecuteScalar();

                Console.WriteLine(count == totalCommandsToIssue
                    ? "Journal contains all events"
                    : $"Journal contains only {count} of {totalCommandsToIssue}");
            }
        }