/// <summary> /// Start the default Primary and Secondary test silos, plus client in-process, /// using the specified silo and client config options. /// </summary> public UnitTestSiloHost(UnitTestSiloOptions siloOptions, UnitTestClientOptions clientOptions) { this.siloInitOptions = siloOptions; this.clientInitOptions = clientOptions; AppDomain.CurrentDomain.UnhandledException += ReportUnobservedException; try { Initialize(siloOptions, clientOptions); string startMsg = "----------------------------- STARTING NEW UNIT TEST SILO HOST: " + this.GetType().FullName + " -------------------------------------"; WriteLog(startMsg); } catch (TimeoutException te) { throw new TimeoutException("Timeout during test initialization", te); } catch (Exception ex) { Exception baseExc = ex.GetBaseException(); if (baseExc is TimeoutException) { throw new TimeoutException("Timeout during test initialization", ex); } throw new AggregateException( string.Format("Exception during test initialization: {0}", TraceLogger.PrintException(ex)), ex); } }
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.ClientConfigFile != null) { clientConfig = ClientConfiguration.LoadFromFile(clientOptions.ClientConfigFile.FullName); } else { clientConfig = ClientConfiguration.StandardLoad(); } if (clientOptions.ProxiedGateway && clientOptions.Gateways != null) { clientConfig.Gateways = clientOptions.Gateways; if (clientOptions.PreferedGatewayIndex >= 0) { clientConfig.PreferedGatewayIndex = clientOptions.PreferedGatewayIndex; } } if (clientOptions.PropagateActivityId) { 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); } else if (clientOptions.ResponseTimeout > TimeSpan.Zero) { clientConfig.ResponseTimeout = clientOptions.ResponseTimeout; } if (options.LargeMessageWarningThreshold > 0) { clientConfig.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold; } GrainClient.Initialize(clientConfig); } }
private void Initialize(UnitTestSiloOptions options, UnitTestClientOptions clientOptions) { 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 (options.ParallelStart) { var handles = new List <Task <SiloHandle> >(); if (doStartPrimary) { int instanceCount = InstanceCounter++; handles.Add(Task.Run(() => StartOrleansSilo(Silo.SiloType.Primary, options, instanceCount))); } if (doStartSecondary) { int instanceCount = InstanceCounter++; handles.Add(Task.Run(() => StartOrleansSilo(Silo.SiloType.Secondary, options, instanceCount))); } Task.WhenAll(handles.ToArray()).Wait(); if (doStartPrimary) { Primary = handles[0].Result; } if (doStartSecondary) { Secondary = handles[1].Result; } } else { if (doStartPrimary) { Primary = StartOrleansSilo(Silo.SiloType.Primary, options, InstanceCounter++); } if (doStartSecondary) { Secondary = StartOrleansSilo(Silo.SiloType.Secondary, options, InstanceCounter++); } } if (!GrainClient.IsInitialized && options.StartClient) { ClientConfiguration clientConfig; if (clientOptions.ClientConfigFile != null) { clientConfig = ClientConfiguration.LoadFromFile(clientOptions.ClientConfigFile.FullName); } else { clientConfig = ClientConfiguration.StandardLoad(); } if (clientOptions.ProxiedGateway && clientOptions.Gateways != null) { clientConfig.Gateways = clientOptions.Gateways; if (clientOptions.PreferedGatewayIndex >= 0) { clientConfig.PreferedGatewayIndex = clientOptions.PreferedGatewayIndex; } } if (clientOptions.PropagateActivityId) { 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); } else if (clientOptions.ResponseTimeout > TimeSpan.Zero) { clientConfig.ResponseTimeout = clientOptions.ResponseTimeout; } if (options.LargeMessageWarningThreshold > 0) { clientConfig.LargeMessageWarningThreshold = options.LargeMessageWarningThreshold; } clientConfig.AdjustForTestEnvironment(); GrainClient.Initialize(clientConfig); } }