fix(grpc-data): H1 cursors bind an opaque namespace/view tag besides (realm, identifier) (review 2)
The realm folds mapped/raw into Raw (and every other index into Uns), so (realm, identifier) alone could resume a raw node's cursor on the same identifier in a mapped namespace. Items and cursor state now carry a binding tag: the SDK adapter (and the events path) passes the node's namespace URI, restoring the pre-port namespace-qualified binding; a peer passes its view tag. The peer key binds it too.
This commit is contained in:
@@ -77,6 +77,8 @@ namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
||||
/// <param name="BoundRealm">With <paramref name="BoundIdentifier"/>, the node the cursor was issued for — re-keyed by the H1 history
|
||||
/// port from the SDK NodeId string to <c>(realm, identifier)</c>, so a cursor never depends on an SDK handle.</param>
|
||||
/// <param name="BoundIdentifier">The node's identifier in <paramref name="BoundRealm"/>; required on every production cursor.</param>
|
||||
/// <param name="BoundTag">The node's binding discriminator (<see cref="HistoryReadPortItem.BindingTag"/> — the namespace URI
|
||||
/// locally, a view tag for a peer); the realm alone folds namespaces, so a cursor is bound to this too.</param>
|
||||
/// <param name="AddressSpaceEpoch">The topology generation. A removal conservatively invalidates all cursors.</param>
|
||||
internal sealed record HistoryContinuationState(
|
||||
string Tagname,
|
||||
@@ -95,6 +97,7 @@ internal sealed record HistoryContinuationState(
|
||||
bool WithinTieCluster = false,
|
||||
AddressSpaceRealm BoundRealm = default,
|
||||
string? BoundIdentifier = null,
|
||||
string? BoundTag = null,
|
||||
long AddressSpaceEpoch = -1)
|
||||
{
|
||||
/// <summary>The walk-back hint this cursor carries.</summary>
|
||||
|
||||
@@ -94,11 +94,22 @@ internal sealed record HistoryReadAtTimeVariant(IReadOnlyList<DateTime> Timestam
|
||||
/// <param name="Identifier">The node's <c>s=</c> identifier in that realm.</param>
|
||||
/// <param name="ContinuationPoint">The inbound continuation point; null/empty = a fresh read.</param>
|
||||
/// <param name="AggregateType">Processed only: the requested aggregate function's NodeId.</param>
|
||||
/// <param name="BindingTag">
|
||||
/// An opaque discriminator a continuation is bound to on top of <c>(realm, identifier)</c>, because the realm folds
|
||||
/// namespaces (mapped/raw → Raw, every other index → Uns): the SDK adapter passes the node's namespace URI
|
||||
/// (<see cref="OtOpcUaNodeManager.HistoryBindingTag"/>), a peer (H2) its view tag (mapping id / kind). Compared ordinally;
|
||||
/// a cursor issued under one tag never resumes under another.
|
||||
/// </param>
|
||||
/// <param name="NodeId">The local adapter's original NodeId, for log lines only (never used to resolve or bind).</param>
|
||||
internal readonly record struct HistoryReadPortItem(
|
||||
AddressSpaceRealm Realm, string Identifier, byte[]? ContinuationPoint = null, NodeId AggregateType = default)
|
||||
AddressSpaceRealm Realm, string Identifier, byte[]? ContinuationPoint = null, NodeId AggregateType = default,
|
||||
string? BindingTag = null, NodeId NodeId = default)
|
||||
{
|
||||
/// <summary>The node, for log lines (<c>Realm:Identifier</c>).</summary>
|
||||
public override string ToString() => $"{Realm}:{Identifier}";
|
||||
/// <summary>What a log line names the node as: the original NodeId when the SDK adapter supplied it, else <c>Realm:Identifier</c>.</summary>
|
||||
public object LogNodeId => NodeId.IsNull ? $"{Realm}:{Identifier}" : NodeId;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string ToString() => LogNodeId.ToString()!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -145,8 +156,9 @@ internal sealed class HistoryReadNodeOutcome
|
||||
/// <param name="Identifier">The node's identifier.</param>
|
||||
/// <param name="Epoch">The history (address-space) epoch the cursor was issued under.</param>
|
||||
/// <param name="Details">The request details (a peer binds their hash; the SDK session store ignores them).</param>
|
||||
/// <param name="Tag">The item's <see cref="HistoryReadPortItem.BindingTag"/>.</param>
|
||||
internal readonly record struct HistoryContinuationBinding(
|
||||
AddressSpaceRealm Realm, string Identifier, long Epoch, HistoryReadVariant? Details);
|
||||
AddressSpaceRealm Realm, string Identifier, long Epoch, HistoryReadVariant? Details, string? Tag = null);
|
||||
|
||||
/// <summary>
|
||||
/// Where the port stores and takes resume state for one caller. The local SDK path binds it to the OPC UA session
|
||||
@@ -361,7 +373,8 @@ public sealed partial class OtOpcUaNodeManager
|
||||
// AggregateType is a per-node parallel collection (same length as nodesToRead, enforced by the base
|
||||
// dispatcher); handle.Index is the node's position in it.
|
||||
items[i] = new HistoryReadPortItem(key.Realm, key.Id, cp.Length > 0 ? cp.ToArray() : null,
|
||||
variant is HistoryReadProcessedVariant ? aggregates[handle.Index] : default);
|
||||
variant is HistoryReadProcessedVariant ? aggregates[handle.Index] : default,
|
||||
HistoryBindingTag(handle.NodeId), handle.NodeId);
|
||||
}
|
||||
|
||||
var outcomes = ReadHistory(variant, items, SessionHistoryContinuationScope(context.OperationContext?.Session),
|
||||
@@ -374,6 +387,17 @@ public sealed partial class OtOpcUaNodeManager
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The continuation binding tag of a local node: its namespace URI. With <c>(realm, identifier)</c> it is the same
|
||||
/// identity the pre-port cursor bound (the namespace-qualified NodeId string), so a cursor of a raw node never resumes
|
||||
/// on the same identifier in the mapped/raw namespace, nor the reverse.
|
||||
/// </summary>
|
||||
/// <param name="nodeId">The node.</param>
|
||||
/// <returns>The namespace URI, or <c>ns=<index></c> for an unregistered index.</returns>
|
||||
internal string HistoryBindingTag(NodeId nodeId) =>
|
||||
Server.NamespaceUris.GetString(nodeId.NamespaceIndex)
|
||||
?? "ns=" + nodeId.NamespaceIndex.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
/// <summary>The continuation scope of a local OPC UA session — the SDK session store, as before the port.</summary>
|
||||
/// <param name="session">The request's session; null on the session-less in-process path.</param>
|
||||
/// <returns>A scope reading <see cref="HistoryContinuationStore"/> at each call.</returns>
|
||||
@@ -417,18 +441,20 @@ public sealed partial class OtOpcUaNodeManager
|
||||
/// single-shot for that node, as before.
|
||||
/// </summary>
|
||||
private byte[]? SaveHistoryContinuation(
|
||||
IHistoryContinuationScope scope, AddressSpaceRealm realm, string identifier, long epoch,
|
||||
IHistoryContinuationScope scope, AddressSpaceRealm realm, string identifier, string? tag, long epoch,
|
||||
HistoryReadVariant? details, HistoryContinuationState state)
|
||||
{
|
||||
if (epoch != Volatile.Read(ref _historyContinuationEpoch)) return null;
|
||||
return scope.Save(state with { BoundRealm = realm, BoundIdentifier = identifier, AddressSpaceEpoch = epoch },
|
||||
new HistoryContinuationBinding(realm, identifier, epoch, details));
|
||||
return scope.Save(state with { BoundRealm = realm, BoundIdentifier = identifier, BoundTag = tag, AddressSpaceEpoch = epoch },
|
||||
new HistoryContinuationBinding(realm, identifier, epoch, details, tag));
|
||||
}
|
||||
|
||||
/// <summary>Whether a taken cursor was issued for this node, in this realm, under this epoch.</summary>
|
||||
private static bool HistoryContinuationMatches(HistoryContinuationState state, AddressSpaceRealm realm, string identifier, long epoch) =>
|
||||
/// <summary>Whether a taken cursor was issued for this node (realm, identifier and binding tag) under this epoch.</summary>
|
||||
private static bool HistoryContinuationMatches(
|
||||
HistoryContinuationState state, AddressSpaceRealm realm, string identifier, string? tag, long epoch) =>
|
||||
state.BoundIdentifier is not null && state.BoundRealm == realm
|
||||
&& string.Equals(state.BoundIdentifier, identifier, StringComparison.Ordinal) && state.AddressSpaceEpoch == epoch;
|
||||
&& string.Equals(state.BoundIdentifier, identifier, StringComparison.Ordinal)
|
||||
&& string.Equals(state.BoundTag, tag, StringComparison.Ordinal) && state.AddressSpaceEpoch == epoch;
|
||||
|
||||
/// <summary>The SDK session store behind a scope (read per call, so a test's store swap applies to the next call).</summary>
|
||||
private sealed class SessionScope(OtOpcUaNodeManager nm, ISession? session) : IHistoryContinuationScope
|
||||
|
||||
@@ -9036,7 +9036,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
var state = _historyContinuationStore.TryTake(session, inboundCp.ToArray());
|
||||
// A point is bound to the node that issued it: another node's source name is a miss too.
|
||||
var boundKey = MapKey(handle.NodeId);
|
||||
if (state is null || !HistoryContinuationMatches(state, boundKey.Realm, boundKey.Id, historyEpoch) || state.Kind != HistoryCursorKind.Events || state.Tagname != sourceName)
|
||||
if (state is null || !HistoryContinuationMatches(state, boundKey.Realm, boundKey.Id, HistoryBindingTag(handle.NodeId), historyEpoch) || state.Kind != HistoryCursorKind.Events || state.Tagname != sourceName)
|
||||
{
|
||||
errors[handle.Index] = StatusCodes.BadContinuationPointInvalid;
|
||||
results[handle.Index] = new SdkHistoryReadResult { StatusCode = StatusCodes.BadContinuationPointInvalid };
|
||||
@@ -9214,7 +9214,8 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
var historyEvent = ProjectEvents(events, selectClauses, where, filterContext);
|
||||
var eventsKey = MapKey(handle.NodeId);
|
||||
var outboundCp = pendingCursor is null ? null : SaveHistoryContinuation(
|
||||
SessionHistoryContinuationScope(session), eventsKey.Realm, eventsKey.Id, historyEpoch, details: null, pendingCursor);
|
||||
SessionHistoryContinuationScope(session), eventsKey.Realm, eventsKey.Id, HistoryBindingTag(handle.NodeId), historyEpoch,
|
||||
details: null, pendingCursor);
|
||||
results[handle.Index] = new SdkHistoryReadResult
|
||||
{
|
||||
// No events ⇒ GoodNoData (the notifier is historized, the window just held no events — or none matched).
|
||||
@@ -10119,8 +10120,8 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
{
|
||||
// Resume read: take the stored cursor. A miss (unknown / evicted / malformed point) ⇒
|
||||
// BadContinuationPointInvalid for THIS node.
|
||||
var state = continuations.TryTake(inboundCp, new HistoryContinuationBinding(handle.Realm, handle.Identifier, historyEpoch, details));
|
||||
if (state is null || !HistoryContinuationMatches(state, handle.Realm, handle.Identifier, historyEpoch) || state.Kind != HistoryCursorKind.Raw
|
||||
var state = continuations.TryTake(inboundCp, new HistoryContinuationBinding(handle.Realm, handle.Identifier, historyEpoch, details, handle.BindingTag));
|
||||
if (state is null || !HistoryContinuationMatches(state, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch) || state.Kind != HistoryCursorKind.Raw
|
||||
|| !TryGetHistorizedTagname(handle.Identifier, out var boundTag, handle.Realm) || boundTag != state.Tagname)
|
||||
{
|
||||
outcome.Error = StatusCodes.BadContinuationPointInvalid;
|
||||
@@ -10187,7 +10188,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
return null;
|
||||
}
|
||||
|
||||
return SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, historyEpoch, details, new HistoryContinuationState(
|
||||
return SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch, details, new HistoryContinuationState(
|
||||
tagname, previous, endUtc, 0, numValuesPerNode, SegmentWidthTicks: walkHint.WidthTicks,
|
||||
EmptyFromTicks: walkHint.EmptyFromTicks, EmptyToTicks: walkHint.EmptyToTicks,
|
||||
PendingEndBound: HistoryBounds.Carry(endBound!, page)! with { DataExhausted = true }));
|
||||
@@ -10253,7 +10254,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
if (startBound is not null && numValuesPerNode == 1 && anything)
|
||||
{
|
||||
// The page is the start bound alone; the data starts at StartTime on the next page.
|
||||
var boundOnlyCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, historyEpoch, details, new HistoryContinuationState(
|
||||
var boundOnlyCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch, details, new HistoryContinuationState(
|
||||
tagname, startUtc, endUtc, 0, numValuesPerNode, SegmentWidthTicks: walkHint.WidthTicks,
|
||||
EmptyFromTicks: walkHint.EmptyFromTicks, EmptyToTicks: walkHint.EmptyToTicks,
|
||||
PendingEndBound: HistoryBounds.Carry(pending, [startBound])));
|
||||
@@ -10440,7 +10441,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
EmptyFromTicks: walkHint.EmptyFromTicks, EmptyToTicks: walkHint.EmptyToTicks,
|
||||
PendingEndBound: HistoryBounds.Carry(endBound, slice),
|
||||
WithinTieCluster: resumeAt == startUtc);
|
||||
clusterCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, historyEpoch, details, clusterState);
|
||||
clusterCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch, details, clusterState);
|
||||
}
|
||||
else if (endBound is not null)
|
||||
{
|
||||
@@ -10495,7 +10496,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
{
|
||||
// Save may return null (no session on this request) ⇒ degrade to single-shot for this node.
|
||||
// Built AFTER historyData so a failure projecting samples can never orphan a stored cursor.
|
||||
outboundCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, historyEpoch, details, nextState);
|
||||
outboundCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch, details, nextState);
|
||||
}
|
||||
else if (endBound is not null)
|
||||
{
|
||||
@@ -10595,8 +10596,8 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
HistoryModifiedCursor? resumeAfter = null;
|
||||
if (inboundCp is { Length: > 0 })
|
||||
{
|
||||
var state = continuations.TryTake(inboundCp, new HistoryContinuationBinding(handle.Realm, handle.Identifier, historyEpoch, details));
|
||||
if (state is null || !HistoryContinuationMatches(state, handle.Realm, handle.Identifier, historyEpoch) || state.Kind != HistoryCursorKind.Modified || state.Tagname != tagname)
|
||||
var state = continuations.TryTake(inboundCp, new HistoryContinuationBinding(handle.Realm, handle.Identifier, historyEpoch, details, handle.BindingTag));
|
||||
if (state is null || !HistoryContinuationMatches(state, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch) || state.Kind != HistoryCursorKind.Modified || state.Tagname != tagname)
|
||||
{
|
||||
outcome.Error = StatusCodes.BadContinuationPointInvalid;
|
||||
outcome.Result = new SdkHistoryReadResult { StatusCode = StatusCodes.BadContinuationPointInvalid };
|
||||
@@ -10626,7 +10627,7 @@ public sealed partial class OtOpcUaNodeManager : CustomNodeManager2, INodeManage
|
||||
if (page.HasMore && numValuesPerNode > 0 && page.Values.Count > 0)
|
||||
{
|
||||
var last = page.Values[^1];
|
||||
outboundCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, historyEpoch, details, new HistoryContinuationState(
|
||||
outboundCp = SaveHistoryContinuation(continuations, handle.Realm, handle.Identifier, handle.BindingTag, historyEpoch, details, new HistoryContinuationState(
|
||||
tagname, last.SourceTimeUtc, endUtc, 0, numValuesPerNode,
|
||||
HistoryCursorKind.Modified, last.ModifiedId, startUtc));
|
||||
}
|
||||
|
||||
@@ -13,9 +13,10 @@ namespace ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
||||
/// <param name="Epoch">The history (address-space) epoch.</param>
|
||||
/// <param name="Realm">The view's realm.</param>
|
||||
/// <param name="Identifier">The view's identifier.</param>
|
||||
/// <param name="BindingTag">The view's binding tag (<see cref="HistoryReadPortItem.BindingTag"/>).</param>
|
||||
/// <param name="DetailsHash">The <see cref="HistoryReadVariant.ComputeDetailsHash"/> of the request.</param>
|
||||
internal readonly record struct PeerHistoryContinuationKey(
|
||||
string Principal, string ServingIncarnation, long Epoch, AddressSpaceRealm Realm, string Identifier, string DetailsHash);
|
||||
string Principal, string ServingIncarnation, long Epoch, AddressSpaceRealm Realm, string Identifier, string? BindingTag, string DetailsHash);
|
||||
|
||||
/// <summary>
|
||||
/// The ORIGIN-side store for remote peers' HistoryRead continuation points (gRPC data history plan §3.2, phase H1;
|
||||
@@ -123,7 +124,7 @@ internal sealed class PeerHistoryContinuationStore
|
||||
|
||||
var token = RandomNumberGenerator.GetBytes(TokenLength);
|
||||
var key = new PeerHistoryContinuationKey(
|
||||
principal, servingIncarnation, state.AddressSpaceEpoch, state.BoundRealm, state.BoundIdentifier, detailsHash);
|
||||
principal, servingIncarnation, state.AddressSpaceEpoch, state.BoundRealm, state.BoundIdentifier, state.BoundTag, detailsHash);
|
||||
lock (_gate)
|
||||
{
|
||||
var now = _clock.GetTimestamp();
|
||||
@@ -214,6 +215,6 @@ internal sealed class PeerHistoryContinuationScope(
|
||||
/// <inheritdoc />
|
||||
public HistoryContinuationState? TryTake(byte[] continuationPoint, HistoryContinuationBinding binding) =>
|
||||
store.TryTake(continuationPoint, new PeerHistoryContinuationKey(
|
||||
principal, currentServingIncarnation(), binding.Epoch, binding.Realm, binding.Identifier,
|
||||
principal, currentServingIncarnation(), binding.Epoch, binding.Realm, binding.Identifier, binding.Tag,
|
||||
binding.Details?.ComputeDetailsHash() ?? string.Empty));
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public sealed class HistoryReadPortPagingFuzzTests(HistoryReadPortServerFixture
|
||||
|
||||
private (uint Status, List<string> Values, byte[]? Cp) PortRead(HistoryReadRawVariant details, AddressSpaceRealm realm, string id, byte[]? cp)
|
||||
{
|
||||
var outcome = fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp)],
|
||||
var outcome = fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp, BindingTag: fx.Nm.HistoryBindingTag(fx.Nodes["dbl"].NodeId))],
|
||||
fx.Nm.SessionHistoryContinuationScope(session: null), CancellationToken.None)[0];
|
||||
// The operation slot, as the override's errors[i] (Status folds GoodNoData in; pinned by the parity tests).
|
||||
return (outcome.Error?.StatusCode.Code ?? StatusCodes.BadHistoryOperationUnsupported.Code,
|
||||
|
||||
@@ -410,6 +410,38 @@ public sealed class HistoryReadPortParityTests(HistoryReadPortServerFixture fx)
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_cursor_is_bound_to_its_namespace_not_only_realm_and_identifier()
|
||||
{
|
||||
await RunAsync(async () =>
|
||||
{
|
||||
var source = new ParitySource();
|
||||
source.Series["P.raw"] = Enumerable.Range(0, 6).Select(i => S((double)i, i)).ToList();
|
||||
fx.Nm.HistorianDataSource = source;
|
||||
var (realm, id, nodeId) = fx.Nodes["raw"];
|
||||
var details = new HistoryReadRawVariant(T(0), T(100), 2, ReturnBounds: false);
|
||||
var local = fx.Nm.HistoryBindingTag(nodeId);
|
||||
// mapped/raw folds into the Raw realm: the same (Raw, identifier) in the projected namespace is ANOTHER node.
|
||||
var mapped = ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ProjectedDataIds.RawNamespaceUri;
|
||||
local.ShouldNotBe(mapped);
|
||||
var scope = fx.Nm.SessionHistoryContinuationScope(session: null);
|
||||
|
||||
HistoryReadNodeOutcome Read(string tag, byte[]? cp) =>
|
||||
fx.Nm.ReadHistory(details, [new HistoryReadPortItem(realm, id, cp, BindingTag: tag)], scope, CancellationToken.None)[0];
|
||||
|
||||
Read(mapped, Read(local, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
Read(local, Read(mapped, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
Read(local, Read(local, null).ContinuationPoint).Status.Code.ShouldBe(StatusCodes.Good.Code);
|
||||
|
||||
// The SDK adapter tags with the same value: an override-issued cursor resumes through the port with the local
|
||||
// tag and is refused with the mapped one.
|
||||
var sdk = Raw(T(0), T(100), 2, bounds: false);
|
||||
Read(local, ReadOverrideRaw(sdk, "raw", null).Cp).Status.Code.ShouldBe(StatusCodes.Good.Code);
|
||||
Read(mapped, ReadOverrideRaw(sdk, "raw", null).Cp).Status.Code.ShouldBe(StatusCodes.BadContinuationPointInvalid.Code);
|
||||
await Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task The_outcome_status_carries_GoodNoData_and_Bad_operation_statuses_verbatim()
|
||||
{
|
||||
@@ -509,7 +541,8 @@ public sealed class HistoryReadPortParityTests(HistoryReadPortServerFixture fx)
|
||||
{
|
||||
var items = nodes.Select((n, i) => new HistoryReadPortItem(
|
||||
fx.Nodes[n.Key].Realm, fx.Nodes[n.Key].Id, n.Cp,
|
||||
details is ReadProcessedDetails p ? p.AggregateType[i] : default)).ToArray();
|
||||
details is ReadProcessedDetails p ? p.AggregateType[i] : default,
|
||||
BindingTag: fx.Nm.HistoryBindingTag(fx.Nodes[n.Key].NodeId), NodeId: fx.Nodes[n.Key].NodeId)).ToArray();
|
||||
var outcomes = fx.Nm.ReadHistory(HistoryReadVariant.From(details), items,
|
||||
fx.Nm.SessionHistoryContinuationScope(session: null), CancellationToken.None);
|
||||
// A slot the port leaves unset is the one the SDK seeded before the override ran (an empty, Good result).
|
||||
|
||||
+9
-6
@@ -20,13 +20,14 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
private static HistoryContinuationState State(string identifier = "Plant/dev/t1", long epoch = 3, AddressSpaceRealm realm = AddressSpaceRealm.Raw) =>
|
||||
new("WW.T1", DateTime.UnixEpoch, DateTime.UnixEpoch.AddDays(1), 0, 10)
|
||||
{
|
||||
BoundRealm = realm, BoundIdentifier = identifier, AddressSpaceEpoch = epoch,
|
||||
BoundRealm = realm, BoundIdentifier = identifier, BoundTag = "view-1", AddressSpaceEpoch = epoch,
|
||||
};
|
||||
|
||||
private static PeerHistoryContinuationKey Key(
|
||||
string principal = Principal, string incarnation = Incarnation, long epoch = 3,
|
||||
AddressSpaceRealm realm = AddressSpaceRealm.Raw, string identifier = "Plant/dev/t1", string hash = Hash) =>
|
||||
new(principal, incarnation, epoch, realm, identifier, hash);
|
||||
AddressSpaceRealm realm = AddressSpaceRealm.Raw, string identifier = "Plant/dev/t1", string hash = Hash,
|
||||
string? tag = "view-1") =>
|
||||
new(principal, incarnation, epoch, realm, identifier, tag, hash);
|
||||
|
||||
private static PeerHistoryContinuationStore Store(int capacity = 8, ManualClock? clock = null, TimeSpan? idle = null) =>
|
||||
new(Principal, Incarnation, capacity, idle, clock ?? new ManualClock());
|
||||
@@ -63,6 +64,8 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
("epoch bump", Key(epoch: 4)),
|
||||
("realm", Key(realm: AddressSpaceRealm.Uns)),
|
||||
("identifier", Key(identifier: "Plant/dev/t2")),
|
||||
("binding tag", Key(tag: "view-2")),
|
||||
("no binding tag", Key(tag: null)),
|
||||
("details hash", Key(hash: "hash-b")),
|
||||
};
|
||||
foreach (var (name, key) in cases)
|
||||
@@ -209,7 +212,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var store = Store();
|
||||
var scope = new PeerHistoryContinuationScope(store, Principal, () => Incarnation);
|
||||
var details = new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, details);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, details, Tag: "view-1");
|
||||
|
||||
var token = scope.Save(State(), binding)!;
|
||||
scope.TryTake(token, binding with { Details = details with { NumValuesPerNode = 11 } }).ShouldBeNull("other details");
|
||||
@@ -230,7 +233,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var incarnation = Incarnation;
|
||||
var scope = new PeerHistoryContinuationScope(store, Principal, () => incarnation);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3,
|
||||
new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false));
|
||||
new HistoryReadRawVariant(DateTime.UnixEpoch, DateTime.UnixEpoch.AddHours(1), 10, ReturnBounds: false), Tag: "view-1");
|
||||
|
||||
var token = scope.Save(State(), binding)!;
|
||||
incarnation = "inc-2";
|
||||
@@ -246,7 +249,7 @@ public sealed class PeerHistoryContinuationStoreTests
|
||||
var store = Store();
|
||||
var owner = new PeerHistoryContinuationScope(store, Principal, () => Incarnation);
|
||||
var other = new PeerHistoryContinuationScope(store, "someone-else", () => Incarnation);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, null);
|
||||
var binding = new HistoryContinuationBinding(AddressSpaceRealm.Raw, "Plant/dev/t1", 3, null, Tag: "view-1");
|
||||
|
||||
Should.Throw<ArgumentException>(() => other.Save(State(), binding), "a store never holds another principal's cursor");
|
||||
var token = owner.Save(State(), binding)!;
|
||||
|
||||
Reference in New Issue
Block a user