示例#1
0
        /// <summary>
        /// This is the lock free version of uninitilize so we can share
        /// it between the public method and error paths inside initialize.
        /// This should only be called inside a lock(initLock) block.
        /// </summary>
        private static void InternalUninitialize(bool cleanup = true)
        {
            // Update this first so IsInitialized immediately begins returning
            // false.  Since this method should be protected externally by
            // a lock(initLock) we should be able to reset everything else
            // before the next init attempt.
            isFullyInitialized = false;

            try
            {
                if (cleanup)
                {
                    client?.Close().GetAwaiter().GetResult();
                }
                else
                {
                    client?.Abort();
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                client?.Dispose();
                client = null;
            }
        }
示例#2
0
        /// <summary>
        /// Restart the default Primary and Secondary silos.
        /// </summary>
        public void RestartDefaultSilos(bool pickNewDeploymentId = false)
        {
            TestingSiloOptions primarySiloOptions   = Primary != null ? this.siloInitOptions : null;
            TestingSiloOptions secondarySiloOptions = Secondary != null ? this.siloInitOptions : null;
            // Restart as the same deployment
            string deploymentId = DeploymentId;

            StopDefaultSilos();

            DeploymentId = pickNewDeploymentId ? null : deploymentId;
            if (primarySiloOptions != null)
            {
                primarySiloOptions.PickNewDeploymentId = pickNewDeploymentId;
                Primary = StartOrleansSilo(Silo.SiloType.Primary, primarySiloOptions, InstanceCounter++);
            }
            if (secondarySiloOptions != null)
            {
                secondarySiloOptions.PickNewDeploymentId = pickNewDeploymentId;
                Secondary = StartOrleansSilo(Silo.SiloType.Secondary, secondarySiloOptions, InstanceCounter++);
            }

            WaitForLivenessToStabilizeAsync().Wait();
            this.InternalClient = (IInternalClusterClient) new ClientBuilder().UseConfiguration(this.ClientConfig).Build();
            this.InternalClient.Connect().Wait();
        }
示例#3
0
        /// <summary>
        /// Initializes client runtime from client configuration object.
        /// </summary>
        private static void DoInternalInitialize(IInternalClusterClient clusterClient)
        {
            if (IsInitialized)
            {
                return;
            }

            lock (initLock)
            {
                if (!IsInitialized)
                {
                    try
                    {
                        // this is probably overkill, but this ensures isFullyInitialized false
                        // before we make a call that makes RuntimeClient.Current not null
                        isFullyInitialized = false;
                        client             = clusterClient; // Keep reference, to avoid GC problems
                        client.Connect().GetAwaiter().GetResult();

                        // this needs to be the last successful step inside the lock so
                        // IsInitialized doesn't return true until we're fully initialized
                        isFullyInitialized = true;
                    }
                    catch (Exception exc)
                    {
                        // just make sure to fully Uninitialize what we managed to partially initialize, so we don't end up in inconsistent state and can later on re-initialize.
                        Console.WriteLine("Initialization failed. {0}", exc);
                        InternalUninitialize();
                        throw;
                    }
                }
            }
        }
示例#4
0
 internal MultipleStreamsTestRunner(IInternalClusterClient client, string streamProvider, int testNum = 0, bool fullTest = true)
 {
     this.client             = client;
     this.streamProviderName = streamProvider;
     this.logger             = (TestingUtils.CreateDefaultLoggerFactory($"{this.GetType().Name}.log")).CreateLogger <MultipleStreamsTestRunner>();
     this.testNumber         = testNum;
     this.runFullTest        = fullTest;
 }
 internal MultipleStreamsTestRunner(IInternalClusterClient client, string streamProvider, int testNum = 0, bool fullTest = true)
 {
     this.client             = client;
     this.streamProviderName = streamProvider;
     this.logger             = LogManager.GetLogger("MultipleStreamsTestRunner", LoggerType.Application);
     this.testNumber         = testNum;
     this.runFullTest        = fullTest;
 }
示例#6
0
 internal SingleStreamTestRunner(IInternalClusterClient client, string streamProvider, int testNum = 0, bool fullTest = true)
 {
     this.client             = client;
     this.streamProviderName = streamProvider;
     this.logger             = new LoggerWrapper <SingleStreamTestRunner>(TestingUtils.CreateDefaultLoggerFactory($"{this.GetType().Name}.log"));
     this.testNumber         = testNum;
     this.runFullTest        = fullTest;
     this.random             = TestConstants.random;
 }
示例#7
0
 private static void InternalInitialize(IInternalClusterClient clusterClient)
 {
     if (TestOnlyNoConnect)
     {
         Trace.TraceInformation("TestOnlyNoConnect - Returning before connecting to cluster.");
     }
     else
     {
         // Finish initializing this client connection to the Orleans cluster
         DoInternalInitialize(clusterClient);
     }
 }
示例#8
0
文件: Program.cs 项目: wattsm/orleans
        private static void RunCommand(string command, string[] args)
        {
            var clientBuilder = new ClientBuilder().LoadConfiguration();

            using (client = (IInternalClusterClient)clientBuilder.Build())
            {
                client.Connect().Wait();
                systemManagement = client.GetGrain <IManagementGrain>(0);
                var options = args.Skip(1)
                              .Where(s => s.StartsWith("-"))
                              .Select(s => s.Substring(1).Split('='))
                              .ToDictionary(a => a[0].ToLowerInvariant(), a => a.Length > 1 ? a[1] : "");

                var restWithoutOptions = args.Skip(1).Where(s => !s.StartsWith("-")).ToArray();

                switch (command)
                {
                case "grainstats":
                    PrintSimpleGrainStatistics(restWithoutOptions);
                    break;

                case "fullgrainstats":
                    PrintGrainStatistics(restWithoutOptions);
                    break;

                case "collect":
                    CollectActivations(options, restWithoutOptions);
                    break;

                case "unregister":
                    var unregisterArgs = args.Skip(1).ToArray();
                    UnregisterGrain(unregisterArgs);
                    break;

                case "lookup":
                    var lookupArgs = args.Skip(1).ToArray();
                    LookupGrain(lookupArgs);
                    break;

                case "grainreport":
                    var grainReportArgs = args.Skip(1).ToArray();
                    GrainReport(grainReportArgs);
                    break;

                default:
                    PrintUsage();
                    break;
                }

                client.Close().Wait();
            }
        }
            public ClientWrapperBase(string name, int gatewayport, string clusterId, Action <IClientBuilder> clientConfigurator)
            {
                this.Name = name;
                Console.WriteLine($"Initializing client {name}");
                var internalClientBuilder = new ClientBuilder()
                                            .UseLocalhostClustering(gatewayport, clusterId, clusterId);

                clientConfigurator?.Invoke(internalClientBuilder);
                this.InternalClient = (IInternalClusterClient)internalClientBuilder.Build();
                this.InternalClient.Connect().Wait();
                var loggerFactory = this.InternalClient.ServiceProvider.GetRequiredService <ILoggerFactory>();

                this.Logger = loggerFactory.CreateLogger($"Client-{name}");
            }
示例#10
0
        internal static async Task CheckPubSubCounts(IInternalClusterClient client, ITestOutputHelper output, string when, int expectedPublisherCount, int expectedConsumerCount, Guid streamId, string streamProviderName, string streamNamespace)
        {
            var pubSub = GetStreamPubSub(client);

            int consumerCount = await pubSub.ConsumerCount(streamId, streamProviderName, streamNamespace);

            Assert_AreEqual(output, expectedConsumerCount, consumerCount, "{0} - ConsumerCount for stream {1} = {2}",
                            when, streamId, consumerCount);

            int publisherCount = await pubSub.ProducerCount(streamId, streamProviderName, streamNamespace);

            Assert_AreEqual(output, expectedPublisherCount, publisherCount, "{0} - PublisherCount for stream {1} = {2}",
                            when, streamId, publisherCount);
        }
示例#11
0
        internal static async Task CheckPubSubCounts(IInternalClusterClient client, ITestOutputHelper output, string when, int expectedPublisherCount, int expectedConsumerCount, Guid streamIdGuid, string streamProviderName, string streamNamespace)
        {
            var pubSub    = GetStreamPubSub(client);
            var streamId  = new InternalStreamId(streamProviderName, StreamId.Create(streamNamespace, streamIdGuid));
            var totalWait = TimeSpan.Zero;

            int consumerCount;

            while ((consumerCount = await pubSub.ConsumerCount(streamId)) != expectedConsumerCount)
            {
                await Task.Delay(1000);

                totalWait += TimeSpan.FromMilliseconds(1000);
                if (totalWait > TimeSpan.FromMilliseconds(5000))
                {
                    break;
                }
            }

            Assert_AreEqual(output, expectedConsumerCount, consumerCount, "{0} - ConsumerCount for stream {1} = {2}",
                            when, streamId, consumerCount);

            int publisherCount;

            totalWait = TimeSpan.Zero;
            while ((publisherCount = await pubSub.ProducerCount(streamId)) != expectedPublisherCount)
            {
                await Task.Delay(1000);

                totalWait += TimeSpan.FromMilliseconds(1000);
                if (totalWait > TimeSpan.FromMilliseconds(5000))
                {
                    break;
                }
            }

            Assert_AreEqual(output, expectedPublisherCount, publisherCount, "{0} - PublisherCount for stream {1} = {2}",
                            when, streamId, publisherCount);
        }
示例#12
0
        private async Task InitializeAsync(TestingSiloOptions options, TestingClientOptions clientOptions)
        {
            bool doStartPrimary   = false;
            bool doStartSecondary = false;

            if (options.StartFreshOrleans)
            {
                // the previous test was !startFresh, so we need to cleanup after it.
                StopAllSilosIfRunning();

                if (options.StartPrimary)
                {
                    doStartPrimary = true;
                }
                if (options.StartSecondary)
                {
                    doStartSecondary = true;
                }
            }
            else
            {
                var runningInstance = Instance;
                if (runningInstance != null)
                {
                    this.Primary            = runningInstance.Primary;
                    this.Secondary          = runningInstance.Secondary;
                    this.Globals            = runningInstance.Globals;
                    this.ClientConfig       = runningInstance.ClientConfig;
                    this.DeploymentId       = runningInstance.DeploymentId;
                    this.DeploymentIdPrefix = runningInstance.DeploymentIdPrefix;
                    this.InternalClient     = runningInstance.InternalClient;
                    this.additionalSilos.AddRange(runningInstance.additionalSilos);
                    foreach (var additionalAssembly in runningInstance.additionalAssemblies)
                    {
                        this.additionalAssemblies.Add(additionalAssembly.Key, additionalAssembly.Value);
                    }
                }

                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)));
                }
                await Task.WhenAll(handles.ToArray());

                if (doStartPrimary)
                {
                    Primary = await handles[0];
                }
                if (doStartSecondary)
                {
                    Secondary = await handles[1];
                }
            }
            else
            {
                if (doStartPrimary)
                {
                    Primary = StartOrleansSilo(Silo.SiloType.Primary, options, InstanceCounter++);
                }
                if (doStartSecondary)
                {
                    Secondary = StartOrleansSilo(Silo.SiloType.Secondary, options, InstanceCounter++);
                }
            }

            WriteLog("Done initializing cluster");

            if (this.InternalClient == null || !this.InternalClient.IsInitialized && options.StartClient)
            {
                InitializeClient(clientOptions, options.LargeMessageWarningThreshold);
            }
        }
