public override async Task Init() { var services = new ServiceCollection(); services.AddOptions(); services.AddLogging(); services.Configure <PostgreStorageOptions>(o => { o.ConnectionString = "Host=localhost;Port=5432;Username=postgres;Password=123456;Database=HttpReports;"; }); services.AddTransient <PostgreSQLStorage>(); services.AddSingleton <PostgreConnectionFactory>(); _storage = services.BuildServiceProvider().GetRequiredService <PostgreSQLStorage>(); await _storage.InitAsync(); }
public static Task InsertTestAsync(PostgreSQLStorage storage, int a, int b, int c) { var startTime = DateTime.Now.AddSeconds(-1); var count = 100000; var random = new Random(); string[] Services = { "User", "User", "User", "User", "User", "Order", "Order", "Order", "Order", "Weixin", "Weixin", "Payment", "Log", "Log", "Log", "DataCenter", "Student", "Student", "Master" }; string[] LoginUsers = { "Jack", "Blues", "Mark", "Tom", "Cat" }; string[] ParentServices = { "User", "Order", "Weixin", "Payment", "Log", "DataCenter" }; string[] LocalIPs = { "192.168.1.1", "192.168.1.1", "192.168.1.1", "192.168.1.2", "192.168.1.2", "192.168.1.2", "192.168.1.3", "192.168.1.3", "192.168.1.4", "192.168.1.5", "192.168.1.6" }; string[] Route = { "/User/Login", "/User/Payment", "/User/Payment", "/User/Payment", "/User/Payment", "/User/Payment", "/User/Search", "/User/Search", "/User/Search", "/Data/QueryData", "/Data/GetCofnig", "/Data/GetCofnig", "/User/LoadData" }; int[] LocalPort = { 8801, 8801, 8801, 8801, 8802, 8802, 8802, 8803, 8803, 8804, 8805, 8806 }; //Task.Run(() => Insert()); //Task.Run(() => Insert()); //Task.Run(() => Insert()); //Task.Run(() => Insert()); //Task.Run(() => Insert()); //Task.Run(() => Insert()); Insert(); return(Task.CompletedTask); void Insert() { for (int i = 0; i < 10000000; i++) { List <Core.RequestBag> requestBags = new List <Core.RequestBag>(); for (int c = 0; c < a; c++) { var _Service = Services[new Random().Next(0, Services.Length - 1)]; var _ParentService = ParentServices[new Random().Next(0, ParentServices.Length - 1)]; var _url = Route[new Random().Next(0, Route.Length - 1)]; if (_ParentService == _Service) { _ParentService = string.Empty; } var info = new RequestInfo { Id = MD5_16(Guid.NewGuid().ToString()), ParentId = "", Service = _Service, ParentService = _ParentService, Route = _url, Url = _url, RequestType = "http", Method = "POST", LoginUser = LoginUsers[new Random().Next(0, LoginUsers.Length - 1)], Milliseconds = _Service switch { "User" => new Random().Next(1400, 1600), "Order" => new Random().Next(1200, 1600), "Weixin" => new Random().Next(600, 1600), "Log" => new Random().Next(100, 500), "Payment" => new Random().Next(100, 800), _ => new Random().Next(1, 1600) }, StatusCode = _Service switch { "User" => new Random().Next(1, 10) > 1 ? 200 : 500, "Order" => new Random().Next(1, 10) > 3 ? 200 : 500, "Weixin" => new Random().Next(1, 10) > 7 ? 200 : 500, "Log" => new Random().Next(1, 10) > 6 ? 200 : 500, "Payment" => new Random().Next(1, 10) > 4 ? 200 : 500, _ => new Random().Next(1, 10) > 5 ? 200 : 500 },