mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-01-07 16:03:07 +00:00
multiple nodes on one autoclient
This commit is contained in:
parent
d53b760731
commit
3c447eb4c5
@ -7,22 +7,6 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</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>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\Framework\ArgsUniform\ArgsUniform.csproj" />
|
<ProjectReference Include="..\..\Framework\ArgsUniform\ArgsUniform.csproj" />
|
||||||
<ProjectReference Include="..\..\Framework\Logging\Logging.csproj" />
|
<ProjectReference Include="..\..\Framework\Logging\Logging.csproj" />
|
||||||
|
|||||||
45
Tools/AutoClient/CodexUser.cs
Normal file
45
Tools/AutoClient/CodexUser.cs
Normal file
@ -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
|
public class Configuration
|
||||||
{
|
{
|
||||||
[Uniform("codex-host", "ch", "CODEXHOST", false, "Codex Host address. (default 'http://localhost')")]
|
[Uniform("codex-endpoints", "ce", "CODEXENDPOINTS", false, "Codex endpoints. Semi-colon separated. (default 'http://localhost:8080')")]
|
||||||
public string CodexHost { get; set; } = "http://localhost";
|
public string CodexEndpoints { 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("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
|
[Uniform("datapath", "dp", "DATAPATH", false, "Root path where all data files will be saved.")]
|
||||||
public string DataPath { get; set; } = "datapath";
|
public string DataPath { get; set; } = "datapath";
|
||||||
|
|||||||
@ -3,14 +3,27 @@ using AutoClient;
|
|||||||
using CodexOpenApi;
|
using CodexOpenApi;
|
||||||
using Core;
|
using Core;
|
||||||
using Logging;
|
using Logging;
|
||||||
|
using Nethereum.Model;
|
||||||
using Utils;
|
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)
|
public static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
var cts = new CancellationTokenSource();
|
var cts = new CancellationTokenSource();
|
||||||
var cancellationToken = cts.Token;
|
|
||||||
Console.CancelKeyPress += (sender, args) => cts.Cancel();
|
Console.CancelKeyPress += (sender, args) => cts.Cancel();
|
||||||
|
|
||||||
var uniformArgs = new ArgsUniform<Configuration>(PrintHelp, args);
|
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");
|
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(
|
var log = new LogSplitter(
|
||||||
new FileLog(Path.Combine(config.LogPath, "autoclient")),
|
new FileLog(Path.Combine(config.LogPath, "autoclient")),
|
||||||
new ConsoleLog()
|
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(
|
var address = new Address(
|
||||||
host: config.CodexHost,
|
host: host,
|
||||||
port: config.CodexPort
|
port: port
|
||||||
);
|
);
|
||||||
|
|
||||||
log.Log($"Start. Address: {address}");
|
log.Log($"Start. Address: {address}");
|
||||||
|
|
||||||
var generator = CreateGenerator(config, log);
|
|
||||||
|
|
||||||
var client = new HttpClient();
|
var client = new HttpClient();
|
||||||
var codex = new CodexApi(client);
|
var codex = new CodexApi(client);
|
||||||
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
|
codex.BaseUrl = $"{address.Host}:{address.Port}/api/codex/v1";
|
||||||
|
|
||||||
await CheckCodex(codex, log);
|
await CheckCodex(codex);
|
||||||
|
|
||||||
var purchasers = new List<Purchaser>();
|
return new CodexUser();
|
||||||
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;
|
private async Task CheckCodex(CodexApi codex)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
log.Log("Checking Codex...");
|
log.Log("Checking Codex...");
|
||||||
try
|
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()
|
private static void PrintHelp()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Generates fake data and creates Codex storage contracts for it.");
|
Console.WriteLine("Generates fake data and creates Codex storage contracts for it.");
|
||||||
|
|||||||
@ -13,4 +13,9 @@
|
|||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Framework\Utils\Utils.csproj" />
|
||||||
|
<ProjectReference Include="..\..\ProjectPlugins\CodexContractsPlugin\CodexContractsPlugin.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user