public async Task Clear_child_lifetimes()
        {
            _gridDomainNode = new GridDomainNode(CreateConfiguration(), new SoftwareProgrammingSagaRoutes(), () => new [] { Sys });
            await _gridDomainNode.Start();

            switch (_case)
            {
            case PersistentHubTestsStatus.PersistenceCase.Aggregate:
                Infrastructure = new AggregatePersistedHub_Infrastructure(_gridDomainNode.System);
                break;

            case PersistentHubTestsStatus.PersistenceCase.IstanceSaga:
                Infrastructure = new InstanceSagaPersistedHub_Infrastructure(_gridDomainNode.System);
                break;

            case PersistentHubTestsStatus.PersistenceCase.StateSaga:
                Infrastructure = new StateSagaPersistedHub_Infrastructure(_gridDomainNode.System);
                break;

            default:
                throw new UnknownCaseException();
            }
            var actorOfAsTestActorRef = ActorOfAsTestActorRef <PersistentHubActor>(Infrastructure.HubProps, "TestHub_" + Guid.NewGuid());

            Hub    = actorOfAsTestActorRef.UnderlyingActor;
            HubRef = actorOfAsTestActorRef.Ref;
        }
예제 #2
0
        public void Start()
        {
            Log.Information($"Created shop node {NodeConfiguration.Name} at {NodeConfiguration.Address.Host} on port {NodeConfiguration.Address.PortNumber}");

            var actorSystemFactory = ActorSystemBuilder.New().Build(NodeConfiguration, new ShopNodeDbConfig());

            _gridDomainNode = new GridDomainNode(actorSystemFactory, _logger ?? Log.Logger, new ShopDomainConfiguration(ReadDbConnectionString));
            _gridDomainNode.Start().Wait();
        }
        public NodeCommandExecutionTests(ITestOutputHelper helper) : base(_config, nodeName, helper)
        {
            Serilog.Log.Logger = new LoggerConfiguration().WriteTo.Console()
                                 .WriteTo.File(Path.Combine("Logs", nameof(NodeCommandExecutionTests) + ".log"))
                                 .CreateLogger();

            var node = new GridDomainNode(new[] { new CatDomainConfiguration() },
                                          new DelegateActorSystemFactory(() => Sys), Serilog.Log.Logger, TimeSpan.FromSeconds(5));

            _domain = node.Start().Result;
        }
예제 #4
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);
        }
예제 #5
0
        protected virtual async Task Start()
        {
            LogManager.SetLoggerFactory(new AutoTestLogFactory());

            var autoTestGridDomainConfiguration = new AutoTestLocalDbConfiguration();

            if (ClearDataOnStart)
            {
                TestDbTools.ClearData(autoTestGridDomainConfiguration, AkkaConf.Persistence);
            }

            GridNode = CreateGridDomainNode(AkkaConf);
            OnNodeCreated();
            await GridNode.Start();

            OnNodeStarted();
        }
예제 #6
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);
        }
예제 #7
0
        public async Task Given_existing_GridNode()
        {
            var container = new UnityContainer();
            var sampleDomainContainerConfiguration = new SampleDomainContainerConfiguration();

            container.Register(sampleDomainContainerConfiguration);

            var serverConfig = new TestGridNodeConfiguration();

            _node = new GridDomainNode(sampleDomainContainerConfiguration,
                                       new SampleRouteMap(container),
                                       () => serverConfig.CreateInMemorySystem());

            await _node.Start();


            _connector = new GridNodeConnector(serverConfig.Network);
            _connector.Connect();
        }
예제 #8
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}");
            }
        }