[#19] Client: Use specific classes for search
All checks were successful
DCO / DCO (pull_request) Successful in 27s

Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
Pavel Gross 2024-07-25 14:20:14 +03:00
parent 3206abc33e
commit 35fe791406
27 changed files with 320 additions and 123 deletions

View file

@ -21,7 +21,7 @@ public class SmokeTests
private static readonly PrmWait lightWait = new (100, 1);
private readonly string key = "KwHDAJ66o8FoLBjVbjP2sWBmgBMGjt7Vv4boA7xQrBoAYBE397Aq";
private readonly string url = "http://172.23.32.4:8080";
[Fact]
public async void NetworkMapTest()
{
@ -115,7 +115,7 @@ public class SmokeTests
{
Header = new ObjectHeader(
containerId: containerId,
type: ObjectType.Regular,
type: ModelsV2.Enums.ObjectType.Regular,
new ObjectAttribute("fileName", "test")),
Payload = new MemoryStream(bytes),
ClientCut = false,
@ -140,6 +140,88 @@ public class SmokeTests
await Cleanup(client);
}
[Fact]
public async void FilterTest()
{
using var client = Client.GetInstance(GetOptions(this.key, this.url));
await Cleanup(client);
var createContainerParam = new PrmContainerCreate(
new ModelsV2.Container(BasicAcl.PublicRW, new PlacementPolicy(true, new Replica(1))))
{
WaitParams = lightWait
};
var containerId = await client.CreateContainerAsync(createContainerParam);
var bytes = new byte[] { 1, 2, 3 };
var ParentHeader = new ObjectHeader(
containerId: containerId,
type: ModelsV2.Enums.ObjectType.Regular)
{
PayloadLength = 3
};
var param = new PrmObjectPut
{
Header = new ObjectHeader(
containerId: containerId,
type: ModelsV2.Enums.ObjectType.Regular,
new ObjectAttribute("fileName", "test"))
{
Split = new Split(),
},
Payload = new MemoryStream(bytes),
ClientCut = false
};
var objectId = await client.PutObjectAsync(param);
var head = await client.GetObjectHeadAsync(new PrmObjectHeadGet(containerId, objectId));
var ecdsaKey = this.key.LoadWif();
var networkInfo = await client.GetNetmapSnapshotAsync();
await CheckFilter(client, containerId, new FilterByContainerId(ObjectMatchType.Equals, containerId));
await CheckFilter(client, containerId, new FilterByOwnerId(ObjectMatchType.Equals, OwnerId.FromKey(ecdsaKey)));
await CheckFilter(client, containerId, new FilterBySplitId(ObjectMatchType.Equals, param.Header.Split.SplitId));
await CheckFilter(client, containerId, new FilterByAttribute(ObjectMatchType.Equals, "fileName", "test"));
await CheckFilter(client, containerId, new FilterByObjectId(ObjectMatchType.Equals, objectId));
await CheckFilter(client, containerId, new FilterByVersion(ObjectMatchType.Equals, networkInfo.NodeInfoCollection[0].Version));
await CheckFilter(client, containerId, new FilterByEpoch(ObjectMatchType.Equals, networkInfo.Epoch));
await CheckFilter(client, containerId, new FilterByPayloadLength(ObjectMatchType.Equals, 3));
var checkSum = CheckSum.CreateCheckSum(bytes);
await CheckFilter(client, containerId, new FilterByPayloadHash(ObjectMatchType.Equals, checkSum));
await CheckFilter(client, containerId, new FilterByPhysicallyStored());
}
private static async Task CheckFilter(IFrostFSClient client, ContainerId containerId, IObjectFilter filter)
{
var resultObjectsCount = 0;
PrmObjectSearch searchParam = new(containerId) { Filters = [filter] };
await foreach (var objId in client.SearchObjectsAsync(searchParam))
{
resultObjectsCount++;
}
Assert.True(1 == resultObjectsCount, $"Filter for {filter.Key} doesn't work");
}
[Theory]
[InlineData(1)]
[InlineData(3 * 1024 * 1024)] // exactly one chunk size - 3MB
@ -153,7 +235,7 @@ public class SmokeTests
bool callbackInvoked = false;
var ctx = new Context
{
Timeout = TimeSpan.FromSeconds(20),
// Timeout = TimeSpan.FromSeconds(20),
Callback = new((CallStatistics cs) =>
{
callbackInvoked = true;
@ -179,7 +261,7 @@ public class SmokeTests
{
Header = new ObjectHeader(
containerId: containerId,
type: ObjectType.Regular,
type: ModelsV2.Enums.ObjectType.Regular,
new ObjectAttribute("fileName", "test")),
Payload = new MemoryStream(bytes),
ClientCut = false,
@ -191,7 +273,7 @@ public class SmokeTests
var objectId = await client.PutObjectAsync(param);
var filter = new ObjectFilter(ObjectMatchType.Equals, "fileName", "test");
var filter = new FilterByAttribute(ObjectMatchType.Equals, "fileName", "test");
bool hasObject = false;
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId) { Filters = [filter] }))
@ -263,7 +345,7 @@ public class SmokeTests
{
Header = new ObjectHeader(
containerId: containerId,
type: ObjectType.Regular,
type: ModelsV2.Enums.ObjectType.Regular,
new ObjectAttribute("fileName", "test")),
Payload = new MemoryStream(bytes),
ClientCut = false,
@ -276,7 +358,7 @@ public class SmokeTests
var objectId = await client.PutObjectAsync(param);
var filter = new ObjectFilter(ObjectMatchType.Equals, "fileName", "test");
var filter = new FilterByAttribute(ObjectMatchType.Equals, "fileName", "test");
bool hasObject = false;
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId) { Filters = [filter], SessionToken = token }))
@ -319,6 +401,7 @@ public class SmokeTests
[InlineData(64 * 1024 * 1024 - 1)]
[InlineData(64 * 1024 * 1024 + 1)]
[InlineData(2 * 64 * 1024 * 1024 + 256)]
[InlineData(200)]
public async void ClientCutScenarioTest(int objectSize)
{
using var client = Client.GetInstance(GetOptions(this.key, this.url));
@ -348,7 +431,7 @@ public class SmokeTests
{
Header = new ObjectHeader(
containerId: containerId,
type: ObjectType.Regular,
type: ModelsV2.Enums.ObjectType.Regular,
new ObjectAttribute("fileName", "test")),
Payload = new MemoryStream(bytes),
ClientCut = true
@ -356,7 +439,7 @@ public class SmokeTests
var objectId = await client.PutObjectAsync(param);
var filter = new ObjectFilter(ObjectMatchType.Equals, "fileName", "test");
var filter = new FilterByAttribute(ObjectMatchType.Equals, "fileName", "test");
bool hasObject = false;
await foreach (var objId in client.SearchObjectsAsync(new PrmObjectSearch(containerId, filter)))
@ -385,6 +468,8 @@ public class SmokeTests
Assert.Equal(MD5.HashData(bytes), MD5.HashData(downloadedBytes));
await CheckFilter(client, containerId, new FilterByRootObject());
await Cleanup(client);
var deadline = DateTime.UtcNow.Add(TimeSpan.FromSeconds(5));
@ -392,14 +477,14 @@ public class SmokeTests
IAsyncEnumerator<ContainerId>? enumerator = null;
do
{
if (deadline <= DateTime.UtcNow)
{
Assert.Fail("Containers exist");
break;
}
if (deadline <= DateTime.UtcNow)
{
Assert.Fail("Containers exist");
break;
}
enumerator = client.ListContainersAsync().GetAsyncEnumerator();
await Task.Delay(500);
enumerator = client.ListContainersAsync().GetAsyncEnumerator();
await Task.Delay(500);
}
while (await enumerator!.MoveNextAsync());
}