// Copyright 2020-2025 The NATS Authors
// Licensed under the Apache License, Version 2.0
namespace ZB.MOM.NatsNet.Server.IntegrationTests.Helpers;
///
/// 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.
///
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;
}
///
/// Creates a JetStream cluster with the given number of servers.
/// Throws if no cluster is available.
///
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.");
}
///
/// Creates a JetStream cluster with the specified configuration template.
///
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;
}
}
}
///
/// Thrown when a test cluster is not available for integration testing.
///
public sealed class ClusterNotAvailableException : Exception
{
public ClusterNotAvailableException(string message) : base(message) { }
}