multiple nodes on one autoclient
This commit is contained in:
parent
d53b760731
commit
3c447eb4c5
|
@ -7,22 +7,6 @@
|
|||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<OpenApiReference Include="..\AutoClientCenter\swagger.json" CodeGenerator="NSwagCSharp" Namespace="AutoClientCenterAPI" Link="OpenAPIs\swagger.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.0.5">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Framework\ArgsUniform\ArgsUniform.csproj" />
|
||||
<ProjectReference Include="..\..\Framework\Logging\Logging.csproj" />
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using CodexOpenApi;
|
||||
using Logging;
|
||||
using static Org.BouncyCastle.Math.EC.ECCurve;
|
||||
using Utils;
|
||||
|
||||
namespace AutoClient
|
||||
{
|
||||
public class CodexUser
|
||||
{
|
||||
private readonly ILog log;
|
||||
private readonly CodexApi codex;
|
||||
private readonly HttpClient client;
|
||||
private readonly Address address;
|
||||
private readonly IFileGenerator generator;
|
||||
private readonly Configuration config;
|
||||
private readonly CancellationToken cancellationToken;
|
||||
|
||||
public CodexUser(ILog log, CodexApi codex, HttpClient client, Address address, IFileGenerator generator, Configuration config, CancellationToken cancellationToken)
|
||||
{
|
||||
this.log = log;
|
||||
this.codex = codex;
|
||||
this.client = client;
|
||||
this.address = address;
|
||||
this.generator = generator;
|
||||
this.config = config;
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public async Task Run()
|
||||
{
|
||||
var purchasers = new List<Purchaser>();
|
||||
for (var i = 0; i < config.NumConcurrentPurchases; i++)
|
||||
{
|
||||
purchasers.Add(new Purchaser(new LogPrefixer(log, $"({i}) "), client, address, codex, config, generator, cancellationToken));
|
||||
}
|
||||
|
||||
var delayPerPurchaser = TimeSpan.FromMinutes(config.ContractDurationMinutes) / config.NumConcurrentPurchases;
|
||||
foreach (var purchaser in purchasers)
|
||||
{
|
||||
purchaser.Start();
|
||||
await Task.Delay(delayPerPurchaser);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,11 +4,8 @@ namespace AutoClient
|
|||
{
|
||||
public class Configuration
|
||||
{
|
||||
[Uniform("codex-host", "ch", "CODEXHOST", false, "Codex Host address. (default 'http://localhost')")]
|
||||
public string CodexHost { get; set; } = "http://localhost";
|
||||
|
||||
[Uniform("codex-port", "cp", "CODEXPORT", false, "port number of Codex API. (8080 by default)")]
|
||||
public int CodexPort { get; set; } = 8080;
|
||||
[Uniform("codex-endpoints", "ce", "CODEXENDPOINTS", false, "Codex endpoints. Semi-colon separated. (default 'http://localhost:8080')")]
|
||||
public string CodexEndpoints { get; set; } = "http://localhost";
|
||||
|
||||
[Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
|
||||
public string DataPath { get; set; } = "datapath";
|
||||
|
|
|
@ -3,14 +3,27 @@ using AutoClient;
|
|||
using CodexOpenApi;
|
||||
using Core;
|
||||
using Logging;
|
||||
using Nethereum.Model;
|
||||
using Utils;
|
||||
|
||||
public static class Program
|
||||
public class Program
|
||||
{
|
||||
private readonly CancellationTokenSource cts;
|
||||
private readonly Configuration config;
|
||||
private readonly LogSplitter log;
|
||||
private readonly IFileGenerator generator;
|
||||
|
||||
public Program(CancellationTokenSource cts, Configuration config, LogSplitter log, IFileGenerator generator)
|
||||
{
|
||||
this.cts = cts;
|
||||
this.config = config;
|
||||
this.log = log;
|
||||
this.generator = generator;
|
||||
}
|
||||
|
||||
public static async Task Main(string[] args)
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
var cancellationToken = cts.Token;
|
||||
Console.CancelKeyPress += (sender, args) => cts.Cancel();
|
||||
|
||||
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
||||
|
@ -21,66 +34,64 @@ public static class Program
|
|||
throw new Exception("Number of concurrent purchases must be > 0");
|
||||
}
|
||||
|
||||
var c = new AutoClientCenterAPI.swaggerClient("", new HttpClient());
|
||||
var tasks = await c.TasksAsync();
|
||||
foreach (var task in tasks.Tasks)
|
||||
{
|
||||
foreach (var step in task.Steps)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var log = new LogSplitter(
|
||||
new FileLog(Path.Combine(config.LogPath, "autoclient")),
|
||||
new ConsoleLog()
|
||||
);
|
||||
|
||||
var generator = CreateGenerator(config, log);
|
||||
|
||||
var p = new Program(cts, config, log, generator);
|
||||
await p.Run(args);
|
||||
cts.Token.WaitHandle.WaitOne();
|
||||
log.Log("Done.");
|
||||
}
|
||||
|
||||
public async Task Run(string[] args)
|
||||
{
|
||||
var codexUsers = CreateUsers();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async Task<CodexUser[]> CreateUsers()
|
||||
{
|
||||
var endpointStrs = config.CodexEndpoints.Split(";", StringSplitOptions.RemoveEmptyEntries);
|
||||
var result = new List<CodexUser>();
|
||||
|
||||
foreach (var e in endpointStrs)
|
||||
{
|
||||
result.Add(await CreateUser(e));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
private async Task<CodexUser> CreateUser(string endpoint)
|
||||
{
|
||||
var splitIndex = endpoint.LastIndexOf(':');
|
||||
var host = endpoint.Substring(0, splitIndex);
|
||||
var port = Convert.ToInt32(endpoint.Substring(splitIndex + 1));
|
||||
|
||||
var address = new Address(
|
||||
host: config.CodexHost,
|
||||
port: config.CodexPort
|
||||
host: host,
|
||||
port: port
|
||||
);
|
||||
|
||||
log.Log($"Start. Address: {address}");
|
||||
|
||||
var generator = CreateGenerator(config, log);
|
||||
|
||||
var client = new HttpClient();
|
||||
var codex = new CodexApi(client);
|
||||
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
|
||||
|
||||
await CheckCodex(codex, log);
|
||||
await CheckCodex(codex);
|
||||
|
||||
var purchasers = new List<Purchaser>();
|
||||
for (var i = 0; i < config.NumConcurrentPurchases; i++)
|
||||
{
|
||||
purchasers.Add(
|
||||
new Purchaser(new LogPrefixer(log, $"({i}) "), client, address, codex, config, generator, cancellationToken)
|
||||
);
|
||||
return new CodexUser();
|
||||
}
|
||||
|
||||
var delayPerPurchaser = TimeSpan.FromMinutes(config.ContractDurationMinutes) / config.NumConcurrentPurchases;
|
||||
foreach (var purchaser in purchasers)
|
||||
{
|
||||
purchaser.Start();
|
||||
await Task.Delay(delayPerPurchaser);
|
||||
}
|
||||
|
||||
cancellationToken.WaitHandle.WaitOne();
|
||||
|
||||
log.Log("Done.");
|
||||
}
|
||||
|
||||
private static IFileGenerator CreateGenerator(Configuration config, LogSplitter log)
|
||||
{
|
||||
if (config.FileSizeMb > 0)
|
||||
{
|
||||
return new RandomFileGenerator(config, log);
|
||||
}
|
||||
return new ImageGenerator(log);
|
||||
}
|
||||
|
||||
private static async Task CheckCodex(CodexApi codex, ILog log)
|
||||
private async Task CheckCodex(CodexApi codex)
|
||||
{
|
||||
log.Log("Checking Codex...");
|
||||
try
|
||||
|
@ -95,6 +106,15 @@ public static class Program
|
|||
}
|
||||
}
|
||||
|
||||
private static IFileGenerator CreateGenerator(Configuration config, LogSplitter log)
|
||||
{
|
||||
if (config.FileSizeMb > 0)
|
||||
{
|
||||
return new RandomFileGenerator(config, log);
|
||||
}
|
||||
return new ImageGenerator(log);
|
||||
}
|
||||
|
||||
private static void PrintHelp()
|
||||
{
|
||||
Console.WriteLine("Generates fake data and creates Codex storage contracts for it.");
|
||||
|
|
|
@ -13,4 +13,9 @@
|
|||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Framework\Utils\Utils.csproj" />
|
||||
<ProjectReference Include="..\..\ProjectPlugins\CodexContractsPlugin\CodexContractsPlugin.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
Loading…
Reference in New Issue