コード例 #1
0
ファイル: Program.cs プロジェクト: zmyer/service-fabric
        /// <summary>
        /// The Main of the client.
        /// </summary>
        /// <param name="args">Arguments to the program.</param>
        public async Task <Dictionary <string, string> > MainWorkload(
            string TaskId,
            string ServiceName,
            string[] GatewayAddresses,
            string[] HttpGatewayAddresses,
            Uri RouterAddress,
            SecurityCredentials credentials,
            WorkloadIdentifier WorkloadId,
            Dictionary <string, string> Parameters,
            ServicePartitionType PartitionType,
            string NamedPartitionKey,
            long Int64PartitionKey,
            TimeSpan SendTimeout,
            bool RetryCall,
            int RetryCount,
            bool isDemo,
            bool useTestability,
            int loopCount,
            bool RunForever,
            bool isPAAS,
            HTTPClient.ClusterEnvironment clusterEnvironment,
            CancellationToken cancellationToken
            )
        {
            Dictionary <string, string> results = new Dictionary <string, string>();

            ScriptTestTaskId = TaskId;

            gatewayAddresses  = GatewayAddresses;
            namedPartitionKey = NamedPartitionKey;
            int64PartitionKey = Int64PartitionKey;
            sendTimeout       = SendTimeout;
            retryCount        = RetryCount;

            BasicWorkTest basicWorkTest;

            Uri serviceName = new Uri(ServiceName);

            // Run Basic Workload test.
            switch (PartitionType)
            {
            case ServicePartitionType.Singleton:
                Tracing.TraceEvent(TraceEventType.Information, 0, "Creating Test Manager: Singleton Service Name: {0}", serviceName.ToString());

                basicWorkTest = new BasicWorkTest(
                    serviceName,
                    gatewayAddresses,
                    HttpGatewayAddresses,
                    RouterAddress,
                    credentials,
                    sendTimeout,
                    retryCount,
                    isDemo,
                    useTestability,
                    isPAAS,
                    clusterEnvironment,
                    RetryCall);
                break;

            case ServicePartitionType.Uniform:
                Tracing.TraceEvent(
                    TraceEventType.Information,
                    0,
                    "Creating Test Manager: Service Name: {0}, partition key: {1}.",
                    serviceName.ToString(),
                    int64PartitionKey);

                basicWorkTest = new BasicWorkTest(
                    serviceName,
                    int64PartitionKey,
                    gatewayAddresses,
                    HttpGatewayAddresses,
                    RouterAddress,
                    credentials,
                    sendTimeout,
                    retryCount,
                    isDemo,
                    useTestability,
                    isPAAS,
                    clusterEnvironment,
                    RetryCall);
                break;

            case ServicePartitionType.Named:
                Tracing.TraceEvent(
                    TraceEventType.Information,
                    0,
                    "Creating Test Manager: Service Name: {0}, partition key: {1}.",
                    serviceName.ToString(),
                    namedPartitionKey);

                basicWorkTest = new BasicWorkTest(
                    serviceName,
                    namedPartitionKey,
                    gatewayAddresses,
                    HttpGatewayAddresses,
                    RouterAddress,
                    credentials,
                    sendTimeout,
                    retryCount,
                    isDemo,
                    useTestability,
                    isPAAS,
                    clusterEnvironment,
                    RetryCall);
                break;

            default:
                Tracing.TraceEvent(
                    TraceEventType.Critical,
                    0,
                    "Main: Unexpected type {0} when creating the test manager.",
                    PartitionType);

                Console.Error.WriteLine("MCF.Client.MainWorkload: Internal Error: Unexpected type {0} wehen creating the test manager.",
                                        PartitionType);
                return(results);
            }

            await basicWorkTest.InitializeAsync();

            if (WorkloadId == WorkloadIdentifier.LegacyWorkload)
            {
                //
                // Workload 0 is special in that it runs the workload and failover tests
                // cases as the legacy ServiceTestClient did
                //
                await basicWorkTest.RunAsync(loopCount, cancellationToken, Parameters);
            }
            else if (WorkloadId == WorkloadIdentifier.LegacyTransientFaultWorkload)
            {
                await basicWorkTest.RunTransientFaultWorkloadAsync(loopCount, cancellationToken);
            }
            else
            {
                //
                // Other workloads are dependent upon how the service implements them
                //
                results = await basicWorkTest.RunSpecificWorkloadAsync(WorkloadId, RunForever, Parameters, sendTimeout, RetryCall, cancellationToken);
            }

            return(results);
        }
コード例 #2
0
ファイル: HttpClient.cs プロジェクト: zmyer/service-fabric
        public async Task StartTest(
            Dictionary<string, string> parameters,
            string taskId,
            CancellationToken cancellationToken)
        {
            Dictionary<string, string> results;
            string serviceName = this.ServiceName;
            string namedPartitionKey = "Default";
            long int64PartitionKey = 1;
            TimeSpan sendTimeout = TimeSpan.FromMinutes(1);
            int retryCount = 64;
            bool isDemo = false;
            int loopCount = 20;
            WorkloadIdentifier workloadId = WorkloadIdentifier.LegacyWorkload;
            bool runForever = false;
            bool useTestability = true;
            bool retryCall = true;
            ServicePartitionType partitionType = ServicePartitionType.Singleton;
            bool isPAAS = false;
            ClusterEnvironment clusterEnvironment = ClusterEnvironment.Windows;

            if (parameters.ContainsKey("workloadId"))
            {
                workloadId = (WorkloadIdentifier)Enum.Parse(typeof(WorkloadIdentifier), parameters["workloadId"], true);
            }

            if (parameters.ContainsKey("serviceName"))
            {
                serviceName = parameters["serviceName"];
            }

            if (parameters.ContainsKey("runForever"))
            {
                runForever = bool.Parse(parameters["runForever"]);
            }

            if (parameters.ContainsKey("retryCall"))
            {
                retryCall = bool.Parse(parameters["retryCall"]);
            }

            if (parameters.ContainsKey("isDemo"))
            {
                isDemo = bool.Parse(parameters["isDemo"]);
            }

            if (parameters.ContainsKey("loopCount"))
            {
                loopCount = int.Parse(parameters["loopCount"]);
            }

            if (parameters.ContainsKey("retryCount"))
            {
                retryCount = int.Parse(parameters["retryCount"]);
            }

            if (parameters.ContainsKey("sendTimeout"))
            {
                sendTimeout = TimeSpan.FromMinutes(int.Parse(parameters["sendTimeout"]));
            }

            if (parameters.ContainsKey("useTestability"))
            {
                useTestability = bool.Parse(parameters["useTestability"]);
            }

            if (parameters.ContainsKey("namedPartitionKey"))
            {
                if (partitionType != ServicePartitionType.Singleton)
                {
                    throw new InvalidOperationException("Ambiguous partition type - Either namedPartitionKey or int64PartitionKey should be specified");
                }

                namedPartitionKey = parameters["namedPartitionKey"];
                partitionType = ServicePartitionType.Named;
            }

            if (parameters.ContainsKey("int64PartitionKey"))
            {
                if (partitionType != ServicePartitionType.Singleton)
                {
                    throw new InvalidOperationException("Ambiguous partition type - Either namedPartitionKey or int64PartitionKey should be specified");
                }

                int64PartitionKey = long.Parse(parameters["int64PartitionKey"]);
                partitionType = ServicePartitionType.Uniform;
            }

            // If 'PAAS' is set, that means the service is running on PAAS cluster, which also means the client 
            // cannot talk directly to the service because Azure forbids that, it needs to use the ReverseProxy 
            // service to communicate with the service.
            if (parameters.ContainsKey("PAAS"))
            {
                isPAAS = bool.Parse(parameters["PAAS"]);
            }

            if ((workloadId == WorkloadIdentifier.LegacyWorkload) && runForever)
            {
                Console.WriteLine("WARNING: runForever parameter ignored when workloadId is 0");
            }

            if (parameters.ContainsKey("clusterEnvironment"))
            {
                Enum.TryParse(parameters["clusterEnvironment"], out clusterEnvironment);
            }

            Console.WriteLine("Cluster is: " + clusterEnvironment);

            Console.WriteLine("Starting Workload");
            //ConsoleWriteDictionary(parameters);

            Console.WriteLine("PartitionType: {0}", partitionType.ToString());
            //ConsoleWriteGatewayAddresses();

            program = new Program();

            Console.WriteLine("GatewayAddress: {0}", config.GatewayAddresses);
            results = await program.MainWorkload(
                taskId, 
                serviceName, 
                config.GatewayAddresses,
                config.HttpApplicationGatewayAddresses, 
                config.ViaForwardingAddress,
                config.ClientCredentials,
                workloadId,
                parameters,
                partitionType, 
                namedPartitionKey, 
                int64PartitionKey, 
                sendTimeout, 
                retryCall, 
                retryCount, 
                isDemo, 
                useTestability, 
                loopCount,
                runForever,
                isPAAS,
                clusterEnvironment,
                cancellationToken);

            Console.WriteLine("Workload {0} Results", workloadId);
            //ConsoleWriteDictionary(results);
        }