예제 #1
0
        public async Task BuildAndRunClients()
        {
            this.configuration = await ConfigurationParser.GetConfiguration(this.configFilePath);

            Console.WriteLine($"Working with the following Config: {JsonConvert.SerializeObject(this.configuration)}");
            Console.WriteLine(
                $"Creating {this.configuration.ClientCount} clients.");
            Console.WriteLine($"Test will take {this.configuration.ClientConfiguration.TestDurationInMinutes} minutes.");
            BrokerFactory         brokerFactory         = new BrokerFactory(this.configuration.BrokerConfiguration);
            MessageBuilderFactory messageBuilderFactory = new MessageBuilderFactory(this.configuration.MessageBuilderConfiguration);
            ClientFactory         clientFactory         = new ClientFactory(this.configuration.ClientConfiguration, brokerFactory, messageBuilderFactory);
            var clients = clientFactory.Create(this.configuration.ClientCount);

            List <Task> taskList = new List <Task>();

            foreach (var client in clients)
            {
                var clientTask = client.RunAsync();
                taskList.Add(clientTask);
            }
            try
            {
                Task.WaitAll(taskList.ToArray());
            }
            catch (AggregateException e)
            {
                for (int j = 0; j < e.InnerExceptions.Count; j++)
                {
                    Console.WriteLine("\n-------------------------------------------------\n{0}", e.InnerExceptions[j].ToString());
                }
            }
            Console.WriteLine($"Test ended.");
        }
예제 #2
0
 public ClientFactory(ClientConfiguration clientConfiguration, BrokerFactory brokerFactory, MessageBuilderFactory messageBuilderFactory)
 {
     this.brokerFactory         = brokerFactory;
     this.messageBuilderFactory = messageBuilderFactory;
     this.clientConfiguration   = clientConfiguration;
 }