[#24] Client: Implement pool part1
first iteration - base classes and methods Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
d1271df207
commit
c9a75ea025
72 changed files with 2786 additions and 468 deletions
|
@ -1,71 +1,19 @@
|
|||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
using FrostFS.Refs;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.SDK.ClientV2.Interfaces;
|
||||
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
||||
using FrostFS.SDK.ClientV2;
|
||||
using FrostFS.SDK.Cryptography;
|
||||
|
||||
using Google.Protobuf;
|
||||
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FrostFS.SDK.Tests;
|
||||
|
||||
public abstract class ObjectTestsBase
|
||||
{
|
||||
protected static readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
|
||||
|
||||
protected IOptions<SingleOwnerClientSettings> Settings { get; set; }
|
||||
protected FrostFsContainerId ContainerId { get; set; }
|
||||
|
||||
protected NetworkMocker NetworkMocker { get; set; } = new NetworkMocker(key);
|
||||
protected SessionMocker SessionMocker { get; set; } = new SessionMocker(key);
|
||||
protected ContainerMocker ContainerMocker { get; set; } = new ContainerMocker(key);
|
||||
protected ObjectMocker Mocker { get; set; }
|
||||
|
||||
protected ObjectTestsBase()
|
||||
{
|
||||
var ecdsaKey = key.LoadWif();
|
||||
|
||||
Settings = Options.Create(new SingleOwnerClientSettings
|
||||
{
|
||||
Key = key,
|
||||
Host = "http://localhost:8080"
|
||||
});
|
||||
|
||||
Mocker = new ObjectMocker(key)
|
||||
{
|
||||
PlacementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)),
|
||||
Version = new FrostFsVersion(2, 13),
|
||||
ContainerGuid = Guid.NewGuid()
|
||||
};
|
||||
|
||||
ContainerId = new FrostFsContainerId(Base58.Encode(Mocker.ContainerGuid.ToBytes()));
|
||||
|
||||
Mocker.ObjectHeader = new(
|
||||
ContainerId,
|
||||
FrostFsObjectType.Regular,
|
||||
[new FrostFsAttributePair("k", "v")],
|
||||
null,
|
||||
FrostFsOwner.FromKey(ecdsaKey),
|
||||
new FrostFsVersion(2, 13));
|
||||
}
|
||||
|
||||
protected IFrostFSClient GetClient()
|
||||
{
|
||||
return FrostFSClient.GetTestInstance(
|
||||
Settings,
|
||||
null,
|
||||
NetworkMocker.GetMock().Object,
|
||||
SessionMocker.GetMock().Object,
|
||||
ContainerMocker.GetMock().Object,
|
||||
Mocker.GetMock().Object);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
||||
[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "No secure purpose")]
|
||||
public class ObjectTest : ObjectTestsBase
|
||||
{
|
||||
[Fact]
|
||||
|
@ -75,7 +23,7 @@ public class ObjectTest : ObjectTestsBase
|
|||
|
||||
var ecdsaKey = key.LoadWif();
|
||||
|
||||
var ctx = new Context
|
||||
var ctx = new CallContext
|
||||
{
|
||||
Key = ecdsaKey,
|
||||
OwnerId = FrostFsOwner.FromKey(ecdsaKey),
|
||||
|
@ -88,18 +36,21 @@ public class ObjectTest : ObjectTestsBase
|
|||
|
||||
Assert.NotNull(result);
|
||||
|
||||
Assert.Equal(Mocker.ObjectHeader!.ContainerId.GetValue(), result.Header.ContainerId.GetValue());
|
||||
Assert.Equal(Mocker.ObjectHeader!.OwnerId!.Value, result.Header.OwnerId!.Value);
|
||||
Assert.NotNull(Mocker.ObjectHeader);
|
||||
|
||||
Assert.Equal(Mocker.ObjectHeader.ContainerId.GetValue(), result.Header.ContainerId.GetValue());
|
||||
Assert.Equal(Mocker.ObjectHeader.OwnerId!.Value, result.Header.OwnerId!.Value);
|
||||
Assert.Equal(Mocker.ObjectHeader.PayloadLength, result.Header.PayloadLength);
|
||||
Assert.NotNull(result.Header.Attributes);
|
||||
Assert.Single(result.Header.Attributes);
|
||||
Assert.Equal(Mocker.ObjectHeader.Attributes[0].Key, result.Header.Attributes[0].Key);
|
||||
Assert.Equal(Mocker.ObjectHeader.Attributes[0].Value, result.Header.Attributes[0].Value);
|
||||
Assert.Equal(Mocker.ObjectHeader.Attributes![0].Key, result.Header.Attributes[0].Key);
|
||||
Assert.Equal(Mocker.ObjectHeader.Attributes![0].Value, result.Header.Attributes[0].Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async void PutObjectTest()
|
||||
{
|
||||
Mocker.ResultObjectIds = new([SHA256.HashData([])]);
|
||||
Mocker.ResultObjectIds.Add(SHA256.HashData([]));
|
||||
|
||||
Random rnd = new();
|
||||
var bytes = new byte[1024];
|
||||
|
@ -134,7 +85,7 @@ public class ObjectTest : ObjectTestsBase
|
|||
[Fact]
|
||||
public async void ClientCutTest()
|
||||
{
|
||||
NetworkMocker.Parameters = new Dictionary<string, byte[]>() { { "MaxObjectSize", [0x0, 0xa] } };
|
||||
NetworkMocker.Parameters.Add("MaxObjectSize", [0x0, 0xa]);
|
||||
|
||||
var blockSize = 2560;
|
||||
byte[] bytes = File.ReadAllBytes(@".\..\..\..\TestData\cat.jpg");
|
||||
|
@ -150,17 +101,19 @@ public class ObjectTest : ObjectTestsBase
|
|||
|
||||
Random rnd = new();
|
||||
|
||||
List<byte[]> objIds = new([new byte[32], new byte[32], new byte[32]]);
|
||||
Collection<byte[]> objIds = new([new byte[32], new byte[32], new byte[32]]);
|
||||
rnd.NextBytes(objIds.ElementAt(0));
|
||||
rnd.NextBytes(objIds.ElementAt(1));
|
||||
rnd.NextBytes(objIds.ElementAt(2));
|
||||
|
||||
Mocker.ResultObjectIds = objIds;
|
||||
foreach (var objId in objIds)
|
||||
Mocker.ResultObjectIds.Add(objId);
|
||||
|
||||
var result = await GetClient().PutObjectAsync(param);
|
||||
|
||||
var singleObjects = Mocker.PutSingleRequests.ToArray();
|
||||
|
||||
Assert.NotNull(Mocker.ClientStreamWriter?.Messages);
|
||||
var streamObjects = Mocker.ClientStreamWriter.Messages.ToArray();
|
||||
|
||||
Assert.Single(singleObjects);
|
||||
|
@ -262,6 +215,7 @@ public class ObjectTest : ObjectTestsBase
|
|||
|
||||
Assert.Equal(FrostFsObjectType.Regular, response.ObjectType);
|
||||
|
||||
Assert.NotNull(response.Attributes);
|
||||
Assert.Single(response.Attributes);
|
||||
|
||||
Assert.Equal(Mocker.HeadResponse.Attributes[0].Key, response.Attributes.First().Key);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue