[#28] Clients: Make immutable parameters
Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
parent
749000a090
commit
9bb7b5eff8
62 changed files with 2742 additions and 963 deletions
|
@ -49,7 +49,7 @@ public class FrostFSClient : IFrostFSClient
|
||||||
|
|
||||||
internal ClientContext ClientCtx { get; set; }
|
internal ClientContext ClientCtx { get; set; }
|
||||||
|
|
||||||
public static IFrostFSClient GetSingleOwnerInstance(IOptions<ClientSettings> clientOptions, GrpcChannelOptions? channelOptions = null)
|
public static IFrostFSClient GetInstance(IOptions<ClientSettings> clientOptions, GrpcChannelOptions? channelOptions = null)
|
||||||
{
|
{
|
||||||
return new FrostFSClient(clientOptions, channelOptions);
|
return new FrostFSClient(clientOptions, channelOptions);
|
||||||
}
|
}
|
||||||
|
@ -170,229 +170,134 @@ public class FrostFSClient : IFrostFSClient
|
||||||
}
|
}
|
||||||
|
|
||||||
#region ApeManagerImplementation
|
#region ApeManagerImplementation
|
||||||
public Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args)
|
public Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetApeManagerService().AddChainAsync(args, ctx);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = GetApeManagerService();
|
public Task RemoveChainAsync(PrmApeChainRemove args, CallContext ctx)
|
||||||
return service.AddChainAsync(args);
|
{
|
||||||
|
return GetApeManagerService().RemoveChainAsync(args, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task RemoveChainAsync(PrmApeChainRemove args)
|
public Task<Chain[]> ListChainAsync(PrmApeChainList args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetApeManagerService().ListChainAsync(args, ctx);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
}
|
|
||||||
|
|
||||||
var service = GetApeManagerService();
|
|
||||||
return service.RemoveChainAsync(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<Chain[]> ListChainAsync(PrmApeChainList args)
|
|
||||||
{
|
|
||||||
if (args is null)
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetApeManagerService();
|
|
||||||
return service.ListChainAsync(args);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ContainerImplementation
|
#region ContainerImplementation
|
||||||
public Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args)
|
public Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetContainerService().GetContainerAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetContainerService();
|
|
||||||
return service.GetContainerAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll? args = null)
|
public IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args, CallContext ctx)
|
||||||
{
|
{
|
||||||
args ??= new PrmContainerGetAll();
|
return GetContainerService().ListContainersAsync(args, ctx);
|
||||||
var service = GetContainerService();
|
|
||||||
return service.ListContainersAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args)
|
public Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetContainerService().CreateContainerAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetContainerService();
|
|
||||||
return service.CreateContainerAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task DeleteContainerAsync(PrmContainerDelete args)
|
public Task DeleteContainerAsync(PrmContainerDelete args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetContainerService().DeleteContainerAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetContainerService();
|
|
||||||
return service.DeleteContainerAsync(args);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region NetworkImplementation
|
#region NetworkImplementation
|
||||||
public Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(PrmNetmapSnapshot? args)
|
public Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
args ??= new PrmNetmapSnapshot();
|
return GetNetmapService().GetNetmapSnapshotAsync(ctx);
|
||||||
var service = GetNetmapService();
|
|
||||||
return service.GetNetmapSnapshotAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsNodeInfo> GetNodeInfoAsync(PrmNodeInfo? args)
|
public Task<FrostFsNodeInfo> GetNodeInfoAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
args ??= new PrmNodeInfo();
|
return GetNetmapService().GetLocalNodeInfoAsync(ctx);
|
||||||
var service = GetNetmapService();
|
|
||||||
return service.GetLocalNodeInfoAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<NetworkSettings> GetNetworkSettingsAsync(PrmNetworkSettings? args)
|
public Task<NetworkSettings> GetNetworkSettingsAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
args ??= new PrmNetworkSettings();
|
return GetNetmapService().GetNetworkSettingsAsync(ctx);
|
||||||
var service = GetNetmapService();
|
|
||||||
return service.GetNetworkSettingsAsync(args.Context!);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ObjectImplementation
|
#region ObjectImplementation
|
||||||
public Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args)
|
public Task<FrostFsHeaderResult> GetObjectHeadAsync(PrmObjectHeadGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().GetObjectHeadAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.GetObjectHeadAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsObject> GetObjectAsync(PrmObjectGet args)
|
public Task<FrostFsObject> GetObjectAsync(PrmObjectGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().GetObjectAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.GetObjectAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<RangeReader> GetRangeAsync(PrmRangeGet args)
|
public Task<RangeReader> GetRangeAsync(PrmRangeGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().GetRangeAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.GetRangeAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args)
|
public Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().GetRangeHashAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.GetRangeHashAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args)
|
public Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().PutObjectAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.PutObjectAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args)
|
public Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().PutSingleObjectAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.PutSingleObjectAsync(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
|
public Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().PatchObjectAsync(args, ctx);
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var service = GetObjectService();
|
public Task DeleteObjectAsync(PrmObjectDelete args, CallContext ctx)
|
||||||
return service.PatchObjectAsync(args);
|
{
|
||||||
|
return GetObjectService().DeleteObjectAsync(args, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task DeleteObjectAsync(PrmObjectDelete args)
|
public IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
return GetObjectService().SearchObjectsAsync(args, ctx);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.DeleteObjectAsync(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args)
|
|
||||||
{
|
|
||||||
if (args is null)
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetObjectService();
|
|
||||||
return service.SearchObjectsAsync(args);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Session Implementation
|
#region Session Implementation
|
||||||
public async Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args)
|
public async Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
var token = await CreateSessionInternalAsync(args, ctx).ConfigureAwait(false);
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var token = await CreateSessionInternalAsync(args).ConfigureAwait(false);
|
|
||||||
|
|
||||||
return new FrostFsSessionToken(token);
|
return new FrostFsSessionToken(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Task<SessionToken> CreateSessionInternalAsync(PrmSessionCreate args)
|
internal Task<SessionToken> CreateSessionInternalAsync(PrmSessionCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
var service = GetSessionService();
|
var service = GetSessionService();
|
||||||
return service.CreateSessionAsync(args);
|
return service.CreateSessionAsync(args, ctx);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Accounting Implementation
|
#region Accounting Implementation
|
||||||
public async Task<Accounting.Decimal> GetBalanceAsync(PrmBalance? args)
|
public async Task<Accounting.Decimal> GetBalanceAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
args ??= new PrmBalance();
|
return await GetAccouningService().GetBallance(ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
var service = GetAccouningService();
|
|
||||||
return await service.GetBallance(args).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ToolsImplementation
|
private async void CheckFrostFsVersionSupport(CallContext ctx)
|
||||||
public FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header)
|
|
||||||
{
|
{
|
||||||
if (header == null)
|
|
||||||
throw new ArgumentNullException(nameof(header));
|
|
||||||
|
|
||||||
return ObjectTools.CalculateObjectId(header, this.ClientCtx);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private async void CheckFrostFsVersionSupport(CallContext? ctx = default)
|
|
||||||
{
|
|
||||||
var args = new PrmNodeInfo(ctx);
|
|
||||||
|
|
||||||
var service = GetNetmapService();
|
var service = GetNetmapService();
|
||||||
var localNodeInfo = await service.GetLocalNodeInfoAsync(args).ConfigureAwait(false);
|
var localNodeInfo = await service.GetLocalNodeInfoAsync(ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
if (!localNodeInfo.Version.IsSupported(ClientCtx.Version))
|
if (!localNodeInfo.Version.IsSupported(ClientCtx.Version))
|
||||||
{
|
{
|
||||||
|
@ -559,10 +464,8 @@ public class FrostFSClient : IFrostFSClient
|
||||||
|
|
||||||
public async Task<string?> Dial(CallContext ctx)
|
public async Task<string?> Dial(CallContext ctx)
|
||||||
{
|
{
|
||||||
var prm = new PrmBalance(ctx);
|
|
||||||
|
|
||||||
var service = GetAccouningService();
|
var service = GetAccouningService();
|
||||||
_ = await service.GetBallance(prm).ConfigureAwait(false);
|
_ = await service.GetBallance(ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,61 +9,57 @@ namespace FrostFS.SDK.Client.Interfaces;
|
||||||
public interface IFrostFSClient : IDisposable
|
public interface IFrostFSClient : IDisposable
|
||||||
{
|
{
|
||||||
#region Network
|
#region Network
|
||||||
Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(PrmNetmapSnapshot? args = null);
|
Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsNodeInfo> GetNodeInfoAsync(PrmNodeInfo? args = null);
|
Task<FrostFsNodeInfo> GetNodeInfoAsync(CallContext ctx);
|
||||||
|
|
||||||
Task<NetworkSettings> GetNetworkSettingsAsync(PrmNetworkSettings? args = null);
|
Task<NetworkSettings> GetNetworkSettingsAsync(CallContext ctx);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Session
|
#region Session
|
||||||
Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args);
|
Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args, CallContext ctx);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ApeManager
|
#region ApeManager
|
||||||
Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args);
|
Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args, CallContext ctx);
|
||||||
|
|
||||||
Task RemoveChainAsync(PrmApeChainRemove args);
|
Task RemoveChainAsync(PrmApeChainRemove args, CallContext ctx);
|
||||||
|
|
||||||
Task<Chain[]> ListChainAsync(PrmApeChainList args);
|
Task<Chain[]> ListChainAsync(PrmApeChainList args, CallContext ctx);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Container
|
#region Container
|
||||||
Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args);
|
Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args, CallContext ctx);
|
||||||
|
|
||||||
IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll? args = null);
|
IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args, CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args);
|
Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args, CallContext ctx);
|
||||||
|
|
||||||
Task DeleteContainerAsync(PrmContainerDelete args);
|
Task DeleteContainerAsync(PrmContainerDelete args, CallContext ctx);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Object
|
#region Object
|
||||||
Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args);
|
Task<FrostFsHeaderResult> GetObjectHeadAsync(PrmObjectHeadGet args, CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsObject> GetObjectAsync(PrmObjectGet args);
|
Task<FrostFsObject> GetObjectAsync(PrmObjectGet args, CallContext ctx);
|
||||||
|
|
||||||
Task<RangeReader> GetRangeAsync(PrmRangeGet args);
|
Task<RangeReader> GetRangeAsync(PrmRangeGet args, CallContext ctx);
|
||||||
|
|
||||||
Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args);
|
Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args, CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args);
|
Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args, CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args);
|
Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx);
|
||||||
|
|
||||||
Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args);
|
Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args, CallContext ctx);
|
||||||
|
|
||||||
Task DeleteObjectAsync(PrmObjectDelete args);
|
Task DeleteObjectAsync(PrmObjectDelete args, CallContext ctx);
|
||||||
|
|
||||||
IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args);
|
IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args, CallContext ctx);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Account
|
#region Account
|
||||||
Task<Accounting.Decimal> GetBalanceAsync(PrmBalance? args = null);
|
Task<Accounting.Decimal> GetBalanceAsync(CallContext ctx);
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Tools
|
|
||||||
FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header);
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Task<string?> Dial(CallContext ctx);
|
public Task<string?> Dial(CallContext ctx);
|
||||||
|
|
|
@ -36,13 +36,19 @@ public struct FrostFsChainTarget(FrostFsTargetType type, string name) : IEquatab
|
||||||
|
|
||||||
public override readonly bool Equals(object obj)
|
public override readonly bool Equals(object obj)
|
||||||
{
|
{
|
||||||
var target = (FrostFsChainTarget)obj;
|
if (obj == null || obj is not FrostFsChainTarget)
|
||||||
return Equals(target);
|
return false;
|
||||||
|
|
||||||
|
return Equals((FrostFsChainTarget)obj);
|
||||||
|
}
|
||||||
|
public readonly bool Equals(FrostFsChainTarget other)
|
||||||
|
{
|
||||||
|
return Type == other.Type && Name.Equals(other.Name, StringComparison.Ordinal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override readonly int GetHashCode()
|
public override readonly int GetHashCode()
|
||||||
{
|
{
|
||||||
return $"{Name}{Type}".GetHashCode();
|
return Name.GetHashCode() ^ (int)Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(FrostFsChainTarget left, FrostFsChainTarget right)
|
public static bool operator ==(FrostFsChainTarget left, FrostFsChainTarget right)
|
||||||
|
@ -54,9 +60,4 @@ public struct FrostFsChainTarget(FrostFsTargetType type, string name) : IEquatab
|
||||||
{
|
{
|
||||||
return !(left == right);
|
return !(left == right);
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly bool Equals(FrostFsChainTarget other)
|
|
||||||
{
|
|
||||||
return Type == other.Type && Name.Equals(other.Name, StringComparison.Ordinal);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace FrostFS.SDK;
|
||||||
|
|
||||||
|
public class FrostFsHeaderResult
|
||||||
|
{
|
||||||
|
public FrostFsObjectHeader? HeaderInfo { get; internal set; }
|
||||||
|
|
||||||
|
public FrostFsSplitInfo? SplitInfo { get; internal set; }
|
||||||
|
}
|
|
@ -24,5 +24,4 @@ public class FrostFsSplit(SplitId splitId,
|
||||||
public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader;
|
public FrostFsObjectHeader? ParentHeader { get; set; } = parentHeader;
|
||||||
|
|
||||||
public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children;
|
public ReadOnlyCollection<FrostFsObjectId>? Children { get; } = children;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
26
src/FrostFS.SDK.Client/Models/Object/FrostFsSplitInfo.cs
Normal file
26
src/FrostFS.SDK.Client/Models/Object/FrostFsSplitInfo.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
using FrostFS.Object;
|
||||||
|
using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
|
namespace FrostFS.SDK;
|
||||||
|
|
||||||
|
public class FrostFsSplitInfo
|
||||||
|
{
|
||||||
|
private readonly SplitInfo _splitInfo;
|
||||||
|
|
||||||
|
private SplitId? _splitId;
|
||||||
|
|
||||||
|
private FrostFsObjectId? _link;
|
||||||
|
|
||||||
|
private FrostFsObjectId? _lastPart;
|
||||||
|
|
||||||
|
internal FrostFsSplitInfo(SplitInfo splitInfo)
|
||||||
|
{
|
||||||
|
_splitInfo = splitInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SplitId SplitId => _splitId ??= new SplitId(_splitInfo.SplitId.ToUuid());
|
||||||
|
|
||||||
|
public FrostFsObjectId Link => _link ??= FrostFsObjectId.FromHash(_splitInfo.Link.Value.Span);
|
||||||
|
|
||||||
|
public FrostFsObjectId LastPart => _lastPart ??= FrostFsObjectId.FromHash(_splitInfo.LastPart.Value.Span);
|
||||||
|
}
|
|
@ -3,22 +3,42 @@ using System.Threading;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public class CallContext()
|
public readonly struct CallContext(TimeSpan timeout, CancellationToken cancellationToken = default) : IEquatable<CallContext>
|
||||||
{
|
{
|
||||||
|
public CancellationToken CancellationToken { get; } = cancellationToken;
|
||||||
|
|
||||||
// internal Action<Exception>? PoolErrorHandler { get; set; }
|
public TimeSpan Timeout { get; } = timeout;
|
||||||
|
|
||||||
// public FrostFsOwner? OwnerId { get; set; }
|
internal readonly DateTime? GetDeadline()
|
||||||
|
{
|
||||||
|
return Timeout.Ticks > 0 ? DateTime.UtcNow.Add(Timeout) : null;
|
||||||
|
}
|
||||||
|
|
||||||
// public FrostFsVersion? Version { get; set; }
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not CallContext)
|
||||||
|
return false;
|
||||||
|
|
||||||
public CancellationToken CancellationToken { get; set; }
|
return Equals((CallContext)obj);
|
||||||
|
}
|
||||||
|
|
||||||
public TimeSpan Timeout { get; set; }
|
public bool Equals(CallContext other)
|
||||||
|
{
|
||||||
|
return Timeout == other.Timeout && CancellationToken.Equals(other.CancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
public DateTime? Deadline => Timeout.Ticks > 0 ? DateTime.UtcNow.Add(Timeout) : null;
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return CancellationToken.GetHashCode() ^ Timeout.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
// public Action<CallStatistics>? Callback { get; set; }
|
public static bool operator ==(CallContext left, CallContext right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
// public Collection<Interceptor> Interceptors { get; } = [];
|
public static bool operator !=(CallContext left, CallContext right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
using System.Security.Cryptography;
|
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public class Credentials(ECDsa key, FrostFsOwner ownerId)
|
|
||||||
{
|
|
||||||
public ECDsa Key { get; } = key;
|
|
||||||
|
|
||||||
public FrostFsOwner OwnerId { get; } = ownerId;
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public interface IContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// The method call can be extended with additional behavior like canceling by timeout or user's request,
|
|
||||||
/// callbacks, interceptors.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>Additional parameters for calling the method</value>
|
|
||||||
CallContext? Context { get; }
|
|
||||||
}
|
|
|
@ -8,5 +8,5 @@ public interface ISessionToken
|
||||||
/// member. The session has a limited validity period, and applies to a strictly defined set of operations.
|
/// member. The session has a limited validity period, and applies to a strictly defined set of operations.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Instance of the session obtained from the server</value>
|
/// <value>Instance of the session obtained from the server</value>
|
||||||
FrostFsSessionToken? SessionToken { get; set; }
|
FrostFsSessionToken? SessionToken { get; }
|
||||||
}
|
}
|
43
src/FrostFS.SDK.Client/Parameters/PrmApeChainAdd.cs
Normal file
43
src/FrostFS.SDK.Client/Parameters/PrmApeChainAdd.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
|
public readonly struct PrmApeChainAdd(FrostFsChainTarget target, FrostFsChain chain, string[]? xheaders = null) : System.IEquatable<PrmApeChainAdd>
|
||||||
|
{
|
||||||
|
public FrostFsChainTarget Target { get; } = target;
|
||||||
|
|
||||||
|
public FrostFsChain Chain { get; } = chain;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmApeChainAdd)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmApeChainAdd)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmApeChainAdd other)
|
||||||
|
{
|
||||||
|
return Target == other.Target
|
||||||
|
&& Chain == other.Chain
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Chain.GetHashCode() ^ Target.GetHashCode() ^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmApeChainAdd left, PrmApeChainAdd right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmApeChainAdd left, PrmApeChainAdd right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,40 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmApeChainList(FrostFsChainTarget target, CallContext? ctx = null) : PrmBase(ctx)
|
public readonly struct PrmApeChainList(FrostFsChainTarget target, string[]? xheaders = null) : System.IEquatable<PrmApeChainList>
|
||||||
{
|
{
|
||||||
public FrostFsChainTarget Target { get; } = target;
|
public FrostFsChainTarget Target { get; } = target;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmApeChainList)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmApeChainList)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Target.GetHashCode() ^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmApeChainList other)
|
||||||
|
{
|
||||||
|
return Target == other.Target
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmApeChainList left, PrmApeChainList right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmApeChainList left, PrmApeChainList right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,46 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmApeChainRemove(FrostFsChainTarget target, FrostFsChain chain, CallContext? ctx = null) : PrmBase(ctx)
|
public readonly struct PrmApeChainRemove(
|
||||||
|
FrostFsChainTarget target,
|
||||||
|
FrostFsChain chain,
|
||||||
|
string[]? xheaders = null) : System.IEquatable<PrmApeChainRemove>
|
||||||
{
|
{
|
||||||
public FrostFsChainTarget Target { get; } = target;
|
public FrostFsChainTarget Target { get; } = target;
|
||||||
|
|
||||||
public FrostFsChain Chain { get; } = chain;
|
public FrostFsChain Chain { get; } = chain;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmApeChainRemove)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmApeChainRemove)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmApeChainRemove other)
|
||||||
|
{
|
||||||
|
return Target == other.Target
|
||||||
|
&& Chain == other.Chain
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Chain.GetHashCode() ^ Target.GetHashCode() ^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmApeChainRemove left, PrmApeChainRemove right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmApeChainRemove left, PrmApeChainRemove right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public sealed class PrmApeChainAdd(FrostFsChainTarget target, FrostFsChain chain, CallContext? ctx = null) : PrmBase(ctx)
|
|
||||||
{
|
|
||||||
public FrostFsChainTarget Target { get; } = target;
|
|
||||||
|
|
||||||
public FrostFsChain Chain { get; } = chain;
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public sealed class PrmBalance(CallContext? ctx = null) : PrmBase(ctx)
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
using System.Collections.Specialized;
|
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public class PrmBase(CallContext? ctx, NameValueCollection? xheaders = null) : IContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// FrostFS request X-Headers
|
|
||||||
/// </summary>
|
|
||||||
public NameValueCollection XHeaders { get; } = xheaders ?? [];
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public CallContext Context { get; } = ctx ?? new CallContext();
|
|
||||||
}
|
|
|
@ -1,17 +1,61 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmContainerCreate(FrostFsContainerInfo container, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmContainerCreate(
|
||||||
|
FrostFsContainerInfo container,
|
||||||
|
PrmWait waitParams,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmContainerCreate>
|
||||||
{
|
{
|
||||||
public FrostFsContainerInfo Container { get; set; } = container;
|
public FrostFsContainerInfo Container { get; } = container;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Since the container becomes available with some delay, it needs to poll the container status
|
/// Since the container becomes available with some delay, it needs to poll the container status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Rules for polling the result</value>
|
/// <value>Rules for polling the result</value>
|
||||||
public PrmWait? WaitParams { get; set; }
|
public PrmWait WaitParams { get; } = waitParams;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Blank session token
|
/// Blank session token
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmContainerCreate)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmContainerCreate)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmContainerCreate other)
|
||||||
|
{
|
||||||
|
return Container == other.Container
|
||||||
|
&& WaitParams == other.WaitParams
|
||||||
|
&& SessionToken == other.SessionToken
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Container.GetHashCode()
|
||||||
|
^ WaitParams.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode())
|
||||||
|
^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmContainerCreate left, PrmContainerCreate right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmContainerCreate left, PrmContainerCreate right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,52 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmContainerDelete(FrostFsContainerId containerId, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmContainerDelete(
|
||||||
|
FrostFsContainerId containerId,
|
||||||
|
PrmWait waitParams,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmContainerDelete>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; set; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Since the container is removed with some delay, it needs to poll the container status
|
/// Since the container is removed with some delay, it needs to poll the container status
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Rules for polling the result</value>
|
/// <value>Rules for polling the result</value>
|
||||||
public PrmWait? WaitParams { get; set; }
|
public PrmWait WaitParams { get; } = waitParams;
|
||||||
|
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmContainerDelete)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmContainerDelete)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmContainerDelete other)
|
||||||
|
{
|
||||||
|
return ContainerId == other.ContainerId
|
||||||
|
&& WaitParams.Equals(other.WaitParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode() ^ WaitParams.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmContainerDelete left, PrmContainerDelete right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmContainerDelete left, PrmContainerDelete right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,40 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmContainerGet(FrostFsContainerId container, CallContext? ctx = null) : PrmBase(ctx)
|
public readonly struct PrmContainerGet(FrostFsContainerId container, string[]? xheaders = null) : System.IEquatable<PrmContainerGet>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId Container { get; set; } = container;
|
public FrostFsContainerId Container { get; } = container;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmContainerGet)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmContainerGet)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmContainerGet other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Container.GetHashCode()
|
||||||
|
^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmContainerGet left, PrmContainerGet right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmContainerGet left, PrmContainerGet right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,39 @@
|
||||||
namespace FrostFS.SDK.Client;
|
using System;
|
||||||
|
|
||||||
public sealed class PrmContainerGetAll(CallContext? ctx = null) : PrmBase(ctx)
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
|
public readonly struct PrmContainerGetAll(string[]? xheaders = null) : IEquatable<PrmContainerGetAll>
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmContainerGetAll)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmContainerGetAll)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmContainerGetAll other)
|
||||||
|
{
|
||||||
|
return XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmContainerGetAll left, PrmContainerGetAll right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmContainerGetAll left, PrmContainerGetAll right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public sealed class PrmNetmapSnapshot(CallContext? ctx = null) : PrmBase(ctx)
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public sealed class PrmNetworkSettings(CallContext? ctx = null) : PrmBase(ctx)
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
namespace FrostFS.SDK.Client;
|
|
||||||
|
|
||||||
public sealed class PrmNodeInfo(CallContext? ctx = null) : PrmBase(ctx)
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,11 +1,51 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmObjectDelete(FrostFsContainerId containerId, FrostFsObjectId objectId, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmObjectDelete(
|
||||||
|
FrostFsContainerId containerId,
|
||||||
|
FrostFsObjectId objectId,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectDelete>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; set; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
public FrostFsObjectId ObjectId { get; set; } = objectId;
|
public FrostFsObjectId ObjectId { get; } = objectId;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectDelete)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectDelete)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectDelete other)
|
||||||
|
{
|
||||||
|
return ContainerId == other.ContainerId
|
||||||
|
&& ObjectId == other.ObjectId
|
||||||
|
&& SessionToken == other.SessionToken
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode() ^ ObjectId.GetHashCode() ^ (SessionToken != null ? SessionToken.GetHashCode() : 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectDelete left, PrmObjectDelete right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectDelete left, PrmObjectDelete right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,52 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmObjectGet(FrostFsContainerId containerId, FrostFsObjectId objectId, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmObjectGet(
|
||||||
|
FrostFsContainerId containerId,
|
||||||
|
FrostFsObjectId objectId,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectGet>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; set; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
public FrostFsObjectId ObjectId { get; set; } = objectId;
|
public FrostFsObjectId ObjectId { get; } = objectId;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectGet)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectGet)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode()
|
||||||
|
^ ObjectId.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectGet other)
|
||||||
|
{
|
||||||
|
return ContainerId == other.ContainerId
|
||||||
|
&& ObjectId == other.ObjectId
|
||||||
|
&& SessionToken == other.SessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectGet left, PrmObjectGet right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectGet left, PrmObjectGet right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,56 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmObjectHeadGet(FrostFsContainerId containerId, FrostFsObjectId objectId, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmObjectHeadGet(
|
||||||
|
FrostFsContainerId containerId,
|
||||||
|
FrostFsObjectId objectId,
|
||||||
|
bool raw = false,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null)
|
||||||
|
: ISessionToken, System.IEquatable<PrmObjectHeadGet>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; set; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
public FrostFsObjectId ObjectId { get; set; } = objectId;
|
public FrostFsObjectId ObjectId { get; } = objectId;
|
||||||
|
|
||||||
|
public bool Raw { get; } = raw;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectHeadGet)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectHeadGet)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectHeadGet other)
|
||||||
|
{
|
||||||
|
return ContainerId == other.ContainerId
|
||||||
|
&& ObjectId == other.ObjectId
|
||||||
|
&& SessionToken == other.SessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode()
|
||||||
|
^ ObjectId.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectHeadGet left, PrmObjectHeadGet right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectHeadGet left, PrmObjectHeadGet right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,23 +2,70 @@
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmObjectPatch(FrostFsAddress address, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmObjectPatch(
|
||||||
|
FrostFsAddress address,
|
||||||
|
FrostFsRange range,
|
||||||
|
Stream? payload,
|
||||||
|
int maxChunkLength,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
bool replaceAttributes = false,
|
||||||
|
FrostFsAttributePair[]? newAttributes = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectPatch>
|
||||||
{
|
{
|
||||||
public FrostFsAddress Address { get; } = address;
|
public FrostFsAddress Address { get; } = address;
|
||||||
|
|
||||||
public FrostFsRange Range { get; set; }
|
public FrostFsRange Range { get; } = range;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A stream with source data
|
/// A stream with source data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Stream? Payload { get; set; }
|
public Stream? Payload { get; } = payload;
|
||||||
|
|
||||||
public FrostFsAttributePair[]? NewAttributes { get; set; }
|
public FrostFsAttributePair[]? NewAttributes { get; } = newAttributes;
|
||||||
|
|
||||||
public bool ReplaceAttributes { get; set; }
|
public bool ReplaceAttributes { get; } = replaceAttributes;
|
||||||
|
|
||||||
public int MaxPayloadPatchChunkLength { get; set; }
|
public int MaxChunkLength { get; } = maxChunkLength;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectPatch)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectPatch)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectPatch other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Address.GetHashCode()
|
||||||
|
^ Range.GetHashCode()
|
||||||
|
^ (Payload == null ? 0 : Payload.GetHashCode())
|
||||||
|
^ (NewAttributes == null ? 0 : NewAttributes.GetHashCode())
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode())
|
||||||
|
^ (ReplaceAttributes ? 1 : 0)
|
||||||
|
^ MaxChunkLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectPatch left, PrmObjectPatch right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectPatch left, PrmObjectPatch right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,19 +2,26 @@ using System.IO;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmObjectPut(CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public readonly struct PrmObjectPut(
|
||||||
|
FrostFsObjectHeader? header,
|
||||||
|
Stream? payload,
|
||||||
|
bool clientCut,
|
||||||
|
int bufferMaxSize = 0,
|
||||||
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
byte[]? customBuffer = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmObjectPut>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Need to provide values like <c>ContainerId</c> and <c>ObjectType</c> to create and object.
|
/// Need to provide values like <c>ContainerId</c> and <c>ObjectType</c> to create and object.
|
||||||
/// Optional parameters ike <c>Attributes</c> can be provided as well.
|
/// Optional parameters ike <c>Attributes</c> can be provided as well.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Header with required parameters to create an object</value>
|
/// <value>Header with required parameters to create an object</value>
|
||||||
public FrostFsObjectHeader? Header { get; set; }
|
public FrostFsObjectHeader? Header { get; } = header;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A stream with source data
|
/// A stream with source data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Stream? Payload { get; set; }
|
public Stream? Payload { get; } = payload;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Object size is limited. In the data exceeds the limit, the object will be splitted.
|
/// Object size is limited. In the data exceeds the limit, the object will be splitted.
|
||||||
|
@ -22,25 +29,60 @@ public sealed class PrmObjectPut(CallContext? ctx = null) : PrmBase(ctx), ISessi
|
||||||
/// as a stream and will be cut on server side.
|
/// as a stream and will be cut on server side.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Is client cut is applied</value>
|
/// <value>Is client cut is applied</value>
|
||||||
public bool ClientCut { get; set; }
|
public bool ClientCut { get; } = clientCut;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Overrides default size of the buffer for stream transferring.
|
/// Overrides default size of the buffer for stream transferring.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Size of the buffer</value>
|
/// <value>Size of the buffer</value>
|
||||||
public int BufferMaxSize { get; set; }
|
public int BufferMaxSize { get; } = bufferMaxSize;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allows to define a buffer for chunks to manage by the memory allocation and releasing.
|
/// Allows to define a buffer for chunks to manage by the memory allocation and releasing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[]? CustomBuffer { get; set; }
|
public byte[]? CustomBuffer { get; } = customBuffer;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
internal int MaxObjectSizeCache { get; set; }
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
internal ulong CurrentStreamPosition { get; set; }
|
internal PutObjectContext PutObjectContext { get; } = new();
|
||||||
|
|
||||||
internal ulong FullLength { get; set; }
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectPut)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectPut)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectPut other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return BufferMaxSize
|
||||||
|
^ (Header == null ? 0 : Header.GetHashCode())
|
||||||
|
^ (Payload == null ? 0 : Payload.GetHashCode())
|
||||||
|
^ (ClientCut ? 1 : 0)
|
||||||
|
^ (CustomBuffer == null ? 0 : CustomBuffer.GetHashCode())
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode())
|
||||||
|
^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectPut left, PrmObjectPut right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectPut left, PrmObjectPut right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,59 @@
|
||||||
using System.Collections.Generic;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
public readonly struct PrmObjectSearch(
|
||||||
|
FrostFsContainerId containerId,
|
||||||
public sealed class PrmObjectSearch(FrostFsContainerId containerId, CallContext? ctx = null, params IObjectFilter[] filters) : PrmBase(ctx), ISessionToken
|
FrostFsSessionToken? token,
|
||||||
|
string[]? xheaders = null,
|
||||||
|
params IObjectFilter[] filters) : ISessionToken, System.IEquatable<PrmObjectSearch>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines container for the search
|
/// Defines container for the search
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value></value>
|
/// <value></value>
|
||||||
public FrostFsContainerId ContainerId { get; set; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Defines the search criteria
|
/// Defines the search criteria
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>Collection of filters</value>
|
/// <value>Collection of filters</value>
|
||||||
public IEnumerable<IObjectFilter> Filters { get; set; } = filters;
|
public IObjectFilter[] Filters { get; } = filters;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = token;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmObjectSearch)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmObjectSearch)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmObjectSearch other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode()
|
||||||
|
^ Filters.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode())
|
||||||
|
^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmObjectSearch left, PrmObjectSearch right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmObjectSearch left, PrmObjectSearch right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmRangeGet(
|
public readonly struct PrmRangeGet(
|
||||||
FrostFsContainerId containerId,
|
FrostFsContainerId containerId,
|
||||||
FrostFsObjectId objectId,
|
FrostFsObjectId objectId,
|
||||||
FrostFsRange range,
|
FrostFsRange range,
|
||||||
bool raw = false,
|
bool raw = false,
|
||||||
CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmRangeGet>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
|
@ -16,5 +17,41 @@ public sealed class PrmRangeGet(
|
||||||
public bool Raw { get; } = raw;
|
public bool Raw { get; } = raw;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmRangeGet)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmRangeGet)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmRangeGet other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode()
|
||||||
|
^ ObjectId.GetHashCode()
|
||||||
|
^ Range.GetHashCode()
|
||||||
|
^ Raw.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmRangeGet left, PrmRangeGet right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmRangeGet left, PrmRangeGet right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmRangeHashGet(
|
public readonly struct PrmRangeHashGet(
|
||||||
FrostFsContainerId containerId,
|
FrostFsContainerId containerId,
|
||||||
FrostFsObjectId objectId,
|
FrostFsObjectId objectId,
|
||||||
FrostFsRange[] ranges,
|
FrostFsRange[] ranges,
|
||||||
byte[] salt,
|
byte[] salt,
|
||||||
CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
FrostFsSessionToken? sessionToken = null,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmRangeHashGet>
|
||||||
{
|
{
|
||||||
public FrostFsContainerId ContainerId { get; } = containerId;
|
public FrostFsContainerId ContainerId { get; } = containerId;
|
||||||
|
|
||||||
|
@ -16,5 +17,42 @@ public sealed class PrmRangeHashGet(
|
||||||
public byte[] Salt { get; } = salt;
|
public byte[] Salt { get; } = salt;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; } = sessionToken;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmRangeHashGet)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmRangeHashGet)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmRangeHashGet other)
|
||||||
|
{
|
||||||
|
return GetHashCode() == other.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return ContainerId.GetHashCode()
|
||||||
|
^ ObjectId.GetHashCode()
|
||||||
|
^ Ranges.GetHashCode()
|
||||||
|
^ Salt.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmRangeHashGet left, PrmRangeHashGet right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmRangeHashGet left, PrmRangeHashGet right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,40 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmSessionCreate(ulong expiration, CallContext? ctx = null) : PrmBase(ctx)
|
public readonly struct PrmSessionCreate(ulong expiration, string[]? xheaders = null) : System.IEquatable<PrmSessionCreate>
|
||||||
{
|
{
|
||||||
public ulong Expiration { get; set; } = expiration;
|
public ulong Expiration { get; } = expiration;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmSessionCreate)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmSessionCreate)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return Expiration.GetHashCode() ^ XHeaders.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmSessionCreate other)
|
||||||
|
{
|
||||||
|
return Expiration == other.Expiration
|
||||||
|
&& XHeaders == other.XHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmSessionCreate left, PrmSessionCreate right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmSessionCreate left, PrmSessionCreate right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,46 @@
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public sealed class PrmSingleObjectPut(FrostFsObject frostFsObject, CallContext? ctx = null) : PrmBase(ctx), ISessionToken
|
public struct PrmSingleObjectPut(
|
||||||
|
FrostFsObject frostFsObject,
|
||||||
|
string[]? xheaders = null) : ISessionToken, System.IEquatable<PrmSingleObjectPut>
|
||||||
{
|
{
|
||||||
public FrostFsObject FrostFsObject { get; set; } = frostFsObject;
|
public FrostFsObject FrostFsObject { get; set; } = frostFsObject;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public FrostFsSessionToken? SessionToken { get; set; }
|
public FrostFsSessionToken? SessionToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FrostFS request X-Headers
|
||||||
|
/// </summary>
|
||||||
|
public string[] XHeaders { get; } = xheaders ?? [];
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmSingleObjectPut)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmSingleObjectPut)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return FrostFsObject.GetHashCode()
|
||||||
|
^ (SessionToken == null ? 0 : SessionToken.GetHashCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmSingleObjectPut other)
|
||||||
|
{
|
||||||
|
return FrostFsObject == other.FrostFsObject
|
||||||
|
&& SessionToken == other.SessionToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmSingleObjectPut left, PrmSingleObjectPut right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmSingleObjectPut left, PrmSingleObjectPut right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace FrostFS.SDK.Client;
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
public class PrmWait(TimeSpan timeout, TimeSpan pollInterval)
|
public readonly struct PrmWait(TimeSpan timeout, TimeSpan pollInterval) : IEquatable<PrmWait>
|
||||||
{
|
{
|
||||||
private static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(120);
|
private static TimeSpan DefaultTimeout = TimeSpan.FromSeconds(120);
|
||||||
private static TimeSpan DefaultPollInterval = TimeSpan.FromSeconds(5);
|
private static TimeSpan DefaultPollInterval = TimeSpan.FromSeconds(5);
|
||||||
|
@ -13,12 +13,40 @@ public class PrmWait(TimeSpan timeout, TimeSpan pollInterval)
|
||||||
|
|
||||||
public static PrmWait DefaultParams { get; } = new PrmWait(DefaultTimeout, DefaultPollInterval);
|
public static PrmWait DefaultParams { get; } = new PrmWait(DefaultTimeout, DefaultPollInterval);
|
||||||
|
|
||||||
public TimeSpan Timeout { get; set; } = timeout.Ticks == 0 ? DefaultTimeout : timeout;
|
public TimeSpan Timeout { get; } = timeout.Ticks == 0 ? DefaultTimeout : timeout;
|
||||||
|
|
||||||
public TimeSpan PollInterval { get; set; } = pollInterval.Ticks == 0 ? DefaultPollInterval : pollInterval;
|
public TimeSpan PollInterval { get; } = pollInterval.Ticks == 0 ? DefaultPollInterval : pollInterval;
|
||||||
|
|
||||||
public DateTime GetDeadline()
|
public readonly DateTime GetDeadline()
|
||||||
{
|
{
|
||||||
return DateTime.UtcNow.AddTicks(Timeout.Ticks);
|
return DateTime.UtcNow.AddTicks(Timeout.Ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override readonly bool Equals(object obj)
|
||||||
|
{
|
||||||
|
if (obj == null || obj is not PrmWait)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return Equals((PrmWait)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override readonly int GetHashCode()
|
||||||
|
{
|
||||||
|
return DefaultTimeout.GetHashCode() ^ DefaultPollInterval.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public readonly bool Equals(PrmWait other)
|
||||||
|
{
|
||||||
|
return Timeout == other.Timeout && PollInterval == other.PollInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(PrmWait left, PrmWait right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(PrmWait left, PrmWait right)
|
||||||
|
{
|
||||||
|
return !(left == right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
10
src/FrostFS.SDK.Client/Parameters/PutObjectContext.cs
Normal file
10
src/FrostFS.SDK.Client/Parameters/PutObjectContext.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
|
internal sealed class PutObjectContext
|
||||||
|
{
|
||||||
|
internal int MaxObjectSizeCache { get; set; }
|
||||||
|
|
||||||
|
internal ulong CurrentStreamPosition { get; set; }
|
||||||
|
|
||||||
|
internal ulong FullLength { get; set; }
|
||||||
|
}
|
|
@ -83,8 +83,7 @@ public class ClientWrapper : ClientStatusMonitor
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var prmNodeInfo = new PrmNodeInfo(ctx);
|
var response = await Client!.GetNodeInfoAsync(ctx).ConfigureAwait(false);
|
||||||
var response = await Client!.GetNodeInfoAsync(prmNodeInfo).ConfigureAwait(false);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (RpcException)
|
catch (RpcException)
|
||||||
|
@ -105,11 +104,7 @@ public class ClientWrapper : ClientStatusMonitor
|
||||||
{
|
{
|
||||||
client = new(WrapperPrm, sessionCache);
|
client = new(WrapperPrm, sessionCache);
|
||||||
|
|
||||||
var dialCtx = new CallContext
|
var dialCtx = new CallContext(TimeSpan.FromTicks((long)WrapperPrm.DialTimeout), ctx.CancellationToken);
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromTicks((long)WrapperPrm.DialTimeout),
|
|
||||||
CancellationToken = ctx.CancellationToken
|
|
||||||
};
|
|
||||||
|
|
||||||
var error = await client.Dial(ctx).ConfigureAwait(false);
|
var error = await client.Dial(ctx).ConfigureAwait(false);
|
||||||
if (!string.IsNullOrEmpty(error))
|
if (!string.IsNullOrEmpty(error))
|
||||||
|
@ -132,8 +127,7 @@ public class ClientWrapper : ClientStatusMonitor
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var prmNodeInfo = new PrmNodeInfo(ctx);
|
var res = await Client.GetNodeInfoAsync(ctx).ConfigureAwait(false);
|
||||||
var res = await Client.GetNodeInfoAsync(prmNodeInfo).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
catch (FrostFsException)
|
catch (FrostFsException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -185,7 +185,7 @@ public partial class Pool : IFrostFSClient
|
||||||
|
|
||||||
InnerPools = inner;
|
InnerPools = inner;
|
||||||
|
|
||||||
var res = await GetNetworkSettingsAsync(new PrmNetworkSettings(ctx)).ConfigureAwait(false);
|
var res = await GetNetworkSettingsAsync(default).ConfigureAwait(false);
|
||||||
|
|
||||||
MaxObjectSize = res.MaxObjectSize;
|
MaxObjectSize = res.MaxObjectSize;
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ public partial class Pool : IFrostFSClient
|
||||||
private static async Task<FrostFsSessionToken> InitSessionForDuration(CallContext ctx, ClientWrapper cw, ulong duration, ECDsa key, bool clientCut)
|
private static async Task<FrostFsSessionToken> InitSessionForDuration(CallContext ctx, ClientWrapper cw, ulong duration, ECDsa key, bool clientCut)
|
||||||
{
|
{
|
||||||
var client = cw.Client;
|
var client = cw.Client;
|
||||||
var networkInfo = await client!.GetNetworkSettingsAsync(new PrmNetworkSettings(ctx)).ConfigureAwait(false);
|
var networkInfo = await client!.GetNetworkSettingsAsync(ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
var epoch = networkInfo.Epoch;
|
var epoch = networkInfo.Epoch;
|
||||||
|
|
||||||
|
@ -320,9 +320,9 @@ public partial class Pool : IFrostFSClient
|
||||||
? ulong.MaxValue
|
? ulong.MaxValue
|
||||||
: epoch + duration;
|
: epoch + duration;
|
||||||
|
|
||||||
var prmSessionCreate = new PrmSessionCreate(exp, ctx);
|
var prmSessionCreate = new PrmSessionCreate(exp);
|
||||||
|
|
||||||
return await client.CreateSessionAsync(prmSessionCreate).ConfigureAwait(false);
|
return await client.CreateSessionAsync(prmSessionCreate, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static string FormCacheKey(string address, string key)
|
internal static string FormCacheKey(string address, string key)
|
||||||
|
@ -507,139 +507,137 @@ public partial class Pool : IFrostFSClient
|
||||||
return statistics;
|
return statistics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(PrmNetmapSnapshot? args = null)
|
public async Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
|
|
||||||
args ??= new();
|
return await client.Client!.GetNetmapSnapshotAsync(ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
return await client.Client!.GetNetmapSnapshotAsync(args).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsNodeInfo> GetNodeInfoAsync(PrmNodeInfo? args = null)
|
public async Task<FrostFsNodeInfo> GetNodeInfoAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetNodeInfoAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetNodeInfoAsync(ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<NetworkSettings> GetNetworkSettingsAsync(PrmNetworkSettings? args = null)
|
public async Task<NetworkSettings> GetNetworkSettingsAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetNetworkSettingsAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetNetworkSettingsAsync(ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args)
|
public async Task<FrostFsSessionToken> CreateSessionAsync(PrmSessionCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.CreateSessionAsync(args).ConfigureAwait(false);
|
return await client.Client!.CreateSessionAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args)
|
public async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.AddChainAsync(args).ConfigureAwait(false);
|
return await client.Client!.AddChainAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveChainAsync(PrmApeChainRemove args)
|
public async Task RemoveChainAsync(PrmApeChainRemove args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
await client.Client!.RemoveChainAsync(args).ConfigureAwait(false);
|
await client.Client!.RemoveChainAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Chain[]> ListChainAsync(PrmApeChainList args)
|
public async Task<Chain[]> ListChainAsync(PrmApeChainList args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.ListChainAsync(args).ConfigureAwait(false);
|
return await client.Client!.ListChainAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args)
|
public async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetContainerAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetContainerAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll? args = null)
|
public IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return client.Client!.ListContainersAsync(args);
|
return client.Client!.ListContainersAsync(args, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args)
|
public async Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.CreateContainerAsync(args).ConfigureAwait(false);
|
return await client.Client!.CreateContainerAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteContainerAsync(PrmContainerDelete args)
|
public async Task DeleteContainerAsync(PrmContainerDelete args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
await client.Client!.DeleteContainerAsync(args).ConfigureAwait(false);
|
await client.Client!.DeleteContainerAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args)
|
public async Task<FrostFsHeaderResult> GetObjectHeadAsync(PrmObjectHeadGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetObjectHeadAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetObjectHeadAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObject> GetObjectAsync(PrmObjectGet args)
|
public async Task<FrostFsObject> GetObjectAsync(PrmObjectGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetObjectAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args)
|
public async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.PutObjectAsync(args).ConfigureAwait(false);
|
return await client.Client!.PutObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args)
|
public async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.PutSingleObjectAsync(args).ConfigureAwait(false);
|
return await client.Client!.PutSingleObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
|
public async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.PatchObjectAsync(args).ConfigureAwait(false);
|
return await client.Client!.PatchObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<RangeReader> GetRangeAsync(PrmRangeGet args)
|
public async Task<RangeReader> GetRangeAsync(PrmRangeGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetRangeAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetRangeAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args)
|
public async Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetRangeHashAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetRangeHashAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<FrostFsObjectId> PatchAsync(PrmObjectPatch args)
|
public async Task<FrostFsObjectId> PatchAsync(PrmObjectPatch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.PatchObjectAsync(args).ConfigureAwait(false);
|
return await client.Client!.PatchObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteObjectAsync(PrmObjectDelete args)
|
public async Task DeleteObjectAsync(PrmObjectDelete args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
await client.Client!.DeleteObjectAsync(args).ConfigureAwait(false);
|
await client.Client!.DeleteObjectAsync(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args)
|
public IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return client.Client!.SearchObjectsAsync(args);
|
return client.Client!.SearchObjectsAsync(args, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Accounting.Decimal> GetBalanceAsync(PrmBalance? args)
|
public async Task<Accounting.Decimal> GetBalanceAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var client = Connection();
|
var client = Connection();
|
||||||
return await client.Client!.GetBalanceAsync(args).ConfigureAwait(false);
|
return await client.Client!.GetBalanceAsync(ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
protected virtual void Dispose(bool disposing)
|
||||||
|
@ -661,9 +659,4 @@ public partial class Pool : IFrostFSClient
|
||||||
Dispose(disposing: true);
|
Dispose(disposing: true);
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@ internal sealed class AccountingServiceProvider : ContextAccessor
|
||||||
_accountingServiceClient = accountingServiceClient;
|
_accountingServiceClient = accountingServiceClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<Decimal> GetBallance(PrmBalance args)
|
internal async Task<Decimal> GetBallance(CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
BalanceRequest request = new()
|
BalanceRequest request = new()
|
||||||
{
|
{
|
||||||
Body = new()
|
Body = new()
|
||||||
|
@ -28,10 +26,10 @@ internal sealed class AccountingServiceProvider : ContextAccessor
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader([]);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await _accountingServiceClient!.BalanceAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await _accountingServiceClient!.BalanceAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,8 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
|
||||||
_apeManagerServiceClient = apeManagerServiceClient;
|
_apeManagerServiceClient = apeManagerServiceClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args)
|
internal async Task<ReadOnlyMemory<byte>> AddChainAsync(PrmApeChainAdd args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
AddChainRequest request = new()
|
AddChainRequest request = new()
|
||||||
{
|
{
|
||||||
Body = new()
|
Body = new()
|
||||||
|
@ -32,17 +30,15 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader(args.XHeaders);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await _apeManagerServiceClient!.AddChainAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await _apeManagerServiceClient!.AddChainAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
return response.Body.ChainId.Memory;
|
return response.Body.ChainId.Memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task RemoveChainAsync(PrmApeChainRemove args)
|
internal async Task RemoveChainAsync(PrmApeChainRemove args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
RemoveChainRequest request = new()
|
RemoveChainRequest request = new()
|
||||||
{
|
{
|
||||||
Body = new()
|
Body = new()
|
||||||
|
@ -55,15 +51,13 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader(args.XHeaders);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await _apeManagerServiceClient!.RemoveChainAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await _apeManagerServiceClient!.RemoveChainAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<Chain[]> ListChainAsync(PrmApeChainList args)
|
internal async Task<Chain[]> ListChainAsync(PrmApeChainList args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
ListChainsRequest request = new()
|
ListChainsRequest request = new()
|
||||||
{
|
{
|
||||||
Body = new()
|
Body = new()
|
||||||
|
@ -75,7 +69,7 @@ internal sealed class ApeManagerServiceProvider : ContextAccessor
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader(args.XHeaders);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await _apeManagerServiceClient!.ListChainsAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await _apeManagerServiceClient!.ListChainsAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
@ -38,21 +37,19 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args)
|
internal async Task<FrostFsContainerInfo> GetContainerAsync(PrmContainerGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
GetRequest request = GetContainerRequest(args.Container.ContainerID, args.XHeaders, ClientContext.Key.ECDsaKey);
|
GetRequest request = GetContainerRequest(args.Container.ContainerID, args.XHeaders, ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await service.GetAsync(request, null, args.Context.Deadline, args.Context.CancellationToken);
|
var response = await service.GetAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
return response.Body.Container.ToModel();
|
return response.Body.Container.ToModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args)
|
internal async IAsyncEnumerable<FrostFsContainerId> ListContainersAsync(PrmContainerGetAll args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new ListRequest
|
var request = new ListRequest
|
||||||
{
|
{
|
||||||
Body = new()
|
Body = new()
|
||||||
|
@ -64,7 +61,7 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader(args.XHeaders);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await service.ListAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await service.ListAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
@ -74,10 +71,8 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args)
|
internal async Task<FrostFsContainerId> CreateContainerAsync(PrmContainerCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var grpcContainer = args.Container.GetContainer();
|
var grpcContainer = args.Container.GetContainer();
|
||||||
|
|
||||||
grpcContainer.OwnerId ??= ClientContext.Owner.OwnerID;
|
grpcContainer.OwnerId ??= ClientContext.Owner.OwnerID;
|
||||||
|
@ -103,7 +98,7 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await service.PutAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await service.PutAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
@ -112,10 +107,8 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
return new FrostFsContainerId(response.Body.ContainerId);
|
return new FrostFsContainerId(response.Body.ContainerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task DeleteContainerAsync(PrmContainerDelete args)
|
internal async Task DeleteContainerAsync(PrmContainerDelete args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new DeleteRequest
|
var request = new DeleteRequest
|
||||||
{
|
{
|
||||||
Body = new DeleteRequest.Types.Body
|
Body = new DeleteRequest.Types.Body
|
||||||
|
@ -136,7 +129,7 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await service.DeleteAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await service.DeleteAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
@ -146,7 +139,7 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GetRequest GetContainerRequest(ContainerID id, NameValueCollection? xHeaders, ECDsa key)
|
private static GetRequest GetContainerRequest(ContainerID id, string[] xHeaders, ECDsa key)
|
||||||
{
|
{
|
||||||
var request = new GetRequest
|
var request = new GetRequest
|
||||||
{
|
{
|
||||||
|
@ -168,13 +161,13 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
Removed
|
Removed
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task WaitForContainer(WaitExpects expect, ContainerID id, PrmWait? waitParams, CallContext ctx)
|
private async Task WaitForContainer(WaitExpects expect, ContainerID id, PrmWait waitParams, CallContext ctx)
|
||||||
{
|
{
|
||||||
var request = GetContainerRequest(id, null, ClientContext.Key.ECDsaKey);
|
var request = GetContainerRequest(id, [], ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
async Task action()
|
async Task action()
|
||||||
{
|
{
|
||||||
var response = await service.GetAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await service.GetAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,9 +177,8 @@ internal sealed class ContainerServiceProvider(ContainerService.ContainerService
|
||||||
private static async Task WaitFor(
|
private static async Task WaitFor(
|
||||||
Func<Task> action,
|
Func<Task> action,
|
||||||
WaitExpects expect,
|
WaitExpects expect,
|
||||||
PrmWait? waitParams)
|
PrmWait waitParams)
|
||||||
{
|
{
|
||||||
waitParams ??= PrmWait.DefaultParams;
|
|
||||||
var deadLine = waitParams.GetDeadline();
|
var deadLine = waitParams.GetDeadline();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
|
|
|
@ -42,19 +42,17 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsNodeInfo> GetLocalNodeInfoAsync(PrmNodeInfo args)
|
internal async Task<FrostFsNodeInfo> GetLocalNodeInfoAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new LocalNodeInfoRequest
|
var request = new LocalNodeInfoRequest
|
||||||
{
|
{
|
||||||
Body = new LocalNodeInfoRequest.Types.Body { }
|
Body = new LocalNodeInfoRequest.Types.Body { }
|
||||||
};
|
};
|
||||||
|
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader([]);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await netmapServiceClient.LocalNodeInfoAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await netmapServiceClient.LocalNodeInfoAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
@ -65,10 +63,10 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
||||||
{
|
{
|
||||||
var request = new NetworkInfoRequest();
|
var request = new NetworkInfoRequest();
|
||||||
|
|
||||||
request.AddMetaHeader(null);
|
request.AddMetaHeader([]);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await netmapServiceClient.NetworkInfoAsync(request, null, ctx.Deadline, ctx.CancellationToken)
|
var response = await netmapServiceClient.NetworkInfoAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
@ -76,16 +74,14 @@ internal sealed class NetmapServiceProvider : ContextAccessor
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(PrmNetmapSnapshot args)
|
internal async Task<FrostFsNetmapSnapshot> GetNetmapSnapshotAsync(CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new NetmapSnapshotRequest();
|
var request = new NetmapSnapshotRequest();
|
||||||
|
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader([]);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await netmapServiceClient.NetmapSnapshotAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await netmapServiceClient.NetmapSnapshotAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -43,10 +43,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsObjectHeader> GetObjectHeadAsync(PrmObjectHeadGet args)
|
internal async Task<FrostFsHeaderResult> GetObjectHeadAsync(PrmObjectHeadGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new HeadRequest
|
var request = new HeadRequest
|
||||||
{
|
{
|
||||||
Body = new HeadRequest.Types.Body
|
Body = new HeadRequest.Types.Body
|
||||||
|
@ -55,7 +53,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
{
|
{
|
||||||
ContainerId = args.ContainerId.ContainerID,
|
ContainerId = args.ContainerId.ContainerID,
|
||||||
ObjectId = args.ObjectId.ToMessage()
|
ObjectId = args.ObjectId.ToMessage()
|
||||||
}
|
},
|
||||||
|
Raw = args.Raw
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,17 +69,27 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await client!.HeadAsync(request, null, ctx.Deadline, ctx.CancellationToken).ConfigureAwait(false);
|
var response = await client!.HeadAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
return response.Body.Header.Header.ToModel();
|
var result = new FrostFsHeaderResult();
|
||||||
|
|
||||||
|
if (response.Body.Header != null)
|
||||||
|
{
|
||||||
|
result.HeaderInfo = response.Body.Header?.Header.ToModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsObject> GetObjectAsync(PrmObjectGet args)
|
if (response.Body.SplitInfo != null)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
result.SplitInfo = new FrostFsSplitInfo(response.Body.SplitInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async Task<FrostFsObject> GetObjectAsync(PrmObjectGet args, CallContext ctx)
|
||||||
|
{
|
||||||
var request = new GetRequest
|
var request = new GetRequest
|
||||||
{
|
{
|
||||||
Body = new GetRequest.Types.Body
|
Body = new GetRequest.Types.Body
|
||||||
|
@ -107,10 +116,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
return await GetObject(request, ctx).ConfigureAwait(false);
|
return await GetObject(request, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<RangeReader> GetRangeAsync(PrmRangeGet args)
|
internal async Task<RangeReader> GetRangeAsync(PrmRangeGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new GetRangeRequest
|
var request = new GetRangeRequest
|
||||||
{
|
{
|
||||||
Body = new GetRangeRequest.Types.Body
|
Body = new GetRangeRequest.Types.Body
|
||||||
|
@ -140,14 +147,12 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var call = client.GetRange(request, null, ctx.Deadline, ctx.CancellationToken);
|
var call = client.GetRange(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
return new RangeReader(call);
|
return new RangeReader(call);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args)
|
internal async Task<ReadOnlyMemory<byte>[]> GetRangeHashAsync(PrmRangeHashGet args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new GetRangeHashRequest
|
var request = new GetRangeHashRequest
|
||||||
{
|
{
|
||||||
Body = new GetRangeHashRequest.Types.Body
|
Body = new GetRangeHashRequest.Types.Body
|
||||||
|
@ -182,7 +187,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await client.GetRangeHashAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await client.GetRangeHashAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
@ -191,11 +196,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
return hashCollection;
|
return hashCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal async Task DeleteObjectAsync(PrmObjectDelete args, CallContext ctx)
|
||||||
internal async Task DeleteObjectAsync(PrmObjectDelete args)
|
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new DeleteRequest
|
var request = new DeleteRequest
|
||||||
{
|
{
|
||||||
Body = new DeleteRequest.Types.Body
|
Body = new DeleteRequest.Types.Body
|
||||||
|
@ -218,15 +220,13 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
request.AddMetaHeader(args.XHeaders, protoToken);
|
request.AddMetaHeader(args.XHeaders, protoToken);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await client.DeleteAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await client.DeleteAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args)
|
internal async IAsyncEnumerable<FrostFsObjectId> SearchObjectsAsync(PrmObjectSearch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new SearchRequest
|
var request = new SearchRequest
|
||||||
{
|
{
|
||||||
Body = new SearchRequest.Types.Body
|
Body = new SearchRequest.Types.Body
|
||||||
|
@ -265,11 +265,8 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args)
|
internal async Task<FrostFsObjectId> PutObjectAsync(PrmObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
if (args is null)
|
|
||||||
throw new ArgumentNullException(nameof(args));
|
|
||||||
|
|
||||||
if (args.Header == null)
|
if (args.Header == null)
|
||||||
throw new ArgumentNullException(nameof(args), "Header is null");
|
throw new ArgumentNullException(nameof(args), "Header is null");
|
||||||
|
|
||||||
|
@ -278,27 +275,25 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
|
|
||||||
if (args.ClientCut)
|
if (args.ClientCut)
|
||||||
{
|
{
|
||||||
return await PutClientCutObject(args).ConfigureAwait(false);
|
return await PutClientCutObject(args, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (args.Header.PayloadLength > 0)
|
if (args.Header.PayloadLength > 0)
|
||||||
args.FullLength = args.Header.PayloadLength;
|
args.PutObjectContext.FullLength = args.Header.PayloadLength;
|
||||||
else if (args.Payload.CanSeek)
|
else if (args.Payload.CanSeek)
|
||||||
args.FullLength = (ulong)args.Payload.Length;
|
args.PutObjectContext.FullLength = (ulong)args.Payload.Length;
|
||||||
else
|
else
|
||||||
throw new ArgumentException("The stream does not have a length and payload length is not defined");
|
throw new ArgumentException("The stream does not have a length and payload length is not defined");
|
||||||
|
|
||||||
var response = await PutStreamObject(args).ConfigureAwait(false);
|
var response = await PutStreamObject(args, ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
return response.ObjectId;
|
return response.ObjectId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args)
|
internal async Task<FrostFsObjectId> PutSingleObjectAsync(PrmSingleObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var grpcObject = ObjectTools.CreateObject(args.FrostFsObject, ClientContext);
|
var grpcObject = ObjectTools.CreateObject(args.FrostFsObject, ClientContext);
|
||||||
|
|
||||||
var request = new PutSingleRequest
|
var request = new PutSingleRequest
|
||||||
|
@ -317,21 +312,19 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
|
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
var response = await client.PutSingleAsync(request, null, ctx.Deadline, ctx.CancellationToken).ConfigureAwait(false);
|
var response = await client.PutSingleAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
return FrostFsObjectId.FromHash(grpcObject.ObjectId.Value.Span);
|
return FrostFsObjectId.FromHash(grpcObject.ObjectId.Value.Span);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args)
|
internal async Task<FrostFsObjectId> PatchObjectAsync(PrmObjectPatch args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
var chunkSize = args.MaxChunkLength;
|
||||||
|
|
||||||
var chunkSize = args.MaxPayloadPatchChunkLength;
|
|
||||||
Stream payload = args.Payload ?? throw new ArgumentNullException(nameof(args), "Stream parameter is null");
|
Stream payload = args.Payload ?? throw new ArgumentNullException(nameof(args), "Stream parameter is null");
|
||||||
|
|
||||||
var call = client.Patch(null, ctx.Deadline, ctx.CancellationToken);
|
var call = client.Patch(null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
byte[]? chunkBuffer = null;
|
byte[]? chunkBuffer = null;
|
||||||
try
|
try
|
||||||
|
@ -415,36 +408,32 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
return response.Body.ObjectId.ToModel();
|
return response.Body.ObjectId.ToModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<FrostFsObjectId> PutClientCutObject(PrmObjectPut args)
|
private async Task<FrostFsObjectId> PutClientCutObject(PrmObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
args.SessionToken ??= await GetDefaultSession(args, ctx).ConfigureAwait(false);
|
|
||||||
|
|
||||||
var payloadStream = args.Payload!;
|
var payloadStream = args.Payload!;
|
||||||
var header = args.Header!;
|
var header = args.Header!;
|
||||||
|
|
||||||
if (header.PayloadLength > 0)
|
if (header.PayloadLength > 0)
|
||||||
args.FullLength = header.PayloadLength;
|
args.PutObjectContext.FullLength = header.PayloadLength;
|
||||||
else if (payloadStream.CanSeek)
|
else if (payloadStream.CanSeek)
|
||||||
args.FullLength = (ulong)payloadStream.Length;
|
args.PutObjectContext.FullLength = (ulong)payloadStream.Length;
|
||||||
else
|
else
|
||||||
throw new ArgumentException("The stream does not have a length and payload length is not defined");
|
throw new ArgumentException("The stream does not have a length and payload length is not defined");
|
||||||
|
|
||||||
if (args.MaxObjectSizeCache == 0)
|
if (args.PutObjectContext.MaxObjectSizeCache == 0)
|
||||||
{
|
{
|
||||||
var networkSettings = await ClientContext.Client.GetNetworkSettingsAsync(new PrmNetworkSettings(ctx))
|
var networkSettings = await ClientContext.Client.GetNetworkSettingsAsync(ctx)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
args.MaxObjectSizeCache = (int)networkSettings.MaxObjectSize;
|
args.PutObjectContext.MaxObjectSizeCache = (int)networkSettings.MaxObjectSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
var restBytes = args.FullLength - args.CurrentStreamPosition;
|
var restBytes = args.PutObjectContext.FullLength - args.PutObjectContext.CurrentStreamPosition;
|
||||||
var objectSize = restBytes > 0 ? (int)Math.Min((ulong)args.MaxObjectSizeCache, restBytes) : args.MaxObjectSizeCache;
|
var objectSize = restBytes > 0 ? (int)Math.Min((ulong)args.PutObjectContext.MaxObjectSizeCache, restBytes) : args.PutObjectContext.MaxObjectSizeCache;
|
||||||
|
|
||||||
//define collection capacity
|
//define collection capacity
|
||||||
var restPart = (restBytes % (ulong)objectSize) > 0 ? 1 : 0;
|
var restPart = (restBytes % (ulong)objectSize) > 0 ? 1 : 0;
|
||||||
var objectsCount = args.FullLength > 0 ? (int)(restBytes / (ulong)objectSize) + restPart : 0;
|
var objectsCount = args.PutObjectContext.FullLength > 0 ? (int)(restBytes / (ulong)objectSize) + restPart : 0;
|
||||||
|
|
||||||
List<FrostFsObjectId> sentObjectIds = new(objectsCount);
|
List<FrostFsObjectId> sentObjectIds = new(objectsCount);
|
||||||
|
|
||||||
|
@ -456,13 +445,13 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
args.Header!.Attributes = null;
|
args.Header!.Attributes = null;
|
||||||
|
|
||||||
// send all parts except the last one as separate Objects
|
// send all parts except the last one as separate Objects
|
||||||
while (restBytes > (ulong)args.MaxObjectSizeCache)
|
while (restBytes > (ulong)args.PutObjectContext.MaxObjectSizeCache)
|
||||||
{
|
{
|
||||||
split = new FrostFsSplit(splitId, sentObjectIds.LastOrDefault());
|
split = new FrostFsSplit(splitId, sentObjectIds.LastOrDefault());
|
||||||
|
|
||||||
args.Header!.Split = split;
|
args.Header!.Split = split;
|
||||||
|
|
||||||
var result = await PutStreamObject(args).ConfigureAwait(false);
|
var result = await PutStreamObject(args, default).ConfigureAwait(false);
|
||||||
|
|
||||||
sentObjectIds.Add(result.ObjectId);
|
sentObjectIds.Add(result.ObjectId);
|
||||||
|
|
||||||
|
@ -474,18 +463,18 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
{
|
{
|
||||||
var largeObjectHeader = new FrostFsObjectHeader(header.ContainerId, FrostFsObjectType.Regular, [.. attributes])
|
var largeObjectHeader = new FrostFsObjectHeader(header.ContainerId, FrostFsObjectType.Regular, [.. attributes])
|
||||||
{
|
{
|
||||||
PayloadLength = args.FullLength,
|
PayloadLength = args.PutObjectContext.FullLength,
|
||||||
};
|
};
|
||||||
|
|
||||||
args.Header.Split!.ParentHeader = largeObjectHeader;
|
args.Header.Split!.ParentHeader = largeObjectHeader;
|
||||||
|
|
||||||
var result = await PutStreamObject(args).ConfigureAwait(false);
|
var result = await PutStreamObject(args, default).ConfigureAwait(false);
|
||||||
|
|
||||||
sentObjectIds.Add(result.ObjectId);
|
sentObjectIds.Add(result.ObjectId);
|
||||||
|
|
||||||
var linkObject = new FrostFsLinkObject(header.ContainerId, split!.SplitId, largeObjectHeader, sentObjectIds);
|
var linkObject = new FrostFsLinkObject(header.ContainerId, split!.SplitId, largeObjectHeader, sentObjectIds);
|
||||||
|
|
||||||
_ = await PutSingleObjectAsync(new PrmSingleObjectPut(linkObject, args.Context)).ConfigureAwait(false);
|
_ = await PutSingleObjectAsync(new PrmSingleObjectPut(linkObject), ctx).ConfigureAwait(false);
|
||||||
|
|
||||||
var parentHeader = args.Header.GetHeader();
|
var parentHeader = args.Header.GetHeader();
|
||||||
|
|
||||||
|
@ -495,7 +484,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
// We are here if the payload is placed to one Object. It means no cut action, just simple PUT.
|
||||||
args.Header!.Attributes = attributes;
|
args.Header!.Attributes = attributes;
|
||||||
|
|
||||||
var singlePartResult = await PutStreamObject(args).ConfigureAwait(false);
|
var singlePartResult = await PutStreamObject(args, default).ConfigureAwait(false);
|
||||||
|
|
||||||
return singlePartResult.ObjectId;
|
return singlePartResult.ObjectId;
|
||||||
}
|
}
|
||||||
|
@ -506,15 +495,13 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
public int ObjectSize = objectSize;
|
public int ObjectSize = objectSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<PutObjectResult> PutStreamObject(PrmObjectPut args)
|
private async Task<PutObjectResult> PutStreamObject(PrmObjectPut args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var payload = args.Payload!;
|
var payload = args.Payload!;
|
||||||
|
|
||||||
var chunkSize = args.BufferMaxSize > 0 ? args.BufferMaxSize : Constants.ObjectChunkSize;
|
var chunkSize = args.BufferMaxSize > 0 ? args.BufferMaxSize : Constants.ObjectChunkSize;
|
||||||
|
|
||||||
var restBytes = args.FullLength - args.CurrentStreamPosition;
|
var restBytes = args.PutObjectContext.FullLength - args.PutObjectContext.CurrentStreamPosition;
|
||||||
|
|
||||||
chunkSize = (int)Math.Min(restBytes, (ulong)chunkSize);
|
chunkSize = (int)Math.Min(restBytes, (ulong)chunkSize);
|
||||||
|
|
||||||
|
@ -524,7 +511,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 0 means no limit from client, so server side cut is performed
|
// 0 means no limit from client, so server side cut is performed
|
||||||
var objectLimitSize = args.ClientCut ? args.MaxObjectSizeCache : 0;
|
var objectLimitSize = args.ClientCut ? args.PutObjectContext.MaxObjectSizeCache : 0;
|
||||||
|
|
||||||
if (args.CustomBuffer != null)
|
if (args.CustomBuffer != null)
|
||||||
{
|
{
|
||||||
|
@ -634,7 +621,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
throw new ArgumentNullException(nameof(initRequest));
|
throw new ArgumentNullException(nameof(initRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
var call = client.Put(null, ctx.Deadline, ctx.CancellationToken);
|
var call = client.Put(null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
await call.RequestStream.WriteAsync(initRequest).ConfigureAwait(false);
|
await call.RequestStream.WriteAsync(initRequest).ConfigureAwait(false);
|
||||||
|
|
||||||
|
@ -658,7 +645,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
if (initRequest is null)
|
if (initRequest is null)
|
||||||
throw new ArgumentNullException(nameof(initRequest));
|
throw new ArgumentNullException(nameof(initRequest));
|
||||||
|
|
||||||
var call = client.Get(initRequest, null, ctx.Deadline, ctx.CancellationToken);
|
var call = client.Get(initRequest, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
return new ObjectReader(call);
|
return new ObjectReader(call);
|
||||||
}
|
}
|
||||||
|
@ -670,7 +657,7 @@ internal sealed class ObjectServiceProvider(ObjectService.ObjectServiceClient cl
|
||||||
throw new ArgumentNullException(nameof(initRequest));
|
throw new ArgumentNullException(nameof(initRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
var call = client.Search(initRequest, null, ctx.Deadline, ctx.CancellationToken);
|
var call = client.Search(initRequest, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
return new SearchReader(call);
|
return new SearchReader(call);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,8 @@ internal sealed class SessionServiceProvider : ContextAccessor
|
||||||
_sessionServiceClient = sessionServiceClient;
|
_sessionServiceClient = sessionServiceClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<SessionToken> CreateSessionAsync(PrmSessionCreate args)
|
internal async Task<SessionToken> CreateSessionAsync(PrmSessionCreate args, CallContext ctx)
|
||||||
{
|
{
|
||||||
var ctx = args.Context!;
|
|
||||||
|
|
||||||
var request = new CreateRequest
|
var request = new CreateRequest
|
||||||
{
|
{
|
||||||
Body = new CreateRequest.Types.Body
|
Body = new CreateRequest.Types.Body
|
||||||
|
@ -30,12 +28,12 @@ internal sealed class SessionServiceProvider : ContextAccessor
|
||||||
request.AddMetaHeader(args.XHeaders);
|
request.AddMetaHeader(args.XHeaders);
|
||||||
request.Sign(ClientContext.Key.ECDsaKey);
|
request.Sign(ClientContext.Key.ECDsaKey);
|
||||||
|
|
||||||
return await CreateSession(request, args.Context!).ConfigureAwait(false);
|
return await CreateSession(request, ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task<SessionToken> CreateSession(CreateRequest request, CallContext ctx)
|
internal async Task<SessionToken> CreateSession(CreateRequest request, CallContext ctx)
|
||||||
{
|
{
|
||||||
var response = await _sessionServiceClient!.CreateAsync(request, null, ctx.Deadline, ctx.CancellationToken);
|
var response = await _sessionServiceClient!.CreateAsync(request, null, ctx.GetDeadline(), ctx.CancellationToken);
|
||||||
|
|
||||||
Verifier.CheckResponse(response);
|
Verifier.CheckResponse(response);
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,6 @@ internal sealed class SessionProvider(ClientContext envCtx)
|
||||||
|
|
||||||
internal async Task<Session.SessionToken> GetDefaultSession(ISessionToken args, CallContext ctx)
|
internal async Task<Session.SessionToken> GetDefaultSession(ISessionToken args, CallContext ctx)
|
||||||
{
|
{
|
||||||
return await envCtx.Client.CreateSessionInternalAsync(new PrmSessionCreate(uint.MaxValue, ctx)).ConfigureAwait(false);
|
return await envCtx.Client.CreateSessionInternalAsync(new PrmSessionCreate(uint.MaxValue), ctx).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,16 +11,6 @@ namespace FrostFS.SDK.Client;
|
||||||
|
|
||||||
internal static class ObjectTools
|
internal static class ObjectTools
|
||||||
{
|
{
|
||||||
internal static FrostFsObjectId CalculateObjectId(FrostFsObjectHeader header, ClientContext ctx)
|
|
||||||
{
|
|
||||||
var grpcHeader = CreateHeader(header, [], ctx);
|
|
||||||
|
|
||||||
if (header.Split != null)
|
|
||||||
SetSplitValues(grpcHeader, header.Split, ctx);
|
|
||||||
|
|
||||||
return new ObjectID { Value = grpcHeader.Sha256() }.ToModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static Object.Object CreateObject(FrostFsObject @object, ClientContext ctx)
|
internal static Object.Object CreateObject(FrostFsObject @object, ClientContext ctx)
|
||||||
{
|
{
|
||||||
@object.Header.OwnerId ??= ctx.Owner;
|
@object.Header.OwnerId ??= ctx.Owner;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||||
using FrostFS.SDK.Proto.Interfaces;
|
using FrostFS.SDK.Proto.Interfaces;
|
||||||
|
@ -11,7 +9,7 @@ namespace FrostFS.SDK.Client;
|
||||||
public static class RequestConstructor
|
public static class RequestConstructor
|
||||||
{
|
{
|
||||||
public static void AddMetaHeader(this IRequest request,
|
public static void AddMetaHeader(this IRequest request,
|
||||||
NameValueCollection? xHeaders,
|
string[] xHeaders,
|
||||||
SessionToken? sessionToken = null)
|
SessionToken? sessionToken = null)
|
||||||
{
|
{
|
||||||
if (request is null)
|
if (request is null)
|
||||||
|
@ -25,9 +23,15 @@ public static class RequestConstructor
|
||||||
if (sessionToken != null)
|
if (sessionToken != null)
|
||||||
request.MetaHeader.SessionToken = sessionToken;
|
request.MetaHeader.SessionToken = sessionToken;
|
||||||
|
|
||||||
if (xHeaders != null && xHeaders.Count > 0)
|
if (xHeaders != null && xHeaders.Length > 0)
|
||||||
request.MetaHeader.XHeaders.AddRange(
|
{
|
||||||
xHeaders.Cast<string>().SelectMany(key => xHeaders.GetValues(key),
|
if (xHeaders.Length % 2 != 0)
|
||||||
(k, v) => new XHeader { Key = k, Value = v }));
|
throw new ArgumentException("xHeaders with odd length");
|
||||||
|
|
||||||
|
for (var i = 0; i < xHeaders.Length; i += 2)
|
||||||
|
{
|
||||||
|
request.MetaHeader.XHeaders.Add(new XHeader { Key = xHeaders[i], Value = xHeaders[i + 1] });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
|
||||||
<PackageReference Include="Google.Protobuf" Version="3.27.0" />
|
<PackageReference Include="Google.Protobuf" Version="3.21.12" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
|
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
// This file is used by Code Analysis to maintain SuppressMessage
|
|
||||||
// attributes that are applied to this project.
|
|
||||||
// Project-level suppressions either have no target or are given
|
|
||||||
// a specific target and scoped to a namespace, type, member, etc.
|
|
||||||
|
|
||||||
|
|
42
src/FrostFS.SDK.Tests/Multithread/MultiThreadTestsBase.cs
Normal file
42
src/FrostFS.SDK.Tests/Multithread/MultiThreadTestsBase.cs
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
using FrostFS.SDK.Client;
|
||||||
|
using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
|
public abstract class MultiThreadTestsBase
|
||||||
|
{
|
||||||
|
private TestNodeInfo[] nodes;
|
||||||
|
|
||||||
|
protected CallContext? Ctx { get; }
|
||||||
|
|
||||||
|
protected MultiThreadTestsBase()
|
||||||
|
{
|
||||||
|
nodes = new TestNodeInfo[4];
|
||||||
|
|
||||||
|
nodes[0] = new(new Uri(""), "");
|
||||||
|
nodes[1] = new(new Uri(""), "");
|
||||||
|
nodes[2] = new(new Uri(""), "");
|
||||||
|
nodes[3] = new(new Uri(""), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestNodeInfo
|
||||||
|
{
|
||||||
|
internal Uri Uri;
|
||||||
|
|
||||||
|
protected ECDsa? Key { get; }
|
||||||
|
|
||||||
|
protected FrostFsOwner? OwnerId { get; }
|
||||||
|
|
||||||
|
protected FrostFsVersion? Version { get; }
|
||||||
|
|
||||||
|
public TestNodeInfo(Uri uri, string keyString)
|
||||||
|
{
|
||||||
|
Uri = uri;
|
||||||
|
Key = keyString.LoadWif();
|
||||||
|
OwnerId = FrostFsOwner.FromKey(Key);
|
||||||
|
Version = new FrostFsVersion(2, 13);
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,11 +6,11 @@ using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.SmokeTests;
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[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")]
|
[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "No secure purpose")]
|
||||||
public class PoolSmokeTests : SmokeTestsBase
|
public class MultithreadPoolSmokeTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
private static readonly PrmWait lightWait = new(100, 1);
|
private static readonly PrmWait lightWait = new(100, 1);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
Key = keyString.LoadWif(),
|
Key = keyString.LoadWif(),
|
||||||
|
|
||||||
NodeParams = [new(1, this.url, 100.0f)],
|
NodeParams = [new(1, url, 100.0f)],
|
||||||
ClientBuilder = null,
|
ClientBuilder = null,
|
||||||
GracefulCloseOnSwitchTimeout = 30_000_000,
|
GracefulCloseOnSwitchTimeout = 30_000_000,
|
||||||
Logger = null
|
Logger = null
|
||||||
|
@ -34,7 +34,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext());
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero));
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
|
@ -59,11 +59,11 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext());
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero));
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
var result = await pool.GetNodeInfoAsync();
|
var result = await pool.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
Assert.Equal(2, result.Version.Major);
|
Assert.Equal(2, result.Version.Major);
|
||||||
Assert.Equal(13, result.Version.Minor);
|
Assert.Equal(13, result.Version.Minor);
|
||||||
|
@ -82,8 +82,8 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
Key = keyString.LoadWif(),
|
Key = keyString.LoadWif(),
|
||||||
NodeParams = [
|
NodeParams = [
|
||||||
new(1, this.url, 100.0f),
|
new(1, url, 100.0f),
|
||||||
new(2, this.url.Replace('0', '1'), 100.0f)
|
new(2, url.Replace('0', '1'), 100.0f)
|
||||||
],
|
],
|
||||||
ClientBuilder = null,
|
ClientBuilder = null,
|
||||||
GracefulCloseOnSwitchTimeout = 30_000_000,
|
GracefulCloseOnSwitchTimeout = 30_000_000,
|
||||||
|
@ -93,17 +93,15 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var ctx = new CallContext
|
var ctx = new CallContext(TimeSpan.Zero);
|
||||||
{
|
|
||||||
};
|
|
||||||
|
|
||||||
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetSingleOwnerOptions(keyString, url));
|
||||||
|
|
||||||
var result = await client.GetNodeInfoAsync();
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
var statistics = pool.Statistic();
|
var statistics = pool.Statistic();
|
||||||
|
|
||||||
|
@ -121,15 +119,15 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var ctx = new CallContext();
|
var ctx = new CallContext(TimeSpan.Zero);
|
||||||
|
|
||||||
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetSingleOwnerOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetSingleOwnerOptions(keyString, url));
|
||||||
|
|
||||||
var result = await client.GetNodeInfoAsync();
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
Assert.False(string.IsNullOrEmpty(callbackText));
|
Assert.False(string.IsNullOrEmpty(callbackText));
|
||||||
Assert.Contains(" took ", callbackText, StringComparison.Ordinal);
|
Assert.Contains(" took ", callbackText, StringComparison.Ordinal);
|
||||||
|
@ -142,13 +140,13 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
var prm = new PrmSessionCreate(100);
|
var prm = new PrmSessionCreate(100);
|
||||||
|
|
||||||
var token = await pool.CreateSessionAsync(prm).ConfigureAwait(true);
|
var token = await pool.CreateSessionAsync(prm, default).ConfigureAwait(true);
|
||||||
|
|
||||||
var ownerHash = Base58.Decode(OwnerId!.Value);
|
var ownerHash = Base58.Decode(OwnerId!.Value);
|
||||||
|
|
||||||
|
@ -164,37 +162,36 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue));
|
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))));
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["key1", "value1"]);
|
||||||
|
|
||||||
createContainerParam.XHeaders.Add("key1", "value1");
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var containerId = await pool.CreateContainerAsync(createContainerParam);
|
|
||||||
|
|
||||||
var bytes = GetRandomBytes(1024);
|
var bytes = GetRandomBytes(1024);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
bufferMaxSize: 1024,
|
||||||
ClientCut = false,
|
payload: new MemoryStream(bytes),
|
||||||
SessionToken = token
|
clientCut: false,
|
||||||
};
|
sessionToken: token);
|
||||||
|
|
||||||
var objectId = await pool.PutObjectAsync(param).ConfigureAwait(true);
|
var objectId = await pool.PutObjectAsync(param, default).ConfigureAwait(true);
|
||||||
|
|
||||||
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId));
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -217,19 +214,17 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))))
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
{
|
lightWait);
|
||||||
WaitParams = lightWait
|
|
||||||
};
|
|
||||||
|
|
||||||
var containerId = await pool.CreateContainerAsync(createContainerParam);
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var bytes = new byte[] { 1, 2, 3 };
|
var bytes = new byte[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
@ -240,30 +235,28 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
PayloadLength = 3
|
PayloadLength = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")],
|
[new FrostFsAttributePair("fileName", "test")],
|
||||||
new FrostFsSplit()),
|
new FrostFsSplit()),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await pool.PutObjectAsync(param);
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var head = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId));
|
var head = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId, false), default);
|
||||||
|
|
||||||
var ecdsaKey = this.keyString.LoadWif();
|
var ecdsaKey = keyString.LoadWif();
|
||||||
|
|
||||||
var networkInfo = await pool.GetNetmapSnapshotAsync();
|
var networkInfo = await pool.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
await CheckFilter(pool, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
await CheckFilter(pool, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
||||||
|
|
||||||
await CheckFilter(pool, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
await CheckFilter(pool, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
||||||
|
|
||||||
await CheckFilter(pool, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header.Split!.SplitId));
|
await CheckFilter(pool, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header!.Split!.SplitId));
|
||||||
|
|
||||||
await CheckFilter(pool, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
await CheckFilter(pool, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
||||||
|
|
||||||
|
@ -286,12 +279,12 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
var resultObjectsCount = 0;
|
var resultObjectsCount = 0;
|
||||||
|
|
||||||
PrmObjectSearch searchParam = new(containerId) { Filters = [filter] };
|
PrmObjectSearch searchParam = new(containerId, null, [], filter);
|
||||||
|
|
||||||
await foreach (var objId in pool.SearchObjectsAsync(searchParam))
|
await foreach (var objId in pool.SearchObjectsAsync(searchParam, default))
|
||||||
{
|
{
|
||||||
resultObjectsCount++;
|
resultObjectsCount++;
|
||||||
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId));
|
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId), default);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
||||||
|
@ -307,7 +300,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
var options = GetDefaultParams();
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
options.Callback = new((CallStatistics cs) =>
|
options.Callback = new((cs) =>
|
||||||
{
|
{
|
||||||
callbackInvoked = true;
|
callbackInvoked = true;
|
||||||
Assert.True(cs.ElapsedMicroSeconds > 0);
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
|
@ -315,45 +308,45 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
var ctx = new CallContext { };
|
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]), ctx);
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
var createdContainer = await pool.CreateContainerAsync(createContainerParam);
|
var createdContainer = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var container = await pool.GetContainerAsync(new PrmContainerGet(createdContainer));
|
var container = await pool.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
Assert.True(callbackInvoked);
|
Assert.True(callbackInvoked);
|
||||||
|
|
||||||
var bytes = GetRandomBytes(objectSize);
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut()
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: createdContainer,
|
containerId: createdContainer,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await pool.PutObjectAsync(param);
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] }))
|
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(createdContainer, null, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId));
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId), default);
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes!);
|
Assert.Single(objHeader.Attributes!);
|
||||||
|
@ -363,7 +356,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await pool.GetObjectAsync(new PrmObjectGet(createdContainer, objectId));
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(createdContainer, objectId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -378,7 +371,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
await foreach (var _ in pool.ListContainersAsync())
|
await foreach (var _ in pool.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -393,52 +386,51 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
var options = GetDefaultParams();
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
options.Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0));
|
options.Callback = new((cs) => Assert.True(cs.ElapsedMicroSeconds > 0));
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue));
|
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
var ctx = new CallContext
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
};
|
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))), ctx);
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams);
|
||||||
|
|
||||||
var container = await pool.CreateContainerAsync(createContainerParam);
|
var container = await pool.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
var containerInfo = await pool.GetContainerAsync(new PrmContainerGet(container, ctx));
|
var containerInfo = await pool.GetContainerAsync(new PrmContainerGet(container), ctx);
|
||||||
Assert.NotNull(containerInfo);
|
Assert.NotNull(containerInfo);
|
||||||
|
|
||||||
var bytes = GetRandomBytes(objectSize);
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut(new CallContext())
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: container,
|
containerId: container,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false,
|
clientCut: false,
|
||||||
SessionToken = token
|
sessionToken: token);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await pool.PutObjectAsync(param);
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(container) { Filters = [filter], SessionToken = token }))
|
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(container, token, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId) { SessionToken = token });
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId, false, token), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
@ -448,7 +440,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await pool.GetObjectAsync(new PrmObjectGet(container, objectId) { SessionToken = token });
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(container, objectId, token), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -463,7 +455,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
await foreach (var _ in pool.ListContainersAsync())
|
await foreach (var _ in pool.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -482,52 +474,49 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
using var pool = new Pool(options);
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
var error = await pool.Dial(new CallContext()).ConfigureAwait(true);
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
Assert.Null(error);
|
Assert.Null(error);
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))))
|
var createContainerParam = new PrmContainerCreate(
|
||||||
{
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
WaitParams = lightWait
|
lightWait);
|
||||||
};
|
|
||||||
|
|
||||||
var containerId = await pool.CreateContainerAsync(createContainerParam);
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var ctx = new CallContext
|
var ctx = new CallContext(TimeSpan.FromSeconds(10));
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromSeconds(10),
|
|
||||||
};
|
|
||||||
|
|
||||||
// ctx.Interceptors.Add(new CallbackInterceptor());
|
// ctx.Interceptors.Add(new CallbackInterceptor());
|
||||||
|
|
||||||
var container = await pool.GetContainerAsync(new PrmContainerGet(containerId, ctx));
|
var container = await pool.GetContainerAsync(new PrmContainerGet(containerId), ctx);
|
||||||
|
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
|
|
||||||
byte[] bytes = GetRandomBytes(objectSize);
|
byte[] bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = true
|
clientCut: true);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await pool.PutObjectAsync(param);
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(containerId, null, filter)))
|
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(containerId, null, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId));
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
@ -537,7 +526,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId));
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -554,7 +543,7 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(pool);
|
await Cleanup(pool);
|
||||||
|
|
||||||
await foreach (var cid in pool.ListContainersAsync())
|
await foreach (var cid in pool.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail($"Container {cid.GetValue()} exist");
|
Assert.Fail($"Container {cid.GetValue()} exist");
|
||||||
}
|
}
|
||||||
|
@ -587,9 +576,9 @@ public class PoolSmokeTests : SmokeTestsBase
|
||||||
|
|
||||||
static async Task Cleanup(Pool pool)
|
static async Task Cleanup(Pool pool)
|
||||||
{
|
{
|
||||||
await foreach (var cid in pool.ListContainersAsync())
|
await foreach (var cid in pool.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
await pool.DeleteContainerAsync(new PrmContainerDelete(cid) { WaitParams = lightWait }).ConfigureAwait(true);
|
await pool.DeleteContainerAsync(new PrmContainerDelete(cid, lightWait), default).ConfigureAwait(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,23 +4,24 @@ using System.Security.Cryptography;
|
||||||
using FrostFS.SDK.Client;
|
using FrostFS.SDK.Client;
|
||||||
using FrostFS.SDK.Client.Interfaces;
|
using FrostFS.SDK.Client.Interfaces;
|
||||||
using FrostFS.SDK.Cryptography;
|
using FrostFS.SDK.Cryptography;
|
||||||
|
using FrostFS.SDK.SmokeTests;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.SmokeTests;
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[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")]
|
[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "No secure purpose")]
|
||||||
public class SmokeClientTests : SmokeTestsBase
|
public class MultithreadSmokeClientTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
private static readonly PrmWait lightWait = new(100, 1);
|
private static readonly PrmWait lightWait = new(100, 1);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void AccountTest()
|
public async void AccountTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
var result = await client.GetBalanceAsync();
|
var result = await client.GetBalanceAsync(default);
|
||||||
|
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.True(result.Value == 0);
|
Assert.True(result.Value == 0);
|
||||||
|
@ -29,9 +30,9 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void NetworkMapTest()
|
public async void NetworkMapTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
var result = await client.GetNetmapSnapshotAsync();
|
var result = await client.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
Assert.True(result.Epoch > 0);
|
Assert.True(result.Epoch > 0);
|
||||||
Assert.Single(result.NodeInfoCollection);
|
Assert.Single(result.NodeInfoCollection);
|
||||||
|
@ -49,9 +50,9 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void NodeInfoTest()
|
public async void NodeInfoTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
var result = await client.GetNodeInfoAsync();
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
Assert.Equal(2, result.Version.Major);
|
Assert.Equal(2, result.Version.Major);
|
||||||
Assert.Equal(13, result.Version.Minor);
|
Assert.Equal(13, result.Version.Minor);
|
||||||
|
@ -64,14 +65,14 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void NodeInfoStatisticsTest()
|
public async void NodeInfoStatisticsTest()
|
||||||
{
|
{
|
||||||
var options = GetClientOptions(this.keyString, this.url);
|
var options = GetClientOptions(keyString, url);
|
||||||
|
|
||||||
var callbackContent = string.Empty;
|
var callbackContent = string.Empty;
|
||||||
options.Value.Callback = (cs) => callbackContent = $"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds";
|
options.Value.Callback = (cs) => callbackContent = $"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds";
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(options);
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
var result = await client.GetNodeInfoAsync();
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
Assert.NotEmpty(callbackContent);
|
Assert.NotEmpty(callbackContent);
|
||||||
}
|
}
|
||||||
|
@ -79,11 +80,9 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void GetSessionTest()
|
public async void GetSessionTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
PrmSessionCreate? prm = new(100);
|
var token = await client.CreateSessionAsync(new(100), default);
|
||||||
|
|
||||||
var token = await client.CreateSessionAsync(prm);
|
|
||||||
|
|
||||||
var ownerHash = Base58.Decode(OwnerId!.Value);
|
var ownerHash = Base58.Decode(OwnerId!.Value);
|
||||||
|
|
||||||
|
@ -95,35 +94,33 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void CreateObjectWithSessionToken()
|
public async void CreateObjectWithSessionToken()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue));
|
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))));
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["key1", "value1"]);
|
||||||
|
|
||||||
createContainerParam.XHeaders.Add("key1", "value1");
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
|
||||||
|
|
||||||
var bytes = GetRandomBytes(1024);
|
var bytes = GetRandomBytes(1024);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false,
|
clientCut: false,
|
||||||
SessionToken = token
|
sessionToken: token);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param).ConfigureAwait(true);
|
var objectId = await client.PutObjectAsync(param, default).ConfigureAwait(true);
|
||||||
|
|
||||||
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId))
|
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId), default)
|
||||||
.ConfigureAwait(true);
|
.ConfigureAwait(true);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
@ -143,17 +140,15 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void FilterTest()
|
public async void FilterTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))))
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
{
|
lightWait);
|
||||||
WaitParams = lightWait
|
|
||||||
};
|
|
||||||
|
|
||||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var bytes = new byte[] { 1, 2, 3 };
|
var bytes = new byte[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
@ -164,30 +159,28 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
PayloadLength = 3
|
PayloadLength = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")],
|
[new FrostFsAttributePair("fileName", "test")],
|
||||||
new FrostFsSplit()),
|
new FrostFsSplit()),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var head = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId));
|
var head = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
var ecdsaKey = this.keyString.LoadWif();
|
var ecdsaKey = keyString.LoadWif();
|
||||||
|
|
||||||
var networkInfo = await client.GetNetmapSnapshotAsync();
|
var networkInfo = await client.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
await CheckFilter(client, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
await CheckFilter(client, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
||||||
|
|
||||||
await CheckFilter(client, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
await CheckFilter(client, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
||||||
|
|
||||||
await CheckFilter(client, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header.Split!.SplitId));
|
await CheckFilter(client, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header!.Split!.SplitId));
|
||||||
|
|
||||||
await CheckFilter(client, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
await CheckFilter(client, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
||||||
|
|
||||||
|
@ -210,12 +203,12 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
var resultObjectsCount = 0;
|
var resultObjectsCount = 0;
|
||||||
|
|
||||||
PrmObjectSearch searchParam = new(containerId) { Filters = [filter] };
|
PrmObjectSearch searchParam = new(containerId, null, [], filter);
|
||||||
|
|
||||||
await foreach (var objId in client.SearchObjectsAsync(searchParam))
|
await foreach (var objId in client.SearchObjectsAsync(searchParam, default))
|
||||||
{
|
{
|
||||||
resultObjectsCount++;
|
resultObjectsCount++;
|
||||||
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId));
|
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId), default);
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
||||||
|
@ -229,51 +222,53 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
{
|
{
|
||||||
bool callbackInvoked = false;
|
bool callbackInvoked = false;
|
||||||
|
|
||||||
var options = GetClientOptions(this.keyString, this.url);
|
var options = GetClientOptions(keyString, url);
|
||||||
|
|
||||||
options.Value.Callback = new((CallStatistics cs) =>
|
options.Value.Callback = new((cs) =>
|
||||||
{
|
{
|
||||||
callbackInvoked = true;
|
callbackInvoked = true;
|
||||||
Assert.True(cs.ElapsedMicroSeconds > 0);
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(options);
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var ctx = new CallContext { Timeout = TimeSpan.FromSeconds(20) };
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]), ctx);
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
var createdContainer = await client.CreateContainerAsync(createContainerParam);
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
Assert.True(callbackInvoked);
|
Assert.True(callbackInvoked);
|
||||||
|
|
||||||
var bytes = GetRandomBytes(objectSize);
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: createdContainer,
|
containerId: createdContainer,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer) { Filters = [filter] }))
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer, null, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId));
|
var res = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId), default);
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
@ -283,7 +278,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId));
|
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -298,7 +293,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
await foreach (var _ in client.ListContainersAsync())
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -307,54 +302,53 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PatchTest()
|
public async void PatchTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
var createdContainer = await client.CreateContainerAsync(createContainerParam);
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
|
|
||||||
var bytes = new byte[1024];
|
var bytes = new byte[1024];
|
||||||
for (int i = 0; i < 1024; i++)
|
for (int i = 0; i < 1024; i++)
|
||||||
{
|
{
|
||||||
bytes[i] = (byte)31;
|
bytes[i] = 31;
|
||||||
}
|
}
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: createdContainer,
|
containerId: createdContainer,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var patch = new byte[16];
|
var patch = new byte[16];
|
||||||
for (int i = 0; i < 16; i++)
|
for (int i = 0; i < 16; i++)
|
||||||
{
|
{
|
||||||
patch[i] = (byte)32;
|
patch[i] = 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
var range = new FrostFsRange(8, (ulong)patch.Length);
|
var range = new FrostFsRange(8, (ulong)patch.Length);
|
||||||
|
|
||||||
var patchParams = new PrmObjectPatch(new FrostFsAddress(createdContainer, objectId))
|
var patchParams = new PrmObjectPatch(
|
||||||
{
|
new FrostFsAddress(createdContainer, objectId),
|
||||||
Payload = new MemoryStream(patch),
|
payload: new MemoryStream(patch),
|
||||||
MaxPayloadPatchChunkLength = 32,
|
maxChunkLength: 32,
|
||||||
Range = range
|
range: range);
|
||||||
};
|
|
||||||
|
|
||||||
var newIbjId = await client.PatchObjectAsync(patchParams);
|
var newIbjId = await client.PatchObjectAsync(patchParams, default);
|
||||||
|
|
||||||
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, newIbjId));
|
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, newIbjId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -378,7 +372,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
await foreach (var _ in client.ListContainersAsync())
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -387,16 +381,18 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void RangeTest()
|
public async void RangeTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
var createdContainer = await client.CreateContainerAsync(createContainerParam);
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
|
|
||||||
var bytes = new byte[256];
|
var bytes = new byte[256];
|
||||||
|
@ -405,20 +401,16 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
bytes[i] = (byte)i;
|
bytes[i] = (byte)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(containerId: createdContainer, type: FrostFsObjectType.Regular),
|
||||||
Header = new FrostFsObjectHeader(
|
payload: new MemoryStream(bytes),
|
||||||
containerId: createdContainer,
|
clientCut: false);
|
||||||
type: FrostFsObjectType.Regular),
|
|
||||||
Payload = new MemoryStream(bytes),
|
|
||||||
ClientCut = false
|
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var rangeParam = new PrmRangeGet(createdContainer, objectId, new FrostFsRange(100, 64));
|
var rangeParam = new PrmRangeGet(createdContainer, objectId, new FrostFsRange(100, 64));
|
||||||
|
|
||||||
var rangeReader = await client.GetRangeAsync(rangeParam);
|
var rangeReader = await client.GetRangeAsync(rangeParam, default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[rangeParam.Range.Length];
|
var downloadedBytes = new byte[rangeParam.Range.Length];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -433,7 +425,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
await foreach (var _ in client.ListContainersAsync())
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -442,16 +434,18 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void RangeHashTest()
|
public async void RangeHashTest()
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1)), [new("testKey", "testValue")]));
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
var createdContainer = await client.CreateContainerAsync(createContainerParam);
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer));
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
|
|
||||||
var bytes = new byte[256];
|
var bytes = new byte[256];
|
||||||
|
@ -460,20 +454,18 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
bytes[i] = (byte)i;
|
bytes[i] = (byte)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: createdContainer,
|
containerId: createdContainer,
|
||||||
type: FrostFsObjectType.Regular),
|
type: FrostFsObjectType.Regular),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false
|
clientCut: false);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var rangeParam = new PrmRangeHashGet(createdContainer, objectId, [new FrostFsRange(100, 64)], bytes);
|
var rangeParam = new PrmRangeHashGet(createdContainer, objectId, [new FrostFsRange(100, 64)], bytes);
|
||||||
|
|
||||||
var hashes = await client.GetRangeHashAsync(rangeParam);
|
var hashes = await client.GetRangeHashAsync(rangeParam, default);
|
||||||
|
|
||||||
foreach (var hash in hashes)
|
foreach (var hash in hashes)
|
||||||
{
|
{
|
||||||
|
@ -482,7 +474,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
await foreach (var _ in client.ListContainersAsync())
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -494,49 +486,48 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
[InlineData(6 * 1024 * 1024 + 100)]
|
[InlineData(6 * 1024 * 1024 + 100)]
|
||||||
public async void SimpleScenarioWithSessionTest(int objectSize)
|
public async void SimpleScenarioWithSessionTest(int objectSize)
|
||||||
{
|
{
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
//Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0))
|
//Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0))
|
||||||
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue));
|
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var ctx = new CallContext
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
{
|
|
||||||
Timeout = TimeSpan.FromSeconds(20),
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(
|
var createContainerParam = new PrmContainerCreate(
|
||||||
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))), ctx);
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams);
|
||||||
|
|
||||||
var container = await client.CreateContainerAsync(createContainerParam);
|
var container = await client.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
var containerInfo = await client.GetContainerAsync(new PrmContainerGet(container, ctx));
|
var containerInfo = await client.GetContainerAsync(new PrmContainerGet(container), ctx);
|
||||||
Assert.NotNull(containerInfo);
|
Assert.NotNull(containerInfo);
|
||||||
|
|
||||||
var bytes = GetRandomBytes(objectSize);
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: container,
|
containerId: container,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = false,
|
clientCut: false,
|
||||||
SessionToken = token
|
sessionToken: token);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(container) { Filters = [filter], SessionToken = token }))
|
await foreach (var objId in client.SearchObjectsAsync(
|
||||||
|
new PrmObjectSearch(container, token, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId) { SessionToken = token });
|
var res = await client.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId, false, token), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
@ -546,7 +537,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await client.GetObjectAsync(new PrmObjectGet(container, objectId) { SessionToken = token });
|
var @object = await client.GetObjectAsync(new PrmObjectGet(container, objectId, token), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -561,7 +552,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
await foreach (var _ in client.ListContainersAsync())
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
Assert.Fail("Containers exist");
|
Assert.Fail("Containers exist");
|
||||||
}
|
}
|
||||||
|
@ -577,48 +568,48 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
public async void ClientCutScenarioTest(int objectSize)
|
public async void ClientCutScenarioTest(int objectSize)
|
||||||
{
|
{
|
||||||
|
|
||||||
var options = GetClientOptions(this.keyString, this.url);
|
var options = GetClientOptions(keyString, url);
|
||||||
options.Value.Interceptors.Add(new CallbackInterceptor());
|
options.Value.Interceptors.Add(new CallbackInterceptor());
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(GetClientOptions(this.keyString, this.url));
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
await Cleanup(client);
|
await Cleanup(client);
|
||||||
|
|
||||||
var createContainerParam = new PrmContainerCreate(new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))))
|
var createContainerParam = new PrmContainerCreate(
|
||||||
{
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
WaitParams = lightWait
|
lightWait);
|
||||||
};
|
|
||||||
|
|
||||||
var containerId = await client.CreateContainerAsync(createContainerParam);
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
var ctx = new CallContext { Timeout = TimeSpan.FromSeconds(10) };
|
var ctx = new CallContext(TimeSpan.FromSeconds(10));
|
||||||
|
|
||||||
var container = await client.GetContainerAsync(new PrmContainerGet(containerId, ctx));
|
var container = await client.GetContainerAsync(new PrmContainerGet(containerId), ctx);
|
||||||
|
|
||||||
Assert.NotNull(container);
|
Assert.NotNull(container);
|
||||||
|
|
||||||
byte[] bytes = GetRandomBytes(objectSize);
|
byte[] bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
new FrostFsObjectHeader(
|
||||||
Header = new FrostFsObjectHeader(
|
|
||||||
containerId: containerId,
|
containerId: containerId,
|
||||||
type: FrostFsObjectType.Regular,
|
type: FrostFsObjectType.Regular,
|
||||||
[new FrostFsAttributePair("fileName", "test")]),
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
Payload = new MemoryStream(bytes),
|
payload: new MemoryStream(bytes),
|
||||||
ClientCut = true
|
clientCut: true);
|
||||||
};
|
|
||||||
|
|
||||||
var objectId = await client.PutObjectAsync(param);
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
bool hasObject = false;
|
bool hasObject = false;
|
||||||
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, null, filter)))
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, null, [], filter), default))
|
||||||
{
|
{
|
||||||
hasObject = true;
|
hasObject = true;
|
||||||
|
|
||||||
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId));
|
var res = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
Assert.NotNull(objHeader.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(objHeader.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
@ -628,7 +619,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
Assert.True(hasObject);
|
Assert.True(hasObject);
|
||||||
|
|
||||||
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId));
|
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
MemoryStream ms = new(downloadedBytes);
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
@ -656,7 +647,7 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
enumerator = client.ListContainersAsync().GetAsyncEnumerator();
|
enumerator = client.ListContainersAsync(default, default).GetAsyncEnumerator();
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
}
|
}
|
||||||
while (await enumerator!.MoveNextAsync());
|
while (await enumerator!.MoveNextAsync());
|
||||||
|
@ -668,8 +659,8 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
bool callbackInvoked = false;
|
bool callbackInvoked = false;
|
||||||
bool intercepterInvoked = false;
|
bool intercepterInvoked = false;
|
||||||
|
|
||||||
var options = GetClientOptions(this.keyString, this.url);
|
var options = GetClientOptions(keyString, url);
|
||||||
options.Value.Callback = (CallStatistics cs) =>
|
options.Value.Callback = (cs) =>
|
||||||
{
|
{
|
||||||
callbackInvoked = true;
|
callbackInvoked = true;
|
||||||
Assert.True(cs.ElapsedMicroSeconds > 0);
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
|
@ -677,9 +668,9 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
options.Value.Interceptors.Add(new CallbackInterceptor(s => intercepterInvoked = true));
|
options.Value.Interceptors.Add(new CallbackInterceptor(s => intercepterInvoked = true));
|
||||||
|
|
||||||
using var client = FrostFSClient.GetSingleOwnerInstance(options);
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
var result = await client.GetNodeInfoAsync(new PrmNodeInfo());
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
Assert.True(callbackInvoked);
|
Assert.True(callbackInvoked);
|
||||||
Assert.True(intercepterInvoked);
|
Assert.True(intercepterInvoked);
|
||||||
|
@ -712,9 +703,9 @@ public class SmokeClientTests : SmokeTestsBase
|
||||||
|
|
||||||
static async Task Cleanup(IFrostFSClient client)
|
static async Task Cleanup(IFrostFSClient client)
|
||||||
{
|
{
|
||||||
await foreach (var cid in client.ListContainersAsync())
|
await foreach (var cid in client.ListContainersAsync(default, default))
|
||||||
{
|
{
|
||||||
await client.DeleteContainerAsync(new PrmContainerDelete(cid) { WaitParams = lightWait });
|
await client.DeleteContainerAsync(new PrmContainerDelete(cid, lightWait), default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
585
src/FrostFS.SDK.Tests/Smoke/PoolSmokeTests.cs
Normal file
585
src/FrostFS.SDK.Tests/Smoke/PoolSmokeTests.cs
Normal file
|
@ -0,0 +1,585 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
using FrostFS.SDK.Client;
|
||||||
|
using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
|
[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 PoolSmokeTests : SmokeTestsBase
|
||||||
|
{
|
||||||
|
private static readonly PrmWait lightWait = new(100, 1);
|
||||||
|
|
||||||
|
private InitParameters GetDefaultParams()
|
||||||
|
{
|
||||||
|
return new InitParameters
|
||||||
|
{
|
||||||
|
Key = keyString.LoadWif(),
|
||||||
|
|
||||||
|
NodeParams = [new(1, url, 100.0f)],
|
||||||
|
ClientBuilder = null,
|
||||||
|
GracefulCloseOnSwitchTimeout = 30_000_000,
|
||||||
|
Logger = null
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NetworkMapTest()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero));
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
var result = await pool.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
|
Assert.True(result.Epoch > 0);
|
||||||
|
Assert.Single(result.NodeInfoCollection);
|
||||||
|
|
||||||
|
var item = result.NodeInfoCollection[0];
|
||||||
|
Assert.Equal(2, item.Version.Major);
|
||||||
|
Assert.Equal(13, item.Version.Minor);
|
||||||
|
Assert.Equal(NodeState.Online, item.State);
|
||||||
|
Assert.True(item.PublicKey.Length > 0);
|
||||||
|
Assert.Single(item.Addresses);
|
||||||
|
Assert.Equal(9, item.Attributes.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoTest()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero));
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
var result = await pool.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
Assert.Equal(2, result.Version.Major);
|
||||||
|
Assert.Equal(13, result.Version.Minor);
|
||||||
|
Assert.Equal(NodeState.Online, result.State);
|
||||||
|
Assert.Equal(33, result.PublicKey.Length);
|
||||||
|
Assert.Single(result.Addresses);
|
||||||
|
Assert.Equal(9, result.Attributes.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoStatisticsTwoNodesTest()
|
||||||
|
{
|
||||||
|
var callbackText = string.Empty;
|
||||||
|
|
||||||
|
var options = new InitParameters
|
||||||
|
{
|
||||||
|
Key = keyString.LoadWif(),
|
||||||
|
NodeParams = [
|
||||||
|
new(1, url, 100.0f),
|
||||||
|
new(2, url.Replace('0', '1'), 100.0f)
|
||||||
|
],
|
||||||
|
ClientBuilder = null,
|
||||||
|
GracefulCloseOnSwitchTimeout = 30_000_000,
|
||||||
|
Logger = null,
|
||||||
|
Callback = (cs) => callbackText = $"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds"
|
||||||
|
};
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.Zero);
|
||||||
|
|
||||||
|
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(GetSingleOwnerOptions(keyString, url));
|
||||||
|
|
||||||
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
var statistics = pool.Statistic();
|
||||||
|
|
||||||
|
Assert.False(string.IsNullOrEmpty(callbackText));
|
||||||
|
Assert.Contains(" took ", callbackText, StringComparison.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoStatisticsTest()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
var callbackText = string.Empty;
|
||||||
|
options.Callback = (cs) => callbackText = $"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds";
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.Zero);
|
||||||
|
|
||||||
|
var error = await pool.Dial(ctx).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(GetSingleOwnerOptions(keyString, url));
|
||||||
|
|
||||||
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
Assert.False(string.IsNullOrEmpty(callbackText));
|
||||||
|
Assert.Contains(" took ", callbackText, StringComparison.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetSessionTest()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
var prm = new PrmSessionCreate(100);
|
||||||
|
|
||||||
|
var token = await pool.CreateSessionAsync(prm, default).ConfigureAwait(true);
|
||||||
|
|
||||||
|
var ownerHash = Base58.Decode(OwnerId!.Value);
|
||||||
|
|
||||||
|
Assert.NotNull(token);
|
||||||
|
Assert.NotEqual(Guid.Empty, token.Id);
|
||||||
|
Assert.Equal(33, token.SessionKey.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void CreateObjectWithSessionToken()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["key1", "value1"]);
|
||||||
|
|
||||||
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(1024);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false,
|
||||||
|
sessionToken: token);
|
||||||
|
|
||||||
|
var objectId = await pool.PutObjectAsync(param, default).ConfigureAwait(true);
|
||||||
|
|
||||||
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void FilterTest()
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
lightWait);
|
||||||
|
|
||||||
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var bytes = new byte[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
var ParentHeader = new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular)
|
||||||
|
{
|
||||||
|
PayloadLength = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")],
|
||||||
|
new FrostFsSplit()),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var head = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var ecdsaKey = keyString.LoadWif();
|
||||||
|
|
||||||
|
var networkInfo = await pool.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header!.Split!.SplitId));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByObjectId(FrostFsMatchType.Equals, objectId));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByVersion(FrostFsMatchType.Equals, networkInfo.NodeInfoCollection[0].Version));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByEpoch(FrostFsMatchType.Equals, networkInfo.Epoch));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByPayloadLength(FrostFsMatchType.Equals, 3));
|
||||||
|
|
||||||
|
var checkSum = CheckSum.CreateCheckSum(bytes);
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByPayloadHash(FrostFsMatchType.Equals, checkSum));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByPhysicallyStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task CheckFilter(Pool pool, FrostFsContainerId containerId, IObjectFilter filter)
|
||||||
|
{
|
||||||
|
var resultObjectsCount = 0;
|
||||||
|
|
||||||
|
PrmObjectSearch searchParam = new(containerId, null, [], filter);
|
||||||
|
|
||||||
|
await foreach (var objId in pool.SearchObjectsAsync(searchParam, default))
|
||||||
|
{
|
||||||
|
resultObjectsCount++;
|
||||||
|
var objHeader = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId), default);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB
|
||||||
|
[InlineData(6 * 1024 * 1024 + 100)]
|
||||||
|
public async void SimpleScenarioTest(int objectSize)
|
||||||
|
{
|
||||||
|
bool callbackInvoked = false;
|
||||||
|
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
options.Callback = new((cs) =>
|
||||||
|
{
|
||||||
|
callbackInvoked = true;
|
||||||
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.Zero);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
|
var createdContainer = await pool.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
|
var container = await pool.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
|
Assert.NotNull(container);
|
||||||
|
Assert.True(callbackInvoked);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: createdContainer,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
bool hasObject = false;
|
||||||
|
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(createdContainer, null, [], filter), default))
|
||||||
|
{
|
||||||
|
hasObject = true;
|
||||||
|
|
||||||
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId), default);
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
Assert.NotNull(objHeader.Attributes);
|
||||||
|
Assert.Single(objHeader.Attributes!);
|
||||||
|
Assert.Equal("fileName", objHeader.Attributes!.First().Key);
|
||||||
|
Assert.Equal("test", objHeader.Attributes!.First().Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(hasObject);
|
||||||
|
|
||||||
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(createdContainer, objectId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
await foreach (var _ in pool.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB
|
||||||
|
[InlineData(6 * 1024 * 1024 + 100)]
|
||||||
|
public async void SimpleScenarioWithSessionTest(int objectSize)
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
options.Callback = new((cs) => Assert.True(cs.ElapsedMicroSeconds > 0));
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
var token = await pool.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams);
|
||||||
|
|
||||||
|
var container = await pool.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
|
var containerInfo = await pool.GetContainerAsync(new PrmContainerGet(container), ctx);
|
||||||
|
Assert.NotNull(containerInfo);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: container,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false,
|
||||||
|
sessionToken: token);
|
||||||
|
|
||||||
|
var objectId = await pool.PutObjectAsync(param, new CallContext(TimeSpan.Zero));
|
||||||
|
|
||||||
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
bool hasObject = false;
|
||||||
|
var objs = pool.SearchObjectsAsync(new PrmObjectSearch(container, token, [], filter), default);
|
||||||
|
await foreach (var objId in objs)
|
||||||
|
{
|
||||||
|
hasObject = true;
|
||||||
|
|
||||||
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId, false, token), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
Assert.NotNull(objHeader.Attributes);
|
||||||
|
Assert.Single(objHeader.Attributes);
|
||||||
|
Assert.Equal("fileName", objHeader.Attributes.First().Key);
|
||||||
|
Assert.Equal("test", objHeader.Attributes.First().Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(hasObject);
|
||||||
|
|
||||||
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(container, objectId, token), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
await foreach (var _ in pool.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(64 * 1024 * 1024)] // exactly 1 block size - 64MB
|
||||||
|
[InlineData(64 * 1024 * 1024 - 1)]
|
||||||
|
[InlineData(64 * 1024 * 1024 + 1)]
|
||||||
|
[InlineData(2 * 64 * 1024 * 1024 + 256)]
|
||||||
|
[InlineData(200)]
|
||||||
|
public async void ClientCutScenarioTest(int objectSize)
|
||||||
|
{
|
||||||
|
var options = GetDefaultParams();
|
||||||
|
|
||||||
|
using var pool = new Pool(options);
|
||||||
|
|
||||||
|
var error = await pool.Dial(new CallContext(TimeSpan.Zero)).ConfigureAwait(true);
|
||||||
|
|
||||||
|
Assert.Null(error);
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
lightWait);
|
||||||
|
|
||||||
|
var containerId = await pool.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.FromSeconds(10));
|
||||||
|
|
||||||
|
// ctx.Interceptors.Add(new CallbackInterceptor());
|
||||||
|
|
||||||
|
var container = await pool.GetContainerAsync(new PrmContainerGet(containerId), ctx);
|
||||||
|
|
||||||
|
Assert.NotNull(container);
|
||||||
|
|
||||||
|
byte[] bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: true);
|
||||||
|
|
||||||
|
var objectId = await pool.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
bool hasObject = false;
|
||||||
|
await foreach (var objId in pool.SearchObjectsAsync(new PrmObjectSearch(containerId, null, [], filter), default))
|
||||||
|
{
|
||||||
|
hasObject = true;
|
||||||
|
|
||||||
|
var res = await pool.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader); Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
Assert.NotNull(objHeader.Attributes);
|
||||||
|
Assert.Single(objHeader.Attributes);
|
||||||
|
Assert.Equal("fileName", objHeader.Attributes[0].Key);
|
||||||
|
Assert.Equal("test", objHeader.Attributes[0].Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(hasObject);
|
||||||
|
|
||||||
|
var @object = await pool.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await CheckFilter(pool, containerId, new FilterByRootObject());
|
||||||
|
|
||||||
|
await Cleanup(pool);
|
||||||
|
|
||||||
|
await foreach (var cid in pool.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail($"Container {cid.GetValue()} exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] GetRandomBytes(int size)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
var bytes = new byte[size];
|
||||||
|
rnd.NextBytes(bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IOptions<ClientSettings> GetSingleOwnerOptions(string key, string url)
|
||||||
|
{
|
||||||
|
return Options.Create(new ClientSettings
|
||||||
|
{
|
||||||
|
Key = key,
|
||||||
|
Host = url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IOptions<ClientSettings> GetOptions(string url)
|
||||||
|
{
|
||||||
|
return Options.Create(new ClientSettings
|
||||||
|
{
|
||||||
|
Host = url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static async Task Cleanup(Pool pool)
|
||||||
|
{
|
||||||
|
await foreach (var cid in pool.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
await pool.DeleteContainerAsync(new PrmContainerDelete(cid, lightWait), default).ConfigureAwait(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
709
src/FrostFS.SDK.Tests/Smoke/SmokeClientTests.cs
Normal file
709
src/FrostFS.SDK.Tests/Smoke/SmokeClientTests.cs
Normal file
|
@ -0,0 +1,709 @@
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
using FrostFS.SDK.Client;
|
||||||
|
using FrostFS.SDK.Client.Interfaces;
|
||||||
|
using FrostFS.SDK.Cryptography;
|
||||||
|
using FrostFS.SDK.SmokeTests;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
|
[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 SmokeClientTests : SmokeTestsBase
|
||||||
|
{
|
||||||
|
private static readonly PrmWait lightWait = new(100, 1);
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void AccountTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
var result = await client.GetBalanceAsync(default);
|
||||||
|
|
||||||
|
Assert.NotNull(result);
|
||||||
|
Assert.True(result.Value == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
Assert.Equal(2, result.Version.Major);
|
||||||
|
Assert.Equal(13, result.Version.Minor);
|
||||||
|
Assert.Equal(NodeState.Online, result.State);
|
||||||
|
Assert.Equal(33, result.PublicKey.Length);
|
||||||
|
Assert.Single(result.Addresses);
|
||||||
|
Assert.Equal(9, result.Attributes.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoStatisticsTest()
|
||||||
|
{
|
||||||
|
var options = GetClientOptions(keyString, url);
|
||||||
|
|
||||||
|
var callbackContent = string.Empty;
|
||||||
|
options.Value.Callback = (cs) => callbackContent = $"{cs.MethodName} took {cs.ElapsedMicroSeconds} microseconds";
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
Assert.NotEmpty(callbackContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void GetSessionTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
var token = await client.CreateSessionAsync(new(100), default);
|
||||||
|
|
||||||
|
var ownerHash = Base58.Decode(OwnerId!.Value);
|
||||||
|
|
||||||
|
Assert.NotNull(token);
|
||||||
|
Assert.NotEqual(Guid.Empty, token.Id);
|
||||||
|
Assert.Equal(33, token.SessionKey.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void CreateObjectWithSessionToken()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["key1", "value1"]);
|
||||||
|
|
||||||
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(1024);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false,
|
||||||
|
sessionToken: token);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default).ConfigureAwait(true);
|
||||||
|
|
||||||
|
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId), default)
|
||||||
|
.ConfigureAwait(true);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk().ConfigureAwait(true)) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(client).ConfigureAwait(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void FilterTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
lightWait);
|
||||||
|
|
||||||
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var bytes = new byte[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
var ParentHeader = new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular)
|
||||||
|
{
|
||||||
|
PayloadLength = 3
|
||||||
|
};
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")],
|
||||||
|
new FrostFsSplit()),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var head = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var ecdsaKey = keyString.LoadWif();
|
||||||
|
|
||||||
|
var networkInfo = await client.GetNetmapSnapshotAsync(default);
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByContainerId(FrostFsMatchType.Equals, containerId));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByOwnerId(FrostFsMatchType.Equals, FrostFsOwner.FromKey(ecdsaKey)));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterBySplitId(FrostFsMatchType.Equals, param.Header!.Split!.SplitId));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test"));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByObjectId(FrostFsMatchType.Equals, objectId));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByVersion(FrostFsMatchType.Equals, networkInfo.NodeInfoCollection[0].Version));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByEpoch(FrostFsMatchType.Equals, networkInfo.Epoch));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByPayloadLength(FrostFsMatchType.Equals, 3));
|
||||||
|
|
||||||
|
var checkSum = CheckSum.CreateCheckSum(bytes);
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByPayloadHash(FrostFsMatchType.Equals, checkSum));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByPhysicallyStored());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task CheckFilter(IFrostFSClient client, FrostFsContainerId containerId, IObjectFilter filter)
|
||||||
|
{
|
||||||
|
var resultObjectsCount = 0;
|
||||||
|
|
||||||
|
PrmObjectSearch searchParam = new(containerId, null, [], filter);
|
||||||
|
|
||||||
|
await foreach (var objId in client.SearchObjectsAsync(searchParam, default))
|
||||||
|
{
|
||||||
|
resultObjectsCount++;
|
||||||
|
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objId), default);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(0 < resultObjectsCount, $"Filter for {filter.Key} doesn't work");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB
|
||||||
|
[InlineData(6 * 1024 * 1024 + 100)]
|
||||||
|
public async void SimpleScenarioTest(int objectSize)
|
||||||
|
{
|
||||||
|
bool callbackInvoked = false;
|
||||||
|
|
||||||
|
var options = GetClientOptions(keyString, url);
|
||||||
|
|
||||||
|
options.Value.Callback = new((cs) =>
|
||||||
|
{
|
||||||
|
callbackInvoked = true;
|
||||||
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
|
Assert.NotNull(container);
|
||||||
|
Assert.True(callbackInvoked);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: createdContainer,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var filter1 = new FilterByOwnerId(FrostFsMatchType.Equals, OwnerId!);
|
||||||
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer, null, [], filter1), default))
|
||||||
|
{
|
||||||
|
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId, false), default);
|
||||||
|
|
||||||
|
var objHeader1 = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId, true), default);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
bool hasObject = false;
|
||||||
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(createdContainer, null, [], filter), default))
|
||||||
|
{
|
||||||
|
hasObject = true;
|
||||||
|
|
||||||
|
var res = await client.GetObjectHeadAsync(new PrmObjectHeadGet(createdContainer, objectId), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
Assert.NotNull(objHeader.Attributes);
|
||||||
|
Assert.Single(objHeader.Attributes);
|
||||||
|
Assert.Equal("fileName", objHeader.Attributes.First().Key);
|
||||||
|
Assert.Equal("test", objHeader.Attributes.First().Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(hasObject);
|
||||||
|
|
||||||
|
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, objectId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void PatchTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
|
Assert.NotNull(container);
|
||||||
|
|
||||||
|
var bytes = new byte[1024];
|
||||||
|
for (int i = 0; i < 1024; i++)
|
||||||
|
{
|
||||||
|
bytes[i] = 31;
|
||||||
|
}
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: createdContainer,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var patch = new byte[16];
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
patch[i] = 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
var range = new FrostFsRange(8, (ulong)patch.Length);
|
||||||
|
|
||||||
|
var patchParams = new PrmObjectPatch(
|
||||||
|
new FrostFsAddress(createdContainer, objectId),
|
||||||
|
payload: new MemoryStream(patch),
|
||||||
|
maxChunkLength: 32,
|
||||||
|
range: range);
|
||||||
|
|
||||||
|
var newIbjId = await client.PatchObjectAsync(patchParams, default);
|
||||||
|
|
||||||
|
var @object = await client.GetObjectAsync(new PrmObjectGet(createdContainer, newIbjId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < (int)range.Offset; i++)
|
||||||
|
Assert.Equal(downloadedBytes[i], bytes[i]);
|
||||||
|
|
||||||
|
var rangeEnd = range.Offset + range.Length;
|
||||||
|
|
||||||
|
for (int i = (int)range.Offset; i < (int)rangeEnd; i++)
|
||||||
|
Assert.Equal(downloadedBytes[i], patch[i - (int)range.Offset]);
|
||||||
|
|
||||||
|
for (int i = (int)rangeEnd; i < bytes.Length; i++)
|
||||||
|
Assert.Equal(downloadedBytes[i], bytes[i]);
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void RangeTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
|
Assert.NotNull(container);
|
||||||
|
|
||||||
|
var bytes = new byte[256];
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
bytes[i] = (byte)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: createdContainer,
|
||||||
|
type: FrostFsObjectType.Regular),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var rangeParam = new PrmRangeGet(createdContainer, objectId, new FrostFsRange(100, 64));
|
||||||
|
|
||||||
|
var rangeReader = await client.GetRangeAsync(rangeParam, default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[rangeParam.Range.Length];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await rangeReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes.AsSpan().Slice(100, 64)), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void RangeHashTest()
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams,
|
||||||
|
xheaders: ["testKey", "testValue"]);
|
||||||
|
|
||||||
|
var createdContainer = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var container = await client.GetContainerAsync(new PrmContainerGet(createdContainer), default);
|
||||||
|
Assert.NotNull(container);
|
||||||
|
|
||||||
|
var bytes = new byte[256];
|
||||||
|
for (int i = 0; i < 256; i++)
|
||||||
|
{
|
||||||
|
bytes[i] = (byte)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: createdContainer,
|
||||||
|
type: FrostFsObjectType.Regular),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var rangeParam = new PrmRangeHashGet(createdContainer, objectId, [new FrostFsRange(100, 64)], bytes);
|
||||||
|
|
||||||
|
var hashes = await client.GetRangeHashAsync(rangeParam, default);
|
||||||
|
|
||||||
|
foreach (var hash in hashes)
|
||||||
|
{
|
||||||
|
var x = hash[..32].ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB
|
||||||
|
[InlineData(6 * 1024 * 1024 + 100)]
|
||||||
|
public async void SimpleScenarioWithSessionTest(int objectSize)
|
||||||
|
{
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
//Callback = new((CallStatistics cs) => Assert.True(cs.ElapsedMicroSeconds > 0))
|
||||||
|
var token = await client.CreateSessionAsync(new PrmSessionCreate(int.MaxValue), default);
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.FromSeconds(20));
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
PrmWait.DefaultParams);
|
||||||
|
|
||||||
|
var container = await client.CreateContainerAsync(createContainerParam, ctx);
|
||||||
|
|
||||||
|
var containerInfo = await client.GetContainerAsync(new PrmContainerGet(container), ctx);
|
||||||
|
Assert.NotNull(containerInfo);
|
||||||
|
|
||||||
|
var bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: container,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: false,
|
||||||
|
sessionToken: token);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
bool hasObject = false;
|
||||||
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(container, token, [], filter), default))
|
||||||
|
{
|
||||||
|
hasObject = true;
|
||||||
|
|
||||||
|
var res = await client.GetObjectHeadAsync(new PrmObjectHeadGet(container, objectId, false, token), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
|
Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
Assert.NotNull(objHeader.Attributes);
|
||||||
|
Assert.Single(objHeader.Attributes);
|
||||||
|
Assert.Equal("fileName", objHeader.Attributes.First().Key);
|
||||||
|
Assert.Equal("test", objHeader.Attributes.First().Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.True(hasObject);
|
||||||
|
|
||||||
|
var @object = await client.GetObjectAsync(new PrmObjectGet(container, objectId, token), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
await foreach (var _ in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData(1)]
|
||||||
|
[InlineData(64 * 1024 * 1024)] // exactly 1 block size - 64MB
|
||||||
|
[InlineData(64 * 1024 * 1024 - 1)]
|
||||||
|
[InlineData(64 * 1024 * 1024 + 1)]
|
||||||
|
[InlineData(2 * 64 * 1024 * 1024 + 256)]
|
||||||
|
[InlineData(200)]
|
||||||
|
public async void ClientCutScenarioTest(int objectSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
var options = GetClientOptions(keyString, url);
|
||||||
|
options.Value.Interceptors.Add(new CallbackInterceptor());
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(GetClientOptions(keyString, url));
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var createContainerParam = new PrmContainerCreate(
|
||||||
|
new FrostFsContainerInfo(new FrostFsPlacementPolicy(true, new FrostFsReplica(1))),
|
||||||
|
lightWait);
|
||||||
|
|
||||||
|
var containerId = await client.CreateContainerAsync(createContainerParam, default);
|
||||||
|
|
||||||
|
var ctx = new CallContext(TimeSpan.FromSeconds(10));
|
||||||
|
|
||||||
|
var container = await client.GetContainerAsync(new PrmContainerGet(containerId), ctx);
|
||||||
|
|
||||||
|
Assert.NotNull(container);
|
||||||
|
|
||||||
|
byte[] bytes = GetRandomBytes(objectSize);
|
||||||
|
|
||||||
|
var param = new PrmObjectPut(
|
||||||
|
new FrostFsObjectHeader(
|
||||||
|
containerId: containerId,
|
||||||
|
type: FrostFsObjectType.Regular,
|
||||||
|
[new FrostFsAttributePair("fileName", "test")]),
|
||||||
|
payload: new MemoryStream(bytes),
|
||||||
|
clientCut: true);
|
||||||
|
|
||||||
|
var objectId = await client.PutObjectAsync(param, default);
|
||||||
|
|
||||||
|
// var filter = new FilterByAttributePair(FrostFsMatchType.Equals, "fileName", "test");
|
||||||
|
|
||||||
|
//bool hasObject = false;
|
||||||
|
//await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, null, [], filter), default))
|
||||||
|
//{
|
||||||
|
// hasObject = true;
|
||||||
|
|
||||||
|
// var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId), default);
|
||||||
|
// Assert.Equal((ulong)bytes.Length, objHeader.PayloadLength);
|
||||||
|
// Assert.NotNull(objHeader.Attributes);
|
||||||
|
// Assert.Single(objHeader.Attributes);
|
||||||
|
// Assert.Equal("fileName", objHeader.Attributes[0].Key);
|
||||||
|
// Assert.Equal("test", objHeader.Attributes[0].Value);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//Assert.True(hasObject);
|
||||||
|
|
||||||
|
|
||||||
|
var filter1 = new FilterByOwnerId(FrostFsMatchType.Equals, OwnerId!);
|
||||||
|
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, null, [], filter1), default))
|
||||||
|
{
|
||||||
|
var objHeader = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId, false), default);
|
||||||
|
|
||||||
|
var objHeader1 = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId, true), default);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var @object = await client.GetObjectAsync(new PrmObjectGet(containerId, objectId), default);
|
||||||
|
|
||||||
|
var downloadedBytes = new byte[@object.Header.PayloadLength];
|
||||||
|
MemoryStream ms = new(downloadedBytes);
|
||||||
|
|
||||||
|
ReadOnlyMemory<byte>? chunk = null;
|
||||||
|
while ((chunk = await @object.ObjectReader!.ReadChunk()) != null)
|
||||||
|
{
|
||||||
|
ms.Write(chunk.Value.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Equal(SHA256.HashData(bytes), SHA256.HashData(downloadedBytes));
|
||||||
|
|
||||||
|
await CheckFilter(client, containerId, new FilterByRootObject());
|
||||||
|
|
||||||
|
await Cleanup(client);
|
||||||
|
|
||||||
|
var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
|
IAsyncEnumerator<FrostFsContainerId>? enumerator = null;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (deadline <= DateTime.UtcNow)
|
||||||
|
{
|
||||||
|
Assert.Fail("Containers exist");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
enumerator = client.ListContainersAsync(default, default).GetAsyncEnumerator();
|
||||||
|
await Task.Delay(500);
|
||||||
|
}
|
||||||
|
while (await enumerator!.MoveNextAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async void NodeInfoCallbackAndInterceptorTest()
|
||||||
|
{
|
||||||
|
bool callbackInvoked = false;
|
||||||
|
bool intercepterInvoked = false;
|
||||||
|
|
||||||
|
var options = GetClientOptions(keyString, url);
|
||||||
|
options.Value.Callback = (cs) =>
|
||||||
|
{
|
||||||
|
callbackInvoked = true;
|
||||||
|
Assert.True(cs.ElapsedMicroSeconds > 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Value.Interceptors.Add(new CallbackInterceptor(s => intercepterInvoked = true));
|
||||||
|
|
||||||
|
using var client = FrostFSClient.GetInstance(options);
|
||||||
|
|
||||||
|
var result = await client.GetNodeInfoAsync(default);
|
||||||
|
|
||||||
|
Assert.True(callbackInvoked);
|
||||||
|
Assert.True(intercepterInvoked);
|
||||||
|
|
||||||
|
Assert.Equal(2, result.Version.Major);
|
||||||
|
Assert.Equal(13, result.Version.Minor);
|
||||||
|
Assert.Equal(NodeState.Online, result.State);
|
||||||
|
Assert.Equal(33, result.PublicKey.Length);
|
||||||
|
Assert.Single(result.Addresses);
|
||||||
|
Assert.Equal(9, result.Attributes.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static byte[] GetRandomBytes(int size)
|
||||||
|
{
|
||||||
|
Random rnd = new();
|
||||||
|
var bytes = new byte[size];
|
||||||
|
rnd.NextBytes(bytes);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IOptions<ClientSettings> GetClientOptions(string key, string url)
|
||||||
|
{
|
||||||
|
return Options.Create(new ClientSettings
|
||||||
|
{
|
||||||
|
Key = key,
|
||||||
|
Host = url
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static async Task Cleanup(IFrostFSClient client)
|
||||||
|
{
|
||||||
|
await foreach (var cid in client.ListContainersAsync(default, default))
|
||||||
|
{
|
||||||
|
await client.DeleteContainerAsync(new PrmContainerDelete(cid, lightWait), default);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
using FrostFS.SDK.Client;
|
using FrostFS.SDK.Client;
|
||||||
using FrostFS.SDK.Cryptography;
|
using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
namespace FrostFS.SDK.SmokeTests;
|
namespace FrostFS.SDK.Tests.Smoke;
|
||||||
|
|
||||||
public abstract class SmokeTestsBase
|
public abstract class SmokeTestsBase
|
||||||
{
|
{
|
|
@ -6,7 +6,7 @@ using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
||||||
public class ContainerTest : ContainerTestsBase
|
public class ContainerTest : ContainerTestsBase
|
||||||
|
@ -14,9 +14,9 @@ public class ContainerTest : ContainerTestsBase
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void CreateContainerTest()
|
public async void CreateContainerTest()
|
||||||
{
|
{
|
||||||
var param = new PrmContainerCreate(new FrostFsContainerInfo(Mocker.PlacementPolicy));
|
var param = new PrmContainerCreate(new FrostFsContainerInfo(Mocker.PlacementPolicy), PrmWait.DefaultParams);
|
||||||
|
|
||||||
var result = await GetClient().CreateContainerAsync(param);
|
var result = await GetClient().CreateContainerAsync(param, default);
|
||||||
|
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.NotNull(result.GetValue());
|
Assert.NotNull(result.GetValue());
|
||||||
|
@ -28,7 +28,7 @@ public class ContainerTest : ContainerTestsBase
|
||||||
{
|
{
|
||||||
var cid = new FrostFsContainerId(Base58.Encode(Mocker.ContainerGuid.ToBytes()));
|
var cid = new FrostFsContainerId(Base58.Encode(Mocker.ContainerGuid.ToBytes()));
|
||||||
|
|
||||||
var result = await GetClient().GetContainerAsync(new PrmContainerGet(cid));
|
var result = await GetClient().GetContainerAsync(new PrmContainerGet(cid), default);
|
||||||
|
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Equal(Mocker.ContainerGuid, result.Nonce);
|
Assert.Equal(Mocker.ContainerGuid, result.Nonce);
|
||||||
|
@ -43,7 +43,7 @@ public class ContainerTest : ContainerTestsBase
|
||||||
Mocker.ContainerIds.Add([0xbb]);
|
Mocker.ContainerIds.Add([0xbb]);
|
||||||
Mocker.ContainerIds.Add([0xcc]);
|
Mocker.ContainerIds.Add([0xcc]);
|
||||||
|
|
||||||
var result = GetClient().ListContainersAsync();
|
var result = GetClient().ListContainersAsync(default, default);
|
||||||
|
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ public class ContainerTest : ContainerTestsBase
|
||||||
Mocker.ReturnContainerRemoved = true;
|
Mocker.ReturnContainerRemoved = true;
|
||||||
var cid = new FrostFsContainerId(Base58.Encode(Mocker.ContainerGuid.ToBytes()));
|
var cid = new FrostFsContainerId(Base58.Encode(Mocker.ContainerGuid.ToBytes()));
|
||||||
|
|
||||||
await GetClient().DeleteContainerAsync(new PrmContainerDelete(cid));
|
await GetClient().DeleteContainerAsync(new PrmContainerDelete(cid, PrmWait.DefaultParams), default);
|
||||||
|
|
||||||
Assert.Single(Mocker.Requests);
|
Assert.Single(Mocker.Requests);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
public abstract class ContainerTestsBase
|
public abstract class ContainerTestsBase
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ public abstract class ContainerTestsBase
|
||||||
Host = "http://localhost:8080"
|
Host = "http://localhost:8080"
|
||||||
});
|
});
|
||||||
|
|
||||||
Mocker = new ContainerMocker(this.key)
|
Mocker = new ContainerMocker(key)
|
||||||
{
|
{
|
||||||
PlacementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)),
|
PlacementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)),
|
||||||
Version = new FrostFsVersion(2, 13),
|
Version = new FrostFsVersion(2, 13),
|
||||||
|
@ -32,9 +32,9 @@ public abstract class ContainerTestsBase
|
||||||
return Client.FrostFSClient.GetTestInstance(
|
return Client.FrostFSClient.GetTestInstance(
|
||||||
Settings,
|
Settings,
|
||||||
null,
|
null,
|
||||||
new NetworkMocker(this.key).GetMock().Object,
|
new NetworkMocker(key).GetMock().Object,
|
||||||
new SessionMocker(this.key).GetMock().Object,
|
new SessionMocker(key).GetMock().Object,
|
||||||
Mocker.GetMock().Object,
|
Mocker.GetMock().Object,
|
||||||
new ObjectMocker(this.key).GetMock().Object);
|
new ObjectMocker(key).GetMock().Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ using FrostFS.SDK.Client;
|
||||||
|
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
||||||
public class NetworkTest : NetworkTestsBase
|
public class NetworkTest : NetworkTestsBase
|
||||||
|
@ -28,17 +28,13 @@ public class NetworkTest : NetworkTestsBase
|
||||||
Mocker.Parameters.Add("HomomorphicHashingDisabled", [1]);
|
Mocker.Parameters.Add("HomomorphicHashingDisabled", [1]);
|
||||||
Mocker.Parameters.Add("MaintenanceModeAllowed", [1]);
|
Mocker.Parameters.Add("MaintenanceModeAllowed", [1]);
|
||||||
|
|
||||||
var param = useContext ?
|
var ctx = useContext
|
||||||
new PrmNetworkSettings(new CallContext
|
? new CallContext(TimeSpan.FromSeconds(20), Mocker.CancellationTokenSource.Token)
|
||||||
{
|
: default;
|
||||||
CancellationToken = Mocker.CancellationTokenSource.Token,
|
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
})
|
|
||||||
: new PrmNetworkSettings();
|
|
||||||
|
|
||||||
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
var result = await GetClient(DefaultSettings).GetNetworkSettingsAsync(param);
|
var result = await GetClient(DefaultSettings).GetNetworkSettingsAsync(ctx);
|
||||||
|
|
||||||
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
|
@ -110,28 +106,13 @@ public class NetworkTest : NetworkTestsBase
|
||||||
|
|
||||||
Mocker.NetmapSnapshotResponse = new NetmapSnapshotResponse { Body = body };
|
Mocker.NetmapSnapshotResponse = new NetmapSnapshotResponse { Body = body };
|
||||||
|
|
||||||
PrmNetmapSnapshot param = new();
|
var ctx = useContext
|
||||||
|
? new CallContext(TimeSpan.FromSeconds(20), Mocker.CancellationTokenSource.Token)
|
||||||
if (useContext)
|
: default;
|
||||||
{
|
|
||||||
var ctx = new CallContext
|
|
||||||
{
|
|
||||||
CancellationToken = Mocker.CancellationTokenSource.Token,
|
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
};
|
|
||||||
|
|
||||||
param = new(ctx);
|
|
||||||
param.XHeaders.Add("headerKey1", "headerValue1");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
param = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
var result = await GetClient(DefaultSettings).GetNetmapSnapshotAsync(param);
|
var result = await GetClient(DefaultSettings).GetNetmapSnapshotAsync(ctx);
|
||||||
|
|
||||||
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
|
@ -166,13 +147,10 @@ public class NetworkTest : NetworkTestsBase
|
||||||
if (useContext)
|
if (useContext)
|
||||||
{
|
{
|
||||||
Assert.NotNull(Mocker.NetmapSnapshotRequest);
|
Assert.NotNull(Mocker.NetmapSnapshotRequest);
|
||||||
Assert.Single(Mocker.NetmapSnapshotRequest.MetaHeader.XHeaders);
|
Assert.Empty(Mocker.NetmapSnapshotRequest.MetaHeader.XHeaders);
|
||||||
Assert.Equal(param.XHeaders.Keys[0], Mocker.NetmapSnapshotRequest.MetaHeader.XHeaders.First().Key);
|
|
||||||
Assert.Equal(param.XHeaders[param.XHeaders.Keys[0]], Mocker.NetmapSnapshotRequest.MetaHeader.XHeaders.First().Value);
|
|
||||||
|
|
||||||
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
||||||
Assert.NotNull(Mocker.DateTime);
|
Assert.NotNull(Mocker.DateTime);
|
||||||
|
|
||||||
Assert.True(Mocker.DateTime.Value >= validTimeoutFrom);
|
Assert.True(Mocker.DateTime.Value >= validTimeoutFrom);
|
||||||
Assert.True(Mocker.DateTime.Value <= validTimeoutTo);
|
Assert.True(Mocker.DateTime.Value <= validTimeoutTo);
|
||||||
}
|
}
|
||||||
|
@ -206,28 +184,13 @@ public class NetworkTest : NetworkTestsBase
|
||||||
|
|
||||||
Mocker.NodeInfoResponse = new LocalNodeInfoResponse { Body = body };
|
Mocker.NodeInfoResponse = new LocalNodeInfoResponse { Body = body };
|
||||||
|
|
||||||
PrmNodeInfo param;
|
var ctx = useContext
|
||||||
|
? new CallContext(TimeSpan.FromSeconds(20), Mocker.CancellationTokenSource.Token)
|
||||||
if (useContext)
|
: default;
|
||||||
{
|
|
||||||
var ctx = new CallContext
|
|
||||||
{
|
|
||||||
CancellationToken = Mocker.CancellationTokenSource.Token,
|
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
};
|
|
||||||
|
|
||||||
param = new(ctx);
|
|
||||||
param.XHeaders.Add("headerKey1", "headerValue1");
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
param = new();
|
|
||||||
}
|
|
||||||
|
|
||||||
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
var result = await GetClient(DefaultSettings).GetNodeInfoAsync(param);
|
var result = await GetClient(DefaultSettings).GetNodeInfoAsync(ctx);
|
||||||
|
|
||||||
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
|
@ -246,10 +209,7 @@ public class NetworkTest : NetworkTestsBase
|
||||||
Assert.NotNull(Mocker.LocalNodeInfoRequest);
|
Assert.NotNull(Mocker.LocalNodeInfoRequest);
|
||||||
if (useContext)
|
if (useContext)
|
||||||
{
|
{
|
||||||
Assert.Single(Mocker.LocalNodeInfoRequest.MetaHeader.XHeaders);
|
Assert.Empty(Mocker.LocalNodeInfoRequest.MetaHeader.XHeaders);
|
||||||
Assert.Equal(param.XHeaders.Keys[0], Mocker.LocalNodeInfoRequest.MetaHeader.XHeaders.First().Key);
|
|
||||||
Assert.Equal(param.XHeaders[param.XHeaders.Keys[0]], Mocker.LocalNodeInfoRequest.MetaHeader.XHeaders.First().Value);
|
|
||||||
|
|
||||||
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
||||||
Assert.NotNull(Mocker.DateTime);
|
Assert.NotNull(Mocker.DateTime);
|
||||||
|
|
|
@ -4,7 +4,7 @@ using FrostFS.SDK.Client.Interfaces;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
||||||
public abstract class NetworkTestsBase
|
public abstract class NetworkTestsBase
|
||||||
|
@ -25,7 +25,7 @@ public abstract class NetworkTestsBase
|
||||||
Host = "http://localhost:8080",
|
Host = "http://localhost:8080",
|
||||||
};
|
};
|
||||||
|
|
||||||
Mocker = new NetworkMocker(this.key);
|
Mocker = new NetworkMocker(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IFrostFSClient GetClient(ClientSettings settings)
|
protected IFrostFSClient GetClient(ClientSettings settings)
|
||||||
|
@ -34,8 +34,8 @@ public abstract class NetworkTestsBase
|
||||||
Options.Create(settings),
|
Options.Create(settings),
|
||||||
null,
|
null,
|
||||||
Mocker.GetMock().Object,
|
Mocker.GetMock().Object,
|
||||||
new SessionMocker(this.key).GetMock().Object,
|
new SessionMocker(key).GetMock().Object,
|
||||||
new ContainerMocker(this.key).GetMock().Object,
|
new ContainerMocker(key).GetMock().Object,
|
||||||
new ObjectMocker(this.key).GetMock().Object);
|
new ObjectMocker(key).GetMock().Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -9,34 +9,12 @@ using FrostFS.SDK.Client.Mappers.GRPC;
|
||||||
|
|
||||||
using Google.Protobuf;
|
using Google.Protobuf;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[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")]
|
[SuppressMessage("Security", "CA5394:Do not use insecure randomness", Justification = "No secure purpose")]
|
||||||
public class ObjectTest : ObjectTestsBase
|
public class ObjectTest : ObjectTestsBase
|
||||||
{
|
{
|
||||||
[Fact]
|
|
||||||
public async void GetObjectTest()
|
|
||||||
{
|
|
||||||
var client = GetClient();
|
|
||||||
|
|
||||||
var objectId = client.CalculateObjectId(Mocker.ObjectHeader!);
|
|
||||||
|
|
||||||
var result = await client.GetObjectAsync(new PrmObjectGet(ContainerId, objectId));
|
|
||||||
|
|
||||||
Assert.NotNull(result);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async void PutObjectTest()
|
public async void PutObjectTest()
|
||||||
{
|
{
|
||||||
|
@ -46,14 +24,12 @@ public class ObjectTest : ObjectTestsBase
|
||||||
var bytes = new byte[1024];
|
var bytes = new byte[1024];
|
||||||
rnd.NextBytes(bytes);
|
rnd.NextBytes(bytes);
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
Mocker.ObjectHeader,
|
||||||
Header = Mocker.ObjectHeader,
|
payload: new MemoryStream(bytes),
|
||||||
Payload = new MemoryStream(bytes),
|
clientCut: false);
|
||||||
ClientCut = false
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = await GetClient().PutObjectAsync(param);
|
var result = await GetClient().PutObjectAsync(param, default);
|
||||||
|
|
||||||
var sentMessages = Mocker.ClientStreamWriter!.Messages;
|
var sentMessages = Mocker.ClientStreamWriter!.Messages;
|
||||||
|
|
||||||
|
@ -81,13 +57,11 @@ public class ObjectTest : ObjectTestsBase
|
||||||
byte[] bytes = File.ReadAllBytes(@".\..\..\..\cat.jpg");
|
byte[] bytes = File.ReadAllBytes(@".\..\..\..\cat.jpg");
|
||||||
var fileLength = bytes.Length;
|
var fileLength = bytes.Length;
|
||||||
|
|
||||||
var param = new PrmObjectPut
|
var param = new PrmObjectPut(
|
||||||
{
|
Mocker.ObjectHeader,
|
||||||
Header = Mocker.ObjectHeader,
|
payload: new MemoryStream(bytes),
|
||||||
Payload = new MemoryStream(bytes),
|
bufferMaxSize: 1024,
|
||||||
BufferMaxSize = 1024,
|
clientCut: true);
|
||||||
ClientCut = true
|
|
||||||
};
|
|
||||||
|
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
|
|
||||||
|
@ -99,7 +73,7 @@ public class ObjectTest : ObjectTestsBase
|
||||||
foreach (var objId in objIds)
|
foreach (var objId in objIds)
|
||||||
Mocker.ResultObjectIds!.Add(objId);
|
Mocker.ResultObjectIds!.Add(objId);
|
||||||
|
|
||||||
var result = await GetClient().PutObjectAsync(param);
|
var result = await GetClient().PutObjectAsync(param, default);
|
||||||
|
|
||||||
var singleObjects = Mocker.PutSingleRequests.ToArray();
|
var singleObjects = Mocker.PutSingleRequests.ToArray();
|
||||||
|
|
||||||
|
@ -151,7 +125,7 @@ public class ObjectTest : ObjectTestsBase
|
||||||
Assert.NotNull(header3.Split.ParentHeader);
|
Assert.NotNull(header3.Split.ParentHeader);
|
||||||
Assert.NotNull(header3.Split.ParentSignature);
|
Assert.NotNull(header3.Split.ParentSignature);
|
||||||
Assert.Equal(header2.Split.SplitId, header3.Split.SplitId);
|
Assert.Equal(header2.Split.SplitId, header3.Split.SplitId);
|
||||||
Assert.Equal(bytes[((fileLength / blockSize) * blockSize)..fileLength], payload3);
|
Assert.Equal(bytes[(fileLength / blockSize * blockSize)..fileLength], payload3);
|
||||||
Assert.True(header3.Attributes.Count == 0);
|
Assert.True(header3.Attributes.Count == 0);
|
||||||
|
|
||||||
//link object
|
//link object
|
||||||
|
@ -175,7 +149,7 @@ public class ObjectTest : ObjectTestsBase
|
||||||
{
|
{
|
||||||
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
|
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
|
||||||
|
|
||||||
await GetClient().DeleteObjectAsync(new PrmObjectDelete(ContainerId, Mocker.ObjectId));
|
await GetClient().DeleteObjectAsync(new PrmObjectDelete(ContainerId, Mocker.ObjectId), default);
|
||||||
|
|
||||||
var request = Mocker.DeleteRequests.FirstOrDefault();
|
var request = Mocker.DeleteRequests.FirstOrDefault();
|
||||||
Assert.NotNull(request);
|
Assert.NotNull(request);
|
||||||
|
@ -188,30 +162,33 @@ public class ObjectTest : ObjectTestsBase
|
||||||
{
|
{
|
||||||
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
|
Mocker.ObjectId = new ObjectID { Value = ByteString.CopyFrom(SHA256.HashData(Encoding.UTF8.GetBytes("test"))) }.ToModel();
|
||||||
|
|
||||||
var response = await GetClient().GetObjectHeadAsync(new PrmObjectHeadGet(ContainerId, Mocker.ObjectId));
|
var res = await GetClient().GetObjectHeadAsync(new PrmObjectHeadGet(ContainerId, Mocker.ObjectId), default);
|
||||||
|
|
||||||
|
var objHeader = res.HeaderInfo;
|
||||||
|
Assert.NotNull(objHeader);
|
||||||
|
|
||||||
var request = Mocker.HeadRequests.FirstOrDefault();
|
var request = Mocker.HeadRequests.FirstOrDefault();
|
||||||
Assert.NotNull(request);
|
Assert.NotNull(request);
|
||||||
Assert.Equal(ContainerId.ToMessage(), request.Body.Address.ContainerId);
|
Assert.Equal(ContainerId.ToMessage(), request.Body.Address.ContainerId);
|
||||||
Assert.Equal(Mocker.ObjectId.ToMessage(), request.Body.Address.ObjectId);
|
Assert.Equal(Mocker.ObjectId.ToMessage(), request.Body.Address.ObjectId);
|
||||||
|
|
||||||
Assert.NotNull(response);
|
Assert.NotNull(objHeader);
|
||||||
Assert.Equal(ContainerId.GetValue(), response.ContainerId.GetValue());
|
Assert.Equal(ContainerId.GetValue(), objHeader.ContainerId.GetValue());
|
||||||
|
|
||||||
Assert.Equal(Mocker.ObjectHeader!.OwnerId!.Value, response.OwnerId!.Value);
|
Assert.Equal(Mocker.ObjectHeader!.OwnerId!.Value, objHeader.OwnerId!.Value);
|
||||||
Assert.Equal(Mocker.ObjectHeader!.Version!.ToString(), response.Version!.ToString());
|
Assert.Equal(Mocker.ObjectHeader!.Version!.ToString(), objHeader.Version!.ToString());
|
||||||
|
|
||||||
Assert.Equal(Mocker.HeadResponse!.PayloadLength, response.PayloadLength);
|
Assert.Equal(Mocker.HeadResponse!.PayloadLength, objHeader.PayloadLength);
|
||||||
|
|
||||||
Assert.Equal(FrostFsObjectType.Regular, response.ObjectType);
|
Assert.Equal(FrostFsObjectType.Regular, objHeader.ObjectType);
|
||||||
|
|
||||||
Assert.NotNull(response.Attributes);
|
Assert.NotNull(objHeader.Attributes);
|
||||||
Assert.Single(response.Attributes);
|
Assert.Single(objHeader.Attributes);
|
||||||
|
|
||||||
Assert.Equal(Mocker.HeadResponse.Attributes[0].Key, response.Attributes.First().Key);
|
Assert.Equal(Mocker.HeadResponse.Attributes[0].Key, objHeader.Attributes.First().Key);
|
||||||
Assert.Equal(Mocker.HeadResponse.Attributes[0].Value, response.Attributes.First().Value);
|
Assert.Equal(Mocker.HeadResponse.Attributes[0].Value, objHeader.Attributes.First().Value);
|
||||||
|
|
||||||
Assert.Null(response.Split);
|
Assert.Null(objHeader.Split);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
@ -229,7 +206,7 @@ public class ObjectTest : ObjectTestsBase
|
||||||
|
|
||||||
var param = new PrmRangeGet(ContainerId, Mocker.ObjectId, new FrostFsRange(100, (ulong)Mocker.RangeResponse.Length));
|
var param = new PrmRangeGet(ContainerId, Mocker.ObjectId, new FrostFsRange(100, (ulong)Mocker.RangeResponse.Length));
|
||||||
|
|
||||||
var result = await GetClient().GetRangeAsync(param);
|
var result = await GetClient().GetRangeAsync(param, default);
|
||||||
|
|
||||||
Assert.NotNull(Mocker.GetRangeRequest);
|
Assert.NotNull(Mocker.GetRangeRequest);
|
||||||
|
|
||||||
|
@ -271,7 +248,7 @@ public class ObjectTest : ObjectTestsBase
|
||||||
|
|
||||||
var param = new PrmRangeHashGet(ContainerId, Mocker.ObjectId, [new FrostFsRange(100, len)], salt);
|
var param = new PrmRangeHashGet(ContainerId, Mocker.ObjectId, [new FrostFsRange(100, len)], salt);
|
||||||
|
|
||||||
var result = await GetClient().GetRangeHashAsync(param);
|
var result = await GetClient().GetRangeHashAsync(param, default);
|
||||||
|
|
||||||
Assert.NotNull(Mocker.GetRangeHashRequest);
|
Assert.NotNull(Mocker.GetRangeHashRequest);
|
||||||
|
|
||||||
|
@ -299,14 +276,13 @@ public class ObjectTest : ObjectTestsBase
|
||||||
|
|
||||||
var range = new FrostFsRange(8, (ulong)patch.Length);
|
var range = new FrostFsRange(8, (ulong)patch.Length);
|
||||||
|
|
||||||
var param = new PrmObjectPatch(address)
|
var param = new PrmObjectPatch(
|
||||||
{
|
address,
|
||||||
Payload = new MemoryStream(patch),
|
payload: new MemoryStream(patch),
|
||||||
MaxPayloadPatchChunkLength = 32,
|
maxChunkLength: 32,
|
||||||
Range = range
|
range: range);
|
||||||
};
|
|
||||||
|
|
||||||
var result = await GetClient().PatchObjectAsync(param);
|
var result = await GetClient().PatchObjectAsync(param, default);
|
||||||
|
|
||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
|
|
|
@ -4,7 +4,7 @@ using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
public abstract class ObjectTestsBase
|
public abstract class ObjectTestsBase
|
||||||
{
|
{
|
|
@ -4,7 +4,7 @@ using FrostFS.SDK.Client;
|
||||||
using FrostFS.SDK.Client.Mappers.GRPC;
|
using FrostFS.SDK.Client.Mappers.GRPC;
|
||||||
using FrostFS.SDK.Cryptography;
|
using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
||||||
public class SessionTest : SessionTestsBase
|
public class SessionTest : SessionTestsBase
|
||||||
|
@ -17,26 +17,21 @@ public class SessionTest : SessionTestsBase
|
||||||
var exp = 100u;
|
var exp = 100u;
|
||||||
PrmSessionCreate param;
|
PrmSessionCreate param;
|
||||||
|
|
||||||
|
CallContext ctx;
|
||||||
if (useContext)
|
if (useContext)
|
||||||
{
|
{
|
||||||
var ctx = new CallContext
|
ctx = new CallContext(TimeSpan.FromSeconds(20), Mocker.CancellationTokenSource.Token);
|
||||||
{
|
param = new PrmSessionCreate(exp, ["headerKey1", "headerValue1"]);
|
||||||
CancellationToken = Mocker.CancellationTokenSource.Token,
|
|
||||||
Timeout = TimeSpan.FromSeconds(20)
|
|
||||||
};
|
|
||||||
|
|
||||||
param = new PrmSessionCreate(exp, ctx);
|
|
||||||
|
|
||||||
param.XHeaders.Add("headerKey1", "headerValue1");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ctx = default;
|
||||||
param = new PrmSessionCreate(exp);
|
param = new PrmSessionCreate(exp);
|
||||||
}
|
}
|
||||||
|
|
||||||
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
var result = await GetClient().CreateSessionAsync(param);
|
var result = await GetClient().CreateSessionAsync(param, ctx);
|
||||||
|
|
||||||
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
||||||
|
|
||||||
|
@ -64,8 +59,8 @@ public class SessionTest : SessionTestsBase
|
||||||
if (useContext)
|
if (useContext)
|
||||||
{
|
{
|
||||||
Assert.Single(Mocker.CreateSessionRequest.MetaHeader.XHeaders);
|
Assert.Single(Mocker.CreateSessionRequest.MetaHeader.XHeaders);
|
||||||
Assert.Equal(param.XHeaders.Keys[0], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Key);
|
Assert.Equal(param.XHeaders[0], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Key);
|
||||||
Assert.Equal(param.XHeaders[param.XHeaders.Keys[0]], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Value);
|
Assert.Equal(param.XHeaders[1], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Value);
|
||||||
|
|
||||||
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
||||||
Assert.NotNull(Mocker.DateTime);
|
Assert.NotNull(Mocker.DateTime);
|
|
@ -5,7 +5,7 @@ using FrostFS.SDK.Cryptography;
|
||||||
|
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
namespace FrostFS.SDK.Tests;
|
namespace FrostFS.SDK.Tests.Unit;
|
||||||
|
|
||||||
public abstract class SessionTestsBase
|
public abstract class SessionTestsBase
|
||||||
{
|
{
|
||||||
|
@ -28,7 +28,7 @@ public abstract class SessionTestsBase
|
||||||
ECDsaKey = key.LoadWif();
|
ECDsaKey = key.LoadWif();
|
||||||
OwnerId = FrostFsOwner.FromKey(ECDsaKey);
|
OwnerId = FrostFsOwner.FromKey(ECDsaKey);
|
||||||
|
|
||||||
Mocker = new SessionMocker(this.key)
|
Mocker = new SessionMocker(key)
|
||||||
{
|
{
|
||||||
PlacementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)),
|
PlacementPolicy = new FrostFsPlacementPolicy(true, new FrostFsReplica(1)),
|
||||||
Version = new FrostFsVersion(2, 13)
|
Version = new FrostFsVersion(2, 13)
|
||||||
|
@ -40,9 +40,9 @@ public abstract class SessionTestsBase
|
||||||
return Client.FrostFSClient.GetTestInstance(
|
return Client.FrostFSClient.GetTestInstance(
|
||||||
Settings,
|
Settings,
|
||||||
null,
|
null,
|
||||||
new NetworkMocker(this.key).GetMock().Object,
|
new NetworkMocker(key).GetMock().Object,
|
||||||
Mocker.GetMock().Object,
|
Mocker.GetMock().Object,
|
||||||
new ContainerMocker(this.key).GetMock().Object,
|
new ContainerMocker(key).GetMock().Object,
|
||||||
new ObjectMocker(this.key).GetMock().Object);
|
new ObjectMocker(key).GetMock().Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue