Ejemplo n.º 1
0
        public async Task InitializeAsync(RequestSenderSpecifications requestSenderSpecifications)
        {
            // Wait for all partitions of the service to become ready to accept requests.
            FabricClient fabricClient = new FabricClient();
            await AwaitPartitionReadyOperation.PerformAsync(fabricClient, this.ServiceName);

            await this.OnInitializeAsync(requestSenderSpecifications);
        }
        private static async Task MainAsync(string[] args)
        {
            // Read the parameters from the configuration file and command line
            Parameters parameters = new Parameters();

            parameters.ReadFromConfigFile();
            parameters.OverrideFromCommandLine(args);

            // Create the test specifications for each client
            int numClients = (int)parameters.ParameterValues[Parameters.Id.NumClients];

            TestSpecifications[] testSpecifications = CreateTestSpecifications(parameters, numClients);

            // Wait until the load driver service (that hosts the clients) is ready
            X509Credentials credentials = new X509Credentials()
            {
                StoreLocation = StoreLocation.LocalMachine,
                StoreName     = new X509Store(StoreName.My, StoreLocation.LocalMachine).Name,
                FindType      = X509FindType.FindByThumbprint,
                FindValue     = (string)parameters.ParameterValues[Parameters.Id.ClientCertificateThumbprint],
            };

            credentials.RemoteCertThumbprints.Add(
                (string)parameters.ParameterValues[Parameters.Id.ServerCertificateThumbprint]);

            FabricClient fabricClient = new FabricClient(
                credentials,
                new FabricClientSettings(),
                GetEndpointAddress(
                    (string)parameters.ParameterValues[Parameters.Id.ClusterAddress],
                    (int)parameters.ParameterValues[Parameters.Id.ClientConnectionPort]));
            ServicePartitionList partitionList = await AwaitPartitionReadyOperation.PerformAsync(
                fabricClient,
                LoadDriverServiceUri);

            // Verify that the load driver service has at least as many partitions as the number of
            // clients that we need to create.
            if (partitionList.Count < numClients)
            {
                string message = String.Format(
                    "The value for parameter '{0}' ({1}) should not be greater than the number of partitions ({2}) of the '{3}' service.",
                    Parameters.ParameterNames.Single(kvp => (kvp.Value == Parameters.Id.NumClients)).Key,
                    numClients,
                    partitionList.Count,
                    LoadDriverServiceUri.AbsoluteUri);
                throw new ConfigurationErrorsException(message);
            }

            // Get the interfaces for each instance of the load driver service.
            ILoadDriver[] loadDrivers = CreateLoadDrivers(
                GetEndpointAddress(
                    (string)parameters.ParameterValues[Parameters.Id.ClusterAddress],
                    (int)parameters.ParameterValues[Parameters.Id.ReverseProxyPort]),
                partitionList);

            // Create and initialize the clients inside the load driver service.
            Task[] initializationTasks = new Task[numClients];
            for (int i = 0; i < numClients; i++)
            {
                initializationTasks[i] = loadDrivers[i].InitializeAsync(testSpecifications[i]);
            }
            await Task.WhenAll(initializationTasks);

            // Run the tests
            TestResults writeTestResults = await RunTestAsync(
                numClients,
                loadDrivers,
                ld => ld.RunWriteTestAsync());

            TestResults readTestResults = await RunTestAsync(
                numClients,
                loadDrivers,
                ld => ld.RunReadTestAsync());

            // Display the results
            Console.WriteLine("Write test results - {0}", writeTestResults);
            Console.WriteLine("Read test results - {0}", readTestResults);
        }