Files
natsnet/dotnet/tests/ZB.MOM.NatsNet.Server.IntegrationTests/Helpers/TestCluster.cs
Joseph Doherty 8db4fccc95 test(batch50): port 118 JetStream cluster 1 integration tests
Ports the first 118 tests from golang/nats-server/server/jetstream_cluster_1_test.go
to C# integration tests in JetStream/JetStreamCluster1Tests.cs. Adds the
Helpers/ scaffold (IntegrationTestBase, TestCluster, NatsTestClient, CheckHelper,
ConfigHelper) and Xunit.SkippableFact package; tests skip automatically unless
NATS_INTEGRATION_TESTS=true is set.
2026-03-01 12:14:55 -05:00

76 lines
3.1 KiB
C#

// Copyright 2020-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
/// <summary>
/// Represents a test JetStream cluster. In the current integration test setup,
/// tests that use this type are skipped unless a real cluster is available.
/// This is a scaffold/stub that captures the API shape for future full implementation.
/// </summary>
public sealed class TestCluster : IDisposable
{
private readonly string _name;
private readonly int _numServers;
private bool _disposed;
public string Name => _name;
private TestCluster(string name, int numServers)
{
_name = name;
_numServers = numServers;
}
/// <summary>
/// Creates a JetStream cluster with the given number of servers.
/// Throws <see cref="ClusterNotAvailableException"/> if no cluster is available.
/// </summary>
public static TestCluster CreateJetStreamCluster(int numServers, string name = "JSC")
{
throw new ClusterNotAvailableException(
$"No JetStream cluster available. Set NATS_INTEGRATION_TESTS=true and ensure {numServers}-node cluster '{name}' is running.");
}
/// <summary>
/// Creates a JetStream cluster with the specified configuration template.
/// </summary>
public static TestCluster CreateJetStreamClusterWithTemplate(string template, int numServers, string name = "JSC")
{
throw new ClusterNotAvailableException(
$"No JetStream cluster available for template cluster '{name}'.");
}
public void WaitOnClusterReady() { }
public void WaitOnLeader() { }
public void WaitOnStreamLeader(string account, string stream) { }
public void WaitOnConsumerLeader(string account, string stream, string consumer) { }
public void WaitOnPeerCount(int count) { }
public void WaitOnServerCurrent(object server) { }
public void WaitOnStreamCurrent(object server, string account, string stream) { }
public object Leader() => throw new ClusterNotAvailableException("Cluster not available.");
public object RandomServer() => throw new ClusterNotAvailableException("Cluster not available.");
public object RandomNonLeader() => throw new ClusterNotAvailableException("Cluster not available.");
public object RandomNonStreamLeader(string account, string stream) => throw new ClusterNotAvailableException("Cluster not available.");
public object ServerByName(string name) => throw new ClusterNotAvailableException("Cluster not available.");
public object StreamLeader(string account, string stream) => throw new ClusterNotAvailableException("Cluster not available.");
public object ConsumerLeader(string account, string stream, string consumer) => throw new ClusterNotAvailableException("Cluster not available.");
public void Dispose()
{
if (!_disposed)
{
_disposed = true;
}
}
}
/// <summary>
/// Thrown when a test cluster is not available for integration testing.
/// </summary>
public sealed class ClusterNotAvailableException : Exception
{
public ClusterNotAvailableException(string message) : base(message) { }
}