test: validate grpc data connections with local docker and opcua cli
This commit is contained in:
@@ -335,6 +335,10 @@ public static class DataProtoMapper
|
||||
v.Remove = new W.HandleChanges();
|
||||
v.Remove.Items.AddRange(r.Items.Select(EncodeHandle));
|
||||
break;
|
||||
case ChallengeSubscriptionFreshness c:
|
||||
v.FreshnessChallenge = new W.HandleChanges();
|
||||
v.FreshnessChallenge.Items.AddRange(c.Items.Select(EncodeHandle));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unsupported command.");
|
||||
}
|
||||
@@ -353,6 +357,7 @@ public static class DataProtoMapper
|
||||
W.SubscriptionCommand.CommandOneofCase.Add => x.Add.Items.Count,
|
||||
W.SubscriptionCommand.CommandOneofCase.Modify => x.Modify.Items.Count,
|
||||
W.SubscriptionCommand.CommandOneofCase.Remove => x.Remove.Items.Count,
|
||||
W.SubscriptionCommand.CommandOneofCase.FreshnessChallenge => x.FreshnessChallenge.Items.Count,
|
||||
_ => 0,
|
||||
};
|
||||
Preflight(x, count, limits);
|
||||
@@ -372,6 +377,10 @@ public static class DataProtoMapper
|
||||
|| handle.StreamEpoch != x.StreamEpoch
|
||||
)
|
||||
throw new ArgumentException("Removal handle belongs to another stream.");
|
||||
if (x.FreshnessChallenge is { } challenge)
|
||||
foreach (var handle in challenge.Items)
|
||||
if (handle.SubscriptionId != x.SubscriptionId || handle.StreamEpoch != x.StreamEpoch)
|
||||
throw new ArgumentException("Challenge handle belongs to another stream.");
|
||||
var t = TimeSpan.FromTicks(x.AcknowledgementTimeoutTicks);
|
||||
return x.CommandCase switch
|
||||
{
|
||||
@@ -406,6 +415,9 @@ public static class DataProtoMapper
|
||||
t,
|
||||
x.Remove.Items.Select(DecodeHandle).ToArray()
|
||||
),
|
||||
W.SubscriptionCommand.CommandOneofCase.FreshnessChallenge => new ChallengeSubscriptionFreshness(
|
||||
x.SubscriptionId, x.StreamEpoch, x.CommandId, t,
|
||||
x.FreshnessChallenge.Items.Select(DecodeHandle).ToArray()),
|
||||
_ => throw new ArgumentException("Missing command."),
|
||||
};
|
||||
}
|
||||
@@ -488,7 +500,8 @@ public static class DataProtoMapper
|
||||
serving,
|
||||
update.Version
|
||||
);
|
||||
items.Add(new DataSubscriptionValue(handle, sample, ageBounds, readiness));
|
||||
items.Add(new DataSubscriptionValue(handle, sample, ageBounds, readiness,
|
||||
subscriptionAgeReadiness && update.HasFreshnessChallengeId && update.FreshnessChallengeId.Length <= 32 ? update.FreshnessChallengeId : null));
|
||||
}
|
||||
return new DataSubscriptionValues(
|
||||
frame.SubscriptionId,
|
||||
@@ -533,6 +546,7 @@ public static class DataProtoMapper
|
||||
ValidateSubscriptionAgeReadiness(item);
|
||||
if (item.AgeBounds.Lower is { } lower) update.OriginAgeTicks = lower.Ticks;
|
||||
update.Readiness = (int)item.Readiness;
|
||||
if (item.FreshnessChallengeId is { } challenge) update.FreshnessChallengeId = challenge;
|
||||
}
|
||||
result.Values.Items.Add(update);
|
||||
}
|
||||
@@ -573,6 +587,7 @@ public static class DataProtoMapper
|
||||
ValidateSubscriptionAgeReadiness(item);
|
||||
if (item.AgeBounds.Lower is { } lower) update.OriginAgeTicks = lower.Ticks;
|
||||
update.Readiness = (int)item.Readiness;
|
||||
if (item.FreshnessChallengeId is { } challenge) update.FreshnessChallengeId = challenge;
|
||||
}
|
||||
if (item.Sample.StatusCode != first.StatusCode)
|
||||
update.StatusCode = item.Sample.StatusCode;
|
||||
@@ -649,7 +664,8 @@ public static class DataProtoMapper
|
||||
throw new ArgumentException("Unexpected serving identity.");
|
||||
var (ageBounds, readiness) = DecodeSubscriptionAgeReadiness(subscriptionAgeReadiness,
|
||||
item.HasOriginAgeTicks, item.OriginAgeTicks, item.HasReadiness, item.Readiness);
|
||||
items.Add(new(handle, DecodeSample(item.Sample, maxElements, maxBytes), ageBounds, readiness));
|
||||
items.Add(new(handle, DecodeSample(item.Sample, maxElements, maxBytes), ageBounds, readiness,
|
||||
subscriptionAgeReadiness && item.HasFreshnessChallengeId && item.FreshnessChallengeId.Length <= 32 ? item.FreshnessChallengeId : null));
|
||||
}
|
||||
return new(
|
||||
frame.SubscriptionId,
|
||||
@@ -995,6 +1011,8 @@ public static class DataProtoMapper
|
||||
SubscriptionAgeReadiness = x.SubscriptionAgeReadiness,
|
||||
ResponseServingIdentity = x.ResponseServingIdentity,
|
||||
WriteServingGenerationEnforced = x.WriteServingGenerationEnforced,
|
||||
SubscriptionFreshnessChallenges = x.SubscriptionFreshnessChallenges,
|
||||
MetadataItemLeases = x.MetadataItemLeases,
|
||||
Limits = new W.Limits
|
||||
{
|
||||
MaxPageItems = l.MaxPageItems,
|
||||
@@ -1061,7 +1079,9 @@ public static class DataProtoMapper
|
||||
x.ClusterId,
|
||||
x.SubscriptionAgeReadiness,
|
||||
x.ResponseServingIdentity,
|
||||
x.WriteServingGenerationEnforced
|
||||
x.WriteServingGenerationEnforced,
|
||||
x.SubscriptionFreshnessChallenges,
|
||||
x.MetadataItemLeases
|
||||
);
|
||||
result.Validate();
|
||||
return result;
|
||||
@@ -1190,6 +1210,9 @@ public static class DataProtoMapper
|
||||
public static W.MetadataResult EncodeMetadataResult(DataItemResult<DataMetadata> item)
|
||||
{
|
||||
DataContractValidation.Required(item.Status);
|
||||
if (item.Lease is { } lease && (item.Status != DataItemStatus.Good || item.Value is null ||
|
||||
lease.CatalogEpoch <= 0 || lease.AuthorityEpoch <= 0 || lease.Duration <= TimeSpan.Zero))
|
||||
throw new ArgumentException("A metadata lease requires a successful item and valid authority.");
|
||||
var result = new W.MetadataResult
|
||||
{
|
||||
CorrelationId = item.CorrelationId,
|
||||
@@ -1199,6 +1222,9 @@ public static class DataProtoMapper
|
||||
result.Value = EncodeMetadata(item.Value);
|
||||
if (item.Diagnostic is not null)
|
||||
result.Diagnostic = item.Diagnostic;
|
||||
if (item.Lease is { } itemLease)
|
||||
result.Lease = new W.Lease { CatalogEpoch = itemLease.CatalogEpoch, AuthorityEpoch = itemLease.AuthorityEpoch,
|
||||
DurationTicks = itemLease.Duration.Ticks };
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1210,11 +1236,17 @@ public static class DataProtoMapper
|
||||
Preflight(item, 1, limits);
|
||||
var status = (DataItemStatus)item.Status;
|
||||
DataContractValidation.Required(status);
|
||||
MetadataLease? lease = item.Lease is { } itemLease
|
||||
? new(itemLease.CatalogEpoch, itemLease.AuthorityEpoch, TimeSpan.FromTicks(itemLease.DurationTicks)) : null;
|
||||
if (lease is not null && (status != DataItemStatus.Good || item.Value is null ||
|
||||
lease.CatalogEpoch <= 0 || lease.AuthorityEpoch <= 0 || lease.Duration <= TimeSpan.Zero))
|
||||
throw new ArgumentException("A metadata lease requires a successful item and valid authority.");
|
||||
return new(
|
||||
item.CorrelationId,
|
||||
status,
|
||||
item.Value is null ? null : DecodeMetadata(item.Value),
|
||||
item.HasDiagnostic ? item.Diagnostic : null
|
||||
item.HasDiagnostic ? item.Diagnostic : null,
|
||||
lease
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user