[#21] Client: Allows multinenant client
All checks were successful
DCO / DCO (pull_request) Successful in 27s
All checks were successful
DCO / DCO (pull_request) Successful in 27s
Using one client for several owners Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
parent
18126ea763
commit
2a28806ace
30 changed files with 349 additions and 281 deletions
|
@ -16,12 +16,12 @@ public abstract class ContainerTestsBase
|
|||
{
|
||||
protected readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
|
||||
|
||||
protected IOptions<ClientSettings> Settings { get; set; }
|
||||
protected IOptions<SingleOwnerClientSettings> Settings { get; set; }
|
||||
protected ContainerMocker Mocker { get; set; }
|
||||
|
||||
protected ContainerTestsBase()
|
||||
{
|
||||
Settings = Options.Create(new ClientSettings
|
||||
Settings = Options.Create(new SingleOwnerClientSettings
|
||||
{
|
||||
Key = key,
|
||||
Host = "http://localhost:8080"
|
||||
|
|
|
@ -19,7 +19,7 @@ public abstract class ObjectTestsBase
|
|||
{
|
||||
protected static readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
|
||||
|
||||
protected IOptions<ClientSettings> Settings { get; set; }
|
||||
protected IOptions<SingleOwnerClientSettings> Settings { get; set; }
|
||||
protected ContainerId ContainerId { get; set; }
|
||||
|
||||
protected NetworkMocker NetworkMocker { get; set; } = new NetworkMocker(key);
|
||||
|
@ -31,7 +31,7 @@ public abstract class ObjectTestsBase
|
|||
{
|
||||
var ecdsaKey = key.LoadWif();
|
||||
|
||||
Settings = Options.Create(new ClientSettings
|
||||
Settings = Options.Create(new SingleOwnerClientSettings
|
||||
{
|
||||
Key = key,
|
||||
Host = "http://localhost:8080"
|
||||
|
@ -71,14 +71,17 @@ public class ObjectTest : ObjectTestsBase
|
|||
public async void GetObjectTest()
|
||||
{
|
||||
var client = GetClient();
|
||||
var objectId = client.CalculateObjectId(Mocker.ObjectHeader!);
|
||||
|
||||
var context = new Context
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(2)
|
||||
};
|
||||
var ecdsaKey = key.LoadWif();
|
||||
|
||||
var result = await client.GetObjectAsync(new PrmObjectGet(ContainerId, objectId) { Context = context });
|
||||
var ctx = new Context {
|
||||
Key = ecdsaKey,
|
||||
OwnerId = OwnerId.FromKey(ecdsaKey),
|
||||
Version = new ModelsV2.Version(2, 13) };
|
||||
|
||||
var objectId = client.CalculateObjectId(Mocker.ObjectHeader!, ctx);
|
||||
|
||||
var result = await client.GetObjectAsync(new PrmObjectGet(ContainerId, objectId) { Context = ctx });
|
||||
|
||||
Assert.NotNull(result);
|
||||
|
||||
|
|
|
@ -13,21 +13,46 @@ using System.Diagnostics;
|
|||
|
||||
using static FrostFS.Session.SessionToken.Types.Body;
|
||||
using FrostFS.SDK.ClientV2.Parameters;
|
||||
using FrostFS.SDK.Tests;
|
||||
|
||||
namespace FrostFS.SDK.SmokeTests;
|
||||
|
||||
public class SmokeTests
|
||||
public abstract class SmokeTestsBase
|
||||
{
|
||||
protected readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
|
||||
protected readonly string url = "http://172.23.32.4:8080";
|
||||
|
||||
protected ECDsa Key { get; }
|
||||
|
||||
protected OwnerId OwnerId { get; }
|
||||
|
||||
protected ModelsV2.Version Version { get; }
|
||||
|
||||
protected Context Ctx { get; }
|
||||
|
||||
protected SmokeTestsBase()
|
||||
{
|
||||
Key = key.LoadWif();
|
||||
OwnerId = OwnerId.FromKey(Key);
|
||||
Version = new ModelsV2.Version(2, 13);
|
||||
|
||||
Ctx = new Context { Key = Key, OwnerId = OwnerId, Version = Version };
|
||||
}
|
||||
}
|
||||
|
||||
public class SmokeTests : SmokeTestsBase
|
||||
{
|
||||
private static readonly PrmWait lightWait = new (100, 1);
|
||||
private readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
|
||||
private readonly string url = "http://172.23.32.4:8080";
|
||||
|
||||
[Fact]
|
||||
public async void NetworkMapTest()
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
|
||||
var result = await client.GetNetmapSnapshotAsync();
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async void NetworkMapTest(bool isSingleOnwerClient)
|
||||
{
|
||||
using var client = isSingleOnwerClient ? Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url)) : Client.GetInstance(GetOptions(this.url));
|
||||
|
||||
PrmNetmapSnapshot? prm = isSingleOnwerClient ? default : new () { Context = Ctx };
|
||||
var result = await client.GetNetmapSnapshotAsync(prm);
|
||||
|
||||
Assert.True(result.Epoch > 0);
|
||||
Assert.Single(result.NodeInfoCollection);
|
||||
|
@ -41,12 +66,17 @@ public class SmokeTests
|
|||
Assert.Equal(9, item.Attributes.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void NodeInfoTest()
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
|
||||
var result = await client.GetNodeInfoAsync();
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async void NodeInfoTest(bool isSingleOnwerClient)
|
||||
{
|
||||
using var client = isSingleOnwerClient ? Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url)) : Client.GetInstance(GetOptions(this.url));
|
||||
|
||||
PrmNodeInfo? prm = isSingleOnwerClient ? default : new() { Context = Ctx };
|
||||
|
||||
var result = await client.GetNodeInfoAsync(prm);
|
||||
|
||||
Assert.Equal(2, result.Version.Major);
|
||||
Assert.Equal(13, result.Version.Minor);
|
||||
|
@ -64,25 +94,25 @@ public class SmokeTests
|
|||
Callback = (cs) => Console.WriteLine($"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds")
|
||||
};
|
||||
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
var result = await client.GetNodeInfoAsync();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void GetSessionTest()
|
||||
[Theory]
|
||||
[InlineData(false)]
|
||||
[InlineData(true)]
|
||||
public async void GetSessionTest(bool isSingleOnwerClient)
|
||||
{
|
||||
var ecdsaKey = this.key.LoadWif();
|
||||
using var client = isSingleOnwerClient ? Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url)) : Client.GetInstance(GetOptions(this.url));
|
||||
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
PrmSessionCreate? prm = isSingleOnwerClient ? new PrmSessionCreate(100) : new PrmSessionCreate(100) { Context = Ctx };
|
||||
|
||||
var token = await client.CreateSessionAsync(new PrmSessionCreate(100));
|
||||
var token = await client.CreateSessionAsync(prm);
|
||||
|
||||
var session = new Session.SessionToken().Deserialize(token.Token);
|
||||
|
||||
var owner = OwnerId.FromKey(ecdsaKey);
|
||||
|
||||
var ownerHash = Base58.Decode(owner.Value);
|
||||
var ownerHash = Base58.Decode(OwnerId.Value);
|
||||
|
||||
Assert.NotNull(session);
|
||||
Assert.Null(session.Body.Container);
|
||||
|
@ -97,7 +127,7 @@ public class SmokeTests
|
|||
[Fact]
|
||||
public async void CreateObjectWithSessionToken()
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
await Cleanup(client);
|
||||
|
||||
|
@ -144,7 +174,7 @@ public class SmokeTests
|
|||
[Fact]
|
||||
public async void FilterTest()
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
await Cleanup(client);
|
||||
|
||||
|
@ -230,7 +260,7 @@ public class SmokeTests
|
|||
[InlineData(6 * 1024 * 1024 + 100)]
|
||||
public async void SimpleScenarioTest(int objectSize)
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
await Cleanup(client);
|
||||
|
||||
|
@ -253,7 +283,7 @@ public class SmokeTests
|
|||
|
||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
||||
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId,ctx));
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId) { Context = ctx });
|
||||
Assert.NotNull(container);
|
||||
Assert.True(callbackInvoked);
|
||||
|
||||
|
@ -318,7 +348,7 @@ public class SmokeTests
|
|||
[InlineData(6 * 1024 * 1024 + 100)]
|
||||
public async void SimpleScenarioWithSessionTest(int objectSize)
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue));
|
||||
|
||||
|
@ -338,7 +368,7 @@ public class SmokeTests
|
|||
|
||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
||||
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId,ctx));
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId) { Context = ctx });
|
||||
Assert.NotNull(container);
|
||||
|
||||
var bytes = GetRandomBytes(objectSize);
|
||||
|
@ -406,7 +436,7 @@ public class SmokeTests
|
|||
[InlineData(200)]
|
||||
public async void ClientCutScenarioTest(int objectSize)
|
||||
{
|
||||
using var client = Client.GetInstance(GetOptions(this.key, this.url));
|
||||
using var client = Client.GetSingleOwnerInstance(GetSingleOwnerOptions(this.key, this.url));
|
||||
|
||||
await Cleanup(client);
|
||||
|
||||
|
@ -417,13 +447,13 @@ public class SmokeTests
|
|||
|
||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
||||
|
||||
var context = new Context
|
||||
var ctx = new Context
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(10),
|
||||
Interceptors = new([new MetricsInterceptor()])
|
||||
};
|
||||
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId, context));
|
||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId) { Context = ctx });
|
||||
|
||||
Assert.NotNull(container);
|
||||
|
||||
|
@ -499,11 +529,19 @@ public class SmokeTests
|
|||
return bytes;
|
||||
}
|
||||
|
||||
private static IOptions<ClientSettings> GetOptions(string key, string url)
|
||||
private static IOptions<SingleOwnerClientSettings> GetSingleOwnerOptions(string key, string url)
|
||||
{
|
||||
return Options.Create(new SingleOwnerClientSettings
|
||||
{
|
||||
Key = key,
|
||||
Host = url
|
||||
});
|
||||
}
|
||||
|
||||
private static IOptions<ClientSettings> GetOptions(string url)
|
||||
{
|
||||
return Options.Create(new ClientSettings
|
||||
{
|
||||
Key = key,
|
||||
Host = url
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue