Exemplo n.º 1
0
        /// <summary>
        /// Creates an returns a new silo.
        /// </summary>
        /// <param name="hostName">The silo name if it is not already specified in the configuration.</param>
        /// <param name="configurationSources">The configuration.</param>
        /// <returns>A new silo.</returns>
        public static ISiloHost CreateSiloHost(string hostName, IEnumerable <IConfigurationSource> configurationSources)
        {
            var configBuilder = new ConfigurationBuilder();

            foreach (var source in configurationSources)
            {
                configBuilder.Add(source);
            }
            var configuration = configBuilder.Build();

            string siloName = configuration[nameof(TestSiloSpecificOptions.SiloName)] ?? hostName;

            var hostBuilder = new SiloHostBuilder()
                              .Configure <ClusterOptions>(configuration)
                              .Configure <SiloOptions>(options => options.SiloName = siloName)
                              .Configure <ClusterMembershipOptions>(options =>
            {
                options.ExpectedClusterSize = int.Parse(configuration["InitialSilosCount"]);
            })
                              .ConfigureHostConfiguration(cb =>
            {
                // TODO: Instead of passing the sources individually, just chain the pre-built configuration once we upgrade to Microsoft.Extensions.Configuration 2.1
                foreach (var source in configBuilder.Sources)
                {
                    cb.Add(source);
                }
            });

            hostBuilder.Properties["Configuration"] = configuration;
            ConfigureAppServices(configuration, hostBuilder);

            hostBuilder.ConfigureServices((context, services) =>
            {
                services.AddSingleton <TestHooksHostEnvironmentStatistics>();
                services.AddFromExisting <IHostEnvironmentStatistics, TestHooksHostEnvironmentStatistics>();
                services.AddSingleton <TestHooksSystemTarget>();
                ConfigureListeningPorts(context, services);

                TryConfigureTestClusterMembership(context, services);
                TryConfigureFileLogging(configuration, services, siloName);

                if (Debugger.IsAttached)
                {
                    // Test is running inside debugger - Make timeout ~= infinite
                    services.Configure <SiloMessagingOptions>(op => op.ResponseTimeout = TimeSpan.FromMilliseconds(1000000));
                }
            });

            hostBuilder.GetApplicationPartManager().ConfigureDefaults();

            var host = hostBuilder.Build();

            InitializeTestHooksSystemTarget(host);
            return(host);
        }
Exemplo n.º 2
0
        private static async Task <ISiloHost> StartSilo()
        {
            // define the cluster configuration
            var config = ClusterConfiguration.LocalhostPrimarySilo();

            config.AddMemoryStorageProvider();

            var builder = new SiloHostBuilder()
                          .UseConfiguration(config)
                          .ConfigureLogging(logging => logging.AddConsole());

            // TODO: After #3578 is released, this should be enough: builder.AddApplicationPartsFromReferences(typeof(HelloGrain).Assembly);
            builder.GetApplicationPartManager().AddApplicationPart(typeof(HelloGrain).Assembly);
            builder.GetApplicationPartManager().AddApplicationPartsFromReferences(typeof(HelloGrain).Assembly);

            var host = builder.Build();
            await host.StartAsync();

            return(host);
        }
        public static ISiloHost CreateSiloHost(string hostName, IEnumerable <IConfigurationSource> configurationSources)
        {
            var configBuilder = new ConfigurationBuilder();

            foreach (var source in configurationSources)
            {
                configBuilder.Add(source);
            }
            var configuration = configBuilder.Build();

            string siloName = configuration[nameof(TestSiloSpecificOptions.SiloName)] ?? hostName;

            ISiloHostBuilder hostBuilder = new SiloHostBuilder()
                                           .Configure(ob => ob.Bind(configuration))
                                           .ConfigureSiloName(siloName)
                                           .ConfigureHostConfiguration(cb =>
            {
                // TODO: Instead of passing the sources individually, just chain the pre-built configuration once we upgrade to Microsoft.Extensions.Configuration 2.1
                foreach (var source in configBuilder.Sources)
                {
                    cb.Add(source);
                }
            });

            hostBuilder.Properties["Configuration"] = configuration;
            ConfigureAppServices(configuration, hostBuilder);

            hostBuilder.ConfigureServices((context, services) =>
            {
                services.AddSingleton <TestHooksHostEnvironmentStatistics>();
                services.AddFromExisting <IHostEnvironmentStatistics, TestHooksHostEnvironmentStatistics>();
                services.AddSingleton <TestHooksSystemTarget>();
                ConfigureListeningPorts(context, services);

                TryConfigureTestClusterMembership(context, services);
                TryConfigureFileLogging(configuration, services, siloName);

                // TODO: make SiloHostBuilder work when not using the legacy configuration, similar to what we did with ClientBuilder.
                // All The important information has been migrated to strongly typed options (everything should be migrated, but the minimum required set is already there).
                var clusterConfiguration = GetOrCreateClusterConfiguration(services);
                if (Debugger.IsAttached)
                {
                    // Test is running inside debugger - Make timeout ~= infinite
                    clusterConfiguration.Globals.ResponseTimeout = TimeSpan.FromMilliseconds(1000000);
                }
            });

            hostBuilder.GetApplicationPartManager().ConfigureDefaults();

            var host = hostBuilder.Build();

            InitializeTestHooksSystemTarget(host);
            return(host);
        }