Exemple #1
0
        public static async Task Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.Error.WriteLine("Expected JSON-serialized configuration to be provided as an argument");
            }

            var monitorProcessId        = int.Parse(args[0], NumberStyles.Integer, CultureInfo.InvariantCulture);
            var serializedConfiguration = args[1];
            var configuration           = TestClusterHostFactory.DeserializeConfiguration(serializedConfiguration);
            var name = configuration["SiloName"];
            var host = TestClusterHostFactory.CreateSiloHost(name, configuration);
            var cts  = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, eventArgs) => cts.Cancel();

            ListenForShutdownCommand(cts);
            MonitorParentProcess(monitorProcessId);

            await host.StartAsync(cts.Token);

            // This is a special marker line.
            var localSiloDetails = (ILocalSiloDetails)host.Services.GetService(typeof(ILocalSiloDetails));

            Console.WriteLine($"{SiloAddressLog}{localSiloDetails.SiloAddress.ToParsableString()}");
            Console.WriteLine($"{GatewayAddressLog}{localSiloDetails.GatewayAddress.ToParsableString()}");
            Console.WriteLine(StartedLog);

            await cts.Token.WhenCancelled();

            await host.StopAsync(CancellationToken.None);
        }
        /// <summary>Creates and initializes a silo in the current app domain.</summary>
        /// <param name="appDomainName">Name of this silo.</param>
        /// <param name="serializedConfigurationSources">Silo config data to be used for this silo.</param>
        public AppDomainSiloHost(string appDomainName, string serializedConfigurationSources)
        {
            var deserializedSources = TestClusterHostFactory.DeserializeConfigurationSources(serializedConfigurationSources);

            this.host = TestClusterHostFactory.CreateSiloHost(appDomainName, deserializedSources);
            this.AppDomainTestHook = new AppDomainTestHooks(this.host);
        }
Exemple #3
0
        /// <summary>Creates and initializes a silo in the current app domain.</summary>
        /// <param name="appDomainName">Name of this silo.</param>
        /// <param name="serializedConfigurationSources">Silo config data to be used for this silo.</param>
        public AppDomainSiloHost(string appDomainName, string serializedConfigurationSources)
        {
            // Force TLS 1.2. It should be done by TestUtils.CheckForAzureStorage and TestUtils.CheckForEventHub,
            // but they will not have any effect here since this silo will run on a different AppDomain
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            var deserializedSources = TestClusterHostFactory.DeserializeConfigurationSources(serializedConfigurationSources);

            this.host = TestClusterHostFactory.CreateSiloHost(appDomainName, deserializedSources);
        }
        /// <summary>Creates a new silo and returns a handle to it.</summary>
        /// <param name="siloName">The name for the new silo.</param>
        /// <param name="configurationSources">
        /// The configuration sources, interpreted by <see cref="TestClusterHostFactory.CreateSiloHost"/>.
        /// </param>
        public static async Task <SiloHandle> CreateAsync(
            string siloName,
            IList <IConfigurationSource> configurationSources)
        {
            var host = TestClusterHostFactory.CreateSiloHost(siloName, configurationSources);
            await host.StartAsync();

            var retValue = new InProcessSiloHandle
            {
                Name           = siloName,
                SiloHost       = host,
                SiloAddress    = host.Services.GetRequiredService <ILocalSiloDetails>().SiloAddress,
                GatewayAddress = host.Services.GetRequiredService <ILocalSiloDetails>().GatewayAddress,
            };

            return(retValue);
        }
        /// <summary>
        /// Create a silo handle.
        /// </summary>
        /// <param name="siloName">Name of the silo.</param>
        /// <param name="configuration">The configuration.</param>
        /// <param name="postConfigureHostBuilder">An optional delegate which is invoked just prior to building the host builder.</param>
        /// <returns>The silo handle.</returns>
        public static async Task <SiloHandle> CreateAsync(
            string siloName,
            IConfiguration configuration,
            Action <IHostBuilder> postConfigureHostBuilder = null)
        {
            var host = await Task.Run(async() =>
            {
                var result = TestClusterHostFactory.CreateSiloHost(siloName, configuration, postConfigureHostBuilder);
                await result.StartAsync();
                return(result);
            });

            var retValue = new InProcessSiloHandle
            {
                Name           = siloName,
                SiloHost       = host,
                SiloAddress    = host.Services.GetRequiredService <ILocalSiloDetails>().SiloAddress,
                GatewayAddress = host.Services.GetRequiredService <ILocalSiloDetails>().GatewayAddress,
            };

            return(retValue);
        }