[#29] Client: Add PlacementVector unit tests

Signed-off-by: Pavel Gross <p.gross@yadro.com>
This commit is contained in:
Pavel Gross 2025-01-13 10:34:44 +03:00
parent 568bdc67e8
commit 43e300c773
33 changed files with 3054 additions and 234 deletions

View file

@ -104,20 +104,23 @@ internal struct Context
return;
}
if (filter.Operation == (int)Operation.EQ ||
filter.Operation == (int)Operation.NE ||
filter.Operation == (int)Operation.LIKE ||
filter.Operation == (int)Operation.GT ||
filter.Operation == (int)Operation.GE ||
filter.Operation == (int)Operation.LT ||
filter.Operation == (int)Operation.LE)
switch (filter.Operation)
{
var n = uint.Parse(filter.Value, CultureInfo.InvariantCulture);
NumCache[filter.Value] = n;
}
else
{
throw new FrostFsException($"{errInvalidFilterOp}: {filter.Operation}");
case (int)Operation.EQ:
case (int)Operation.NE:
case (int)Operation.LIKE:
break;
case (int)Operation.GT:
case (int)Operation.GE:
case (int)Operation.LT:
case (int)Operation.LE:
{
var n = uint.Parse(filter.Value, CultureInfo.InvariantCulture);
NumCache[filter.Value] = n;
break;
}
default:
throw new FrostFsException($"{errInvalidFilterOp}: {filter.Operation}");
}
}
@ -153,7 +156,7 @@ internal struct Context
// for the given selector.
static (int bucketCount, int nodesInBucket) CalcNodesCount(FrostFsSelector selector)
{
return selector.Clause == (uint)FrostFsClause.Same
return selector.Clause == (int)FrostFsClause.Same
? (1, (int)selector.Count)
: ((int)selector.Count, 1);
}
@ -211,11 +214,17 @@ internal struct Context
{
double[] ws = [];
foreach (var res in result)
var sortedNodes = new NodeAttrPair[result.Count];
for (int i = 0; i < result.Count; i++)
{
Tools.AppendWeightsTo(res.nodes, weightFunc, ws);
Tools.SortHasherSliceByWeightValue(res.nodes.ToList(), ws, HrwSeedHash);
var res = result[i];
Tools.AppendWeightsTo(res.nodes, weightFunc, ref ws);
sortedNodes[i].nodes = Tools.SortHasherSliceByWeightValue(res.nodes.ToList(), ws, HrwSeedHash).ToArray();
sortedNodes[i].attr = result[i].attr;
}
return sortedNodes;
}
return [.. result];
}
@ -273,7 +282,7 @@ internal struct Context
if (res.Count < bucketCount)
{
// Fallback to using minimum allowed backup factor (1).
res = fallback;
res.AddRange(fallback);
if (Strict && res.Count < bucketCount)
{
@ -293,7 +302,12 @@ internal struct Context
}
var hashers = res.Select(r => new HasherList(r)).ToList();
Tools.SortHasherSliceByWeightValue(hashers, weights, HrwSeedHash);
hashers = Tools.SortHasherSliceByWeightValue(hashers, weights, HrwSeedHash);
for (int i = 0; i < res.Count; i++)
{
res[i] = hashers[i].Nodes;
}
}
if (res.Count < bucketCount)
@ -331,7 +345,7 @@ internal struct Context
switch (f.Operation)
{
case (int)Operation.EQ:
return nodeInfo.Attributes[f.Key] == f.Value;
return nodeInfo.Attributes.TryGetValue(f.Key, out var val) && val == f.Value;
case (int)Operation.LIKE:
{
var hasPrefix = f.Value.StartsWith(likeWildcard, StringComparison.Ordinal);
@ -357,12 +371,21 @@ internal struct Context
return nodeInfo.Attributes[f.Key] != f.Value;
default:
{
var attr = f.Key switch
ulong attr;
switch (f.Key)
{
FrostFsNodeInfo.AttrPrice => nodeInfo.Price,
FrostFsNodeInfo.AttrCapacity => nodeInfo.GetCapacity(),
_ => uint.Parse(nodeInfo.Attributes[f.Key], CultureInfo.InvariantCulture),
};
case FrostFsNodeInfo.AttrPrice:
attr = nodeInfo.Price;
break;
case FrostFsNodeInfo.AttrCapacity:
attr = nodeInfo.GetCapacity();
break;
default:
if (!ulong.TryParse(nodeInfo.Attributes[f.Key], NumberStyles.Integer, CultureInfo.InvariantCulture, out attr))
return false;
break;
}
switch (f.Operation)
{