test(cluster): HOCON parses, role parser truth table
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
<Folder Name="/tests/" />
|
<Folder Name="/tests/" />
|
||||||
<Folder Name="/tests/Core/">
|
<Folder Name="/tests/Core/">
|
||||||
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests.csproj" />
|
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests.csproj" />
|
||||||
|
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Cluster.Tests/ZB.MOM.WW.OtOpcUa.Cluster.Tests.csproj" />
|
||||||
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/ZB.MOM.WW.OtOpcUa.Configuration.Tests.csproj" />
|
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Configuration.Tests/ZB.MOM.WW.OtOpcUa.Configuration.Tests.csproj" />
|
||||||
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Tests/ZB.MOM.WW.OtOpcUa.Core.Tests.csproj" />
|
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Tests/ZB.MOM.WW.OtOpcUa.Core.Tests.csproj" />
|
||||||
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests/ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests.csproj" />
|
<Project Path="tests/Core/ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests/ZB.MOM.WW.OtOpcUa.Core.Scripting.Tests.csproj" />
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using Akka.Configuration;
|
||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.OtOpcUa.Cluster.Tests;
|
||||||
|
|
||||||
|
public sealed class HoconLoaderTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void LoadBaseConfig_returns_nonempty_string()
|
||||||
|
{
|
||||||
|
var hocon = HoconLoader.LoadBaseConfig();
|
||||||
|
hocon.ShouldNotBeNullOrWhiteSpace();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Base_config_parses_to_cluster_provider()
|
||||||
|
{
|
||||||
|
var cfg = ConfigurationFactory.ParseString(HoconLoader.LoadBaseConfig());
|
||||||
|
cfg.GetString("akka.actor.provider").ShouldBe("cluster");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Split_brain_resolver_is_keep_oldest()
|
||||||
|
{
|
||||||
|
var cfg = ConfigurationFactory.ParseString(HoconLoader.LoadBaseConfig());
|
||||||
|
cfg.GetString("akka.cluster.split-brain-resolver.active-strategy").ShouldBe("keep-oldest");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Stable_after_is_15_seconds()
|
||||||
|
{
|
||||||
|
var cfg = ConfigurationFactory.ParseString(HoconLoader.LoadBaseConfig());
|
||||||
|
cfg.GetTimeSpan("akka.cluster.split-brain-resolver.stable-after")
|
||||||
|
.ShouldBe(TimeSpan.FromSeconds(15));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Failure_detector_threshold_is_10()
|
||||||
|
{
|
||||||
|
var cfg = ConfigurationFactory.ParseString(HoconLoader.LoadBaseConfig());
|
||||||
|
cfg.GetDouble("akka.cluster.failure-detector.threshold").ShouldBe(10.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Opcua_synchronized_dispatcher_is_pinned()
|
||||||
|
{
|
||||||
|
var cfg = ConfigurationFactory.ParseString(HoconLoader.LoadBaseConfig());
|
||||||
|
cfg.GetString("opcua-synchronized-dispatcher.type").ShouldBe("PinnedDispatcher");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using Shouldly;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace ZB.MOM.WW.OtOpcUa.Cluster.Tests;
|
||||||
|
|
||||||
|
public sealed class RoleParserTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null)]
|
||||||
|
[InlineData("")]
|
||||||
|
[InlineData(" ")]
|
||||||
|
public void Empty_input_yields_empty_array(string? raw)
|
||||||
|
{
|
||||||
|
RoleParser.Parse(raw).ShouldBeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Single_role_admin()
|
||||||
|
{
|
||||||
|
RoleParser.Parse("admin").ShouldBe(new[] { "admin" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Two_roles_csv()
|
||||||
|
{
|
||||||
|
RoleParser.Parse("admin,driver").ShouldBe(new[] { "admin", "driver" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Whitespace_tolerant()
|
||||||
|
{
|
||||||
|
RoleParser.Parse(" admin , driver ").ShouldBe(new[] { "admin", "driver" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Case_insensitive_normalizes_to_lower()
|
||||||
|
{
|
||||||
|
RoleParser.Parse("ADMIN,Driver").ShouldBe(new[] { "admin", "driver" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Duplicate_roles_deduped()
|
||||||
|
{
|
||||||
|
RoleParser.Parse("admin,admin,driver").ShouldBe(new[] { "admin", "driver" });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Unknown_role_throws()
|
||||||
|
{
|
||||||
|
Should.Throw<ArgumentException>(() => RoleParser.Parse("admin,master"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
|
<RootNamespace>ZB.MOM.WW.OtOpcUa.Cluster.Tests</RootNamespace>
|
||||||
|
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="xunit.v3"/>
|
||||||
|
<PackageReference Include="Shouldly"/>
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
|
||||||
|
<PackageReference Include="xunit.runner.visualstudio">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\src\Core\ZB.MOM.WW.OtOpcUa.Cluster\ZB.MOM.WW.OtOpcUa.Cluster.csproj"/>
|
||||||
|
<ProjectReference Include="..\..\..\src\Core\ZB.MOM.WW.OtOpcUa.Commons\ZB.MOM.WW.OtOpcUa.Commons.csproj"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<!-- OpenTelemetry.Api advisory inherits from Akka.Cluster.Hosting (see Cluster.csproj). -->
|
||||||
|
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-g94r-2vxg-569j"/>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user