コード例 #1
0
        /// <summary>
        /// Restart the default Primary and Secondary silos.
        /// </summary>
        public void RestartDefaultSilos()
        {
            UnitTestSiloOptions primarySiloOptions   = Primary.Options;
            UnitTestSiloOptions secondarySiloOptions = Secondary.Options;
            // Restart as the same deployment
            string deploymentId = DeploymentId;

            StopDefaultSilos();

            DeploymentId = deploymentId;
            primarySiloOptions.PickNewDeploymentId   = false;
            secondarySiloOptions.PickNewDeploymentId = false;

            Primary   = _StartOrleansSilo(Silo.SiloType.Primary, primarySiloOptions);
            Secondary = _StartOrleansSilo(Silo.SiloType.Secondary, secondarySiloOptions);
            WaitForLivenessToStabilize();
            GrainClient.Initialize();
        }
コード例 #2
0
        private void _StopOrleansSilo(SiloHandle instance, bool kill)
        {
            if (!kill)
            {
                try { if (instance.Silo != null)
                      {
                          instance.Silo.Stop();
                      }
                }
                catch (RemotingException re) { Console.WriteLine(re); /* Ignore error */ }
                catch (Exception exc) { Console.WriteLine(exc); throw; }
            }

            try
            {
                _UnloadSiloInAppDomain(instance.AppDomain);
            }
            catch (Exception exc) { Console.WriteLine(exc); throw; }

            instance.AppDomain = null;
            instance.Silo      = null;
            instance.Process   = null;
        }
コード例 #3
0
        private SiloHandle _StartOrleansSilo(Silo.SiloType type, UnitTestSiloOptions options, AppDomain shared = null)
        {
            // Load initial config settings, then apply some overrides below.
            ClusterConfiguration config = new ClusterConfiguration();

            if (options.SiloConfigFile == null)
            {
                config.StandardLoad();
            }
            else
            {
                config.LoadFromFile(options.SiloConfigFile.FullName);
            }

            int basePort = options.BasePort >= 0 ? options.BasePort : BasePort;

            if (config.Globals.SeedNodes.Count > 0 && options.BasePort < 0)
            {
                config.PrimaryNode = config.Globals.SeedNodes[0];
            }
            else
            {
                config.PrimaryNode = new IPEndPoint(IPAddress.Loopback, basePort);
            }
            config.Globals.SeedNodes.Clear();
            config.Globals.SeedNodes.Add(config.PrimaryNode);

            if (!String.IsNullOrEmpty(DeploymentId))
            {
                config.Globals.DeploymentId = DeploymentId;
            }
            config.Defaults.PropagateActivityId = options.PropagateActivityId;
            if (options.LargeMessageWarningThreshold > 0)
            {
                config.Defaults.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
            }

            config.Globals.LivenessType = options.LivenessType;

            globalConfig = config.Globals;

            string siloName;

            switch (type)
            {
            case Silo.SiloType.Primary:
                siloName = "Primary";
                break;

            default:
                siloName = "Secondary_" + InstanceCounter.ToString(CultureInfo.InvariantCulture);
                break;
            }

            NodeConfiguration nodeConfig = config.GetConfigurationForNode(siloName);

            nodeConfig.HostNameOrIPAddress = "loopback";
            nodeConfig.Port = basePort + InstanceCounter;
            nodeConfig.DefaultTraceLevel   = config.Defaults.DefaultTraceLevel;
            nodeConfig.PropagateActivityId = config.Defaults.PropagateActivityId;
            nodeConfig.BulkMessageLimit    = config.Defaults.BulkMessageLimit;

            config.Globals.ExpectedClusterSize = 2;

            config.Overrides[siloName] = nodeConfig;

            InstanceCounter++;

            Console.WriteLine("Starting a new silo in app domain {0} with config {1}", siloName, config.ToString(siloName));
            AppDomain appDomain;
            Silo      silo = _LoadSiloInNewAppDomain(siloName, type, config, out appDomain);

            silo.Start();

            SiloHandle retValue = new SiloHandle
            {
                Name      = siloName,
                Silo      = silo,
                Options   = options,
                Endpoint  = silo.SiloAddress.Endpoint,
                AppDomain = appDomain,
            };

            return(retValue);
        }
コード例 #4
0
        private void _Initialize(UnitTestSiloOptions options, UnitTestClientOptions clientOptions = null)
        {
            bool doStartPrimary   = false;
            bool doStartSecondary = false;

            if (options.StartFreshOrleans)
            {
                // the previous test was !startFresh, so we need to cleanup after it.
                if (Primary != null || Secondary != null || GrainClient.IsInitialized)
                {
                    StopDefaultSilos();
                }

                StopAdditionalSilos();

                if (options.StartPrimary)
                {
                    doStartPrimary = true;
                }
                if (options.StartSecondary)
                {
                    doStartSecondary = true;
                }
            }
            else
            {
                if (options.StartPrimary && Primary == null)
                {
                    // first time.
                    doStartPrimary = true;
                }
                if (options.StartSecondary && Secondary == null)
                {
                    doStartSecondary = true;
                }
            }
            if (options.PickNewDeploymentId && String.IsNullOrEmpty(DeploymentId))
            {
                DeploymentId = _GetDeploymentId();
            }

            if (doStartPrimary)
            {
                Primary = _StartOrleansSilo(Silo.SiloType.Primary, options);
            }
            if (doStartSecondary)
            {
                Secondary = _StartOrleansSilo(Silo.SiloType.Secondary, options);
            }

            if (!GrainClient.IsInitialized && options.StartClient)
            {
                if (clientOptions != null && clientOptions.ClientConfigFile != null)
                {
                    clientConfig = ClientConfiguration.LoadFromFile(clientOptions.ClientConfigFile.FullName);
                }
                else
                {
                    clientConfig = ClientConfiguration.StandardLoad();
                }

                if (clientOptions != null)
                {
                    clientConfig.ResponseTimeout = clientOptions.ResponseTimeout;
                    if (clientOptions.ProxiedGateway && clientOptions.Gateways != null)
                    {
                        clientConfig.Gateways = clientOptions.Gateways;
                        if (clientOptions.PreferedGatewayIndex >= 0)
                        {
                            clientConfig.PreferedGatewayIndex = clientOptions.PreferedGatewayIndex;
                        }
                    }
                    clientConfig.PropagateActivityId = clientOptions.PropagateActivityId;
                    if (!String.IsNullOrEmpty(DeploymentId))
                    {
                        clientConfig.DeploymentId = DeploymentId;
                    }
                }
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    // Test is running inside debugger - Make timeout ~= infinite
                    clientConfig.ResponseTimeout = TimeSpan.FromMilliseconds(1000000);
                }
                if (options.LargeMessageWarningThreshold > 0)
                {
                    clientConfig.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold;
                }
                GrainClient.Initialize(clientConfig);
            }
        }