示例#13
0
        private void InitializeClient(TestingClientOptions clientOptions, int largeMessageWarningThreshold)
        {
            if (this.Client == null)
            {
                WriteLog("Initializing Grain Client");
                ClientConfiguration clientConfig;

                try
                {
                    if (clientOptions.ClientConfigFile != null)
                    {
                        clientConfig = ClientConfiguration.LoadFromFile(clientOptions.ClientConfigFile.FullName);
                    }
                    else
                    {
                        clientConfig = ClientConfiguration.StandardLoad();
                    }
                }
                catch (FileNotFoundException)
                {
                    if (clientOptions.ClientConfigFile != null &&
                        !string.Equals(clientOptions.ClientConfigFile.Name, TestingClientOptions.DEFAULT_CLIENT_CONFIG_FILE, StringComparison.InvariantCultureIgnoreCase))
                    {
                        // if the user is not using the defaults, then throw because the file was legitimally not found
                        throw;
                    }

                    clientConfig = ClientConfiguration.LocalhostSilo();
                }

                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(this.DeploymentId))
                {
                    clientConfig.DeploymentId = this.DeploymentId;
                }
                if (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 (largeMessageWarningThreshold > 0)
                {
                    clientConfig.LargeMessageWarningThreshold = largeMessageWarningThreshold;
                }
                AdjustForTest(clientConfig, clientOptions);
                this.ClientConfig = clientConfig;

                try
                {
                    this.InternalClient = (IInternalClusterClient) new ClientBuilder().UseConfiguration(clientConfig).Build();
                    this.InternalClient.Connect().Wait();
                }
                catch
                {
                    this.InternalClient?.Abort();
                    this.InternalClient = null;
                    throw;
                }
            }
        }
示例#14
0
        internal static IStreamPubSub GetStreamPubSub(IInternalClusterClient client)
        {
            var runtime = client.ServiceProvider.GetRequiredService <IStreamProviderRuntime>();

            return(runtime.PubSub(StreamPubSubType.ExplicitGrainBasedAndImplicit));
        }
示例#15
0
        public static Task <ConsumerProxy> NewConsumerClientObjectsAsync(Guid streamId, string streamProvider, ILogger logger, IInternalClusterClient client, int consumerCount = 1)
        {
            if (consumerCount < 1)
            {
                throw new ArgumentOutOfRangeException("consumerCount", "argument must be 1 or greater");
            }
            logger.LogInformation("ConsumerProxy.NewConsumerClientObjectsAsync: multiplexing {ConsumerCount} consumer client objects for stream {StreamId}.", consumerCount, streamId);
            var objs = new IStreaming_ConsumerGrain[consumerCount];

            for (var i = 0; i < consumerCount; ++i)
            {
                objs[i] = Streaming_ConsumerClientObject.NewObserver(logger, client);
            }
            return(NewConsumerProxy(streamId, streamProvider, objs, logger, client));
        }
示例#16
0
 internal static IStreamPubSub GetStreamPubSub(IInternalClusterClient client)
 {
     return(client.StreamProviderRuntime.PubSub(StreamPubSubType.ExplicitGrainBasedAndImplicit));
 }