Commit Graph

338 Commits

Author SHA1 Message Date
Joseph Doherty
a41d0f453c feat(cluster): add placement engine with topology-aware peer selection (B9-prep) 2026-02-24 17:09:32 -05:00
Joseph Doherty
824e0b3607 feat(raft): add membership proposals, snapshot checkpoints, and log compaction (B4+B5+B6)
- ProposeAddPeerAsync/ProposeRemovePeerAsync: single-change-at-a-time membership
  changes through RAFT consensus (Go ref: raft.go:961-1019)
- RaftLog.Compact: removes entries up to given index for log compaction
- CreateSnapshotCheckpointAsync: creates snapshot and compacts log in one operation
- DrainAndReplaySnapshotAsync: drains commit queue, installs snapshot, resets indices
- Pre-vote protocol skipped (Go NATS doesn't implement it either)
- 23 new tests in RaftMembershipAndSnapshotTests
2026-02-24 17:08:59 -05:00
Joseph Doherty
5b706c969d feat(raft): add commit queue, election timers, and peer health tracking (B1+B2+B3)
- CommitQueue<T>: channel-based queue for committed entries awaiting state machine application
- RaftPeerState: tracks replication and health state (nextIndex, matchIndex, lastContact)
- RaftNode: CommitIndex/ProcessedIndex tracking, election timer with randomized 150-300ms interval,
  peer state integration with heartbeat and replication updates
- 52 new tests across RaftApplyQueueTests, RaftElectionTimerTests, RaftHealthTests
2026-02-24 17:01:00 -05:00
Joseph Doherty
579063dabd test(parity): port 373 Go tests across protocol and services subsystems (C11+E15)
Protocol (C11):
- ClientProtocolGoParityTests: 45 tests (header stripping, tracing, limits, NRG)
- ConsumerGoParityTests: 60 tests (filters, actions, pinned, priority groups)
- JetStreamGoParityTests: 38 tests (stream CRUD, purge, mirror, retention)

Services (E15):
- MqttGoParityTests: 65 tests (packet parsing, QoS, retained, sessions)
- WsGoParityTests: 58 tests (compression, JWT auth, frame encoding)
- EventGoParityTests: 56 tests (event DTOs, serialization, health checks)
- AccountGoParityTests: 28 tests (route mapping, system account, limits)
- MonitorGoParityTests: 23 tests (connz filtering, pagination, sort)

DB: 1,148/2,937 mapped (39.1%), up from 1,012 (34.5%)
2026-02-24 16:52:15 -05:00
Joseph Doherty
94878d3dcc feat(monitoring+events): add connz filtering, event payloads, and message trace context (E12+E13+E14)
- Add ConnzHandler with sorting, filtering, pagination, CID lookup, and closed connection ring buffer
- Add full Go events.go parity types (ConnectEventMsg, DisconnectEventMsg, ServerStatsMsg, etc.)
- Add MessageTraceContext for per-message trace propagation with header parsing
- 74 new tests (17 ConnzFilter + 16 EventPayload + 41 MessageTraceContext)
2026-02-24 16:17:21 -05:00
Joseph Doherty
37d3cc29ea feat(networking): add leaf subject filtering and port networking Go tests (D6+D7)
D6: Add ExportSubjects/ImportSubjects allow-lists to LeafHubSpokeMapper alongside
existing DenyExports/DenyImports deny-lists. When an allow-list is non-empty, subjects
must match at least one allow pattern; deny always takes precedence. Updated
LeafNodeOptions, LeafHubSpokeMapper (5-arg constructor), and LeafNodeManager to wire
through the new allow-lists. Added 13 new unit + integration tests covering allow-list
semantics, deny precedence, bidirectional filtering, and wire-level propagation.

D7: Existing NetworkingGoParityTests.cs (50 tests) covers gateway interest mode,
route pool accounting, and leaf node connections. Parity DB already up to date.
2026-02-24 16:07:33 -05:00
Joseph Doherty
02531dda58 feat(config+ws): add TLS cert reload, WS compression negotiation, WS JWT auth (E9+E10+E11)
E9: TLS Certificate Reload
- Add TlsCertificateProvider with Interlocked-swappable cert field
- New connections get current cert, existing connections keep theirs
- ConfigReloader.ReloadTlsCertificate rebuilds SslServerAuthenticationOptions
- NatsServer.ApplyConfigChanges triggers TLS reload on TLS config changes
- 11 tests covering cert swap, versioning, thread safety, config diff

E10: WebSocket Compression Negotiation (RFC 7692)
- Add WsDeflateNegotiator to parse Sec-WebSocket-Extensions parameters
- Parse server_no_context_takeover, client_no_context_takeover,
  server_max_window_bits, client_max_window_bits
- WsDeflateParams record struct with ToResponseHeaderValue()
- NATS always enforces no_context_takeover (matching Go server)
- WsUpgrade returns negotiated WsDeflateParams in upgrade result
- 22 tests covering parameter parsing, clamping, response headers

E11: WebSocket JWT Authentication
- Extract JWT from Authorization header (Bearer token), cookie, or ?jwt= query param
- Priority: Authorization header > cookie > query parameter
- WsUpgrade.TryUpgradeAsync now parses query string from request URI
- Add FailUnauthorizedAsync for 401 responses
- 24 tests covering all JWT extraction sources and priority ordering
2026-02-24 16:03:46 -05:00
Joseph Doherty
c6ecbbfbcc feat(config): add system account, SIGHUP reload, and auth change propagation (E6+E7+E8)
E6: Add IsSystemAccount property to Account, mark $SYS account as system,
add IsSystemSubject/IsSubscriptionAllowed/GetSubListForSubject helpers to
route $SYS.> subjects to the system account's SubList and block non-system
accounts from subscribing.

E7: Add ConfigReloader.ReloadAsync and ApplyDiff for structured async reload,
add ConfigReloadResult/ConfigApplyResult types. SIGHUP handler already wired
via PosixSignalRegistration in HandleSignals.

E8: Add PropagateAuthChanges to re-evaluate connected clients after auth
config reload, disconnecting clients whose credentials no longer pass
authentication with -ERR 'Authorization Violation'.
2026-02-24 15:48:48 -05:00
Joseph Doherty
18acd6f4e2 feat(jetstream): add mirror sync loop and source coordination with filtering (C9+C10) 2026-02-24 15:41:35 -05:00
Joseph Doherty
6ad8ab69bf docs: update test_parity.db with C7+C8, D4+D5, E4+E5 Go parity mappings 2026-02-24 15:35:55 -05:00
Joseph Doherty
1da1849ed6 docs: update test_parity.db with E4+E5 Go parity mappings 2026-02-24 15:31:48 -05:00
Joseph Doherty
235971ddcc feat(auth): add account import/export cycle detection and JetStream limits (E4+E5)
E4: AccountImportExport with DFS cycle detection for service imports,
RemoveServiceImport/RemoveStreamImport, and ValidateImport authorization.
E5: AccountLimits record with MaxStorage/MaxConsumers/MaxAckPending,
TryReserveConsumer/ReleaseConsumer, TrackStorageDelta on Account.
20 new tests, all passing.
2026-02-24 15:25:12 -05:00
Joseph Doherty
efd053ba60 feat(networking): expand gateway reply mapper and add leaf solicited connections (D4+D5)
D4: Add hash segment support to ReplyMapper (_GR_.{cluster}.{hash}.{reply}),
FNV-1a ComputeReplyHash, TryExtractClusterId/Hash, legacy format compat.
D5: Add ConnectSolicitedAsync with exponential backoff (1s-60s cap),
JetStreamDomain propagation in LEAF handshake, LeafNodeOptions.JetStreamDomain.
2026-02-24 15:22:24 -05:00
Joseph Doherty
7116988d03 feat(jetstream): add API leader forwarding and stream purge options (C7+C8)
C7: JetStreamApiRouter now checks leadership before mutating operations.
Non-leader nodes return error code 10003 with a leader_hint field.
JetStreamMetaGroup gains IsLeader() and Leader for cluster-aware routing.

C8: StreamApiHandlers.HandlePurge accepts PurgeRequest options (filter,
seq, keep). StreamManager.PurgeEx implements subject-filtered purge,
sequence-based purge, keep-last-N, and filter+keep combinations.
2026-02-24 15:22:22 -05:00
Joseph Doherty
d259a2d03e docs: update test_parity.db with C5+C6, D2+D3, E2+E3 Go parity mappings
- Consumer priority groups and pull timeout/filter mappings
- Route pool accounting and S2 compression mappings
- MQTT session persistence, QoS 2, and retained message mappings
- Total mapped: 924 → 938 of 2,937
2026-02-24 15:14:42 -05:00
Joseph Doherty
e49e5895c1 feat(mqtt): add session persistence, QoS 2 state machine, and retained store (E2+E3)
Add MqttSessionStore with save/load/delete/list operations, flapper
detection (backoff on rapid reconnects), and TimeProvider-based testing.
Add MqttRetainedStore for per-topic retained messages with MQTT wildcard
matching (+/# filters). Add MqttQos2StateMachine tracking the full
PUBREC/PUBREL/PUBCOMP flow with duplicate rejection and timeout detection.

19 new tests: 9 session persistence, 10 QoS/retained message tests.
2026-02-24 15:13:34 -05:00
Joseph Doherty
662b2e0d87 feat(consumers): add PriorityGroupManager and PullConsumer timeout/compiled filters (C5+C6) 2026-02-24 15:11:30 -05:00
Joseph Doherty
386cc201de feat(routes): add pool accounting per account and S2 compression codec (D2+D3)
D2: Add FNV-1a-based ComputeRoutePoolIdx to RouteManager matching Go's
route.go:533-545, with PoolIndex on RouteConnection and account-aware
ForwardRoutedMessageAsync that routes to the correct pool connection.

D3: Replace DeflateStream with IronSnappy in RouteCompressionCodec, add
RouteCompressionLevel enum, NegotiateCompression, and IsCompressed
detection. 17 new tests (6 pool + 11 compression), all passing.
2026-02-24 15:11:20 -05:00
Joseph Doherty
21d10582b3 docs: update test_parity.db with C3+C4, D1, E1 Go parity mappings
- 10 consumer delivery/redelivery mappings (PushConsumer, RedeliveryTracker)
- 7 gateway interest-only mode mappings (GatewayInterestTracker)
- 10 MQTT binary parser mappings (MqttBinaryDecoder)
- Total mapped: 909 → 924 of 2,937
2026-02-24 15:04:22 -05:00
Joseph Doherty
612b15c781 feat: add PushConsumer delivery loop and RedeliveryTracker (C3+C4)
C3 – PushConsumerEngine delivery dispatch:
- Add DeliverSubject property (mirrors consumer.go:1131 dsubj field)
- Add StartDeliveryLoop / StopDeliveryLoop: background Task that drains
  ConsumerHandle.PushFrames and calls a sendMessage delegate per frame
- Delivery loop honours AvailableAtUtc for rate-limiting (consumer.go:5120)
- Data frames: HMSG headers Nats-Sequence, Nats-Time-Stamp, Nats-Subject
  (stream.go:586 JSSequence / JSTimeStamp / JSSubject constants)
- Flow-control frames: "NATS/1.0 100 FlowControl Request" (consumer.go:5501)
- Heartbeat frames: "NATS/1.0 100 Idle Heartbeat" (consumer.go:5222)
- Add DeliverSubject field to ConsumerConfig (consumer.go:115)

C4 – RedeliveryTracker with backoff schedules:
- Schedule(seq, deliveryCount, ackWaitMs): computes deadline using backoff
  array indexed by (deliveryCount-1), clamped at last entry (consumer.go:5540)
- GetDue(): returns sequences whose deadline has passed
- Acknowledge(seq): removes sequence from tracking
- IsMaxDeliveries(seq, maxDeliver): checks threshold for drop decision
- Empty backoff array falls back to ackWaitMs

Tests: 7 PushConsumerDelivery tests + 10 RedeliveryTracker tests (17 total)
2026-02-24 15:01:15 -05:00
Joseph Doherty
27faf64548 feat(gateways): implement GatewayInterestTracker for interest-only mode state machine (D1)
Ports the gateway interest-only mode from Go (gateway.go:100-150, 1500-1600):

- Add GatewayInterestTracker with Optimistic/Transitioning/InterestOnly modes
- In Optimistic mode, track no-interest set; switch to InterestOnly when set
  exceeds threshold (default 1000, matching Go defaultGatewayMaxRUnsubThreshold)
- In InterestOnly mode, only forward subjects with tracked RS+ interest;
  use SubjectMatch.MatchLiteral for wildcard pattern support
- Integrate tracker into GatewayConnection: A+/A- messages update tracker,
  SendMessageAsync skips send when ShouldForward returns false
- Expose InterestTracker property on GatewayConnection for observability
- Add 13 unit tests covering all 8 specified behaviors plus edge cases
2026-02-24 15:00:23 -05:00
Joseph Doherty
b6c373c5e4 feat(mqtt): add MqttBinaryDecoder with CONNECT/PUBLISH/SUBSCRIBE parsing and 27 tests
Port binary MQTT 3.1.1 packet body decoding from Go mqtt.go (~lines 700–1500, 2200).
MqttBinaryDecoder parses CONNECT (protocol name, connect flags, keepalive, client ID,
will topic/message, username, password), PUBLISH (topic, packet ID for QoS>0, DUP/
RETAIN flags, application payload), and SUBSCRIBE (packet ID, topic-filter + QoS list).
Adds TranslateFilterToNatsSubject for simple MQTT wildcard conversion (+ → *, # → >,
/ → .). All 27 tests in MqttBinaryParserTests pass.
2026-02-24 14:58:48 -05:00
Joseph Doherty
a201e8019a test(config): port Go opts_test.go config parsing tests
Adds OptsGoParityTests.cs with 49 tests porting 15 unmapped Go test
functions from server/opts_test.go: random port semantics, listen port
config variants, multiple users, authorization block parsing, options
defaults (TestDefaultSentinel), write_deadline parsing, path handling,
variable/env-var substitution chains, and unknown field tolerance.
2026-02-24 14:54:00 -05:00
Joseph Doherty
adee23f853 docs: update test_parity.db with AckProcessor Go parity mappings 2026-02-24 14:52:16 -05:00
Joseph Doherty
a7f1243d4f feat(consumers): add NAK/TERM/PROGRESS ack types with backoff (Go parity) 2026-02-24 14:49:20 -05:00
Joseph Doherty
4092e15ace docs: update test_parity.db with FileStore Go parity mappings
Map 36 additional Go tests from filestore_test.go to .NET equivalents
in FileStoreGoParityTests.cs. FileStore mapped: 73 -> 109. Total: 893/2937.
2026-02-24 14:44:09 -05:00
Joseph Doherty
a245bd75a7 feat(storage): port FileStore Go tests and add sync methods (Go parity)
Add 67 Go-parity tests from filestore_test.go covering:
- SkipMsg/SkipMsgs sequence reservation
- RemoveMsg/EraseMsg soft-delete
- LoadMsg/LoadLastMsg/LoadNextMsg message retrieval
- AllLastSeqs/MultiLastSeqs per-subject last sequences
- SubjectForSeq reverse lookup
- NumPending with filters and last-per-subject mode
- Recovery watermark preservation after purge
- FastState NumDeleted/LastTime correctness
- PurgeEx with empty subject + keep parameter
- Compact _first watermark tracking
- Multi-block operations and state verification

Implements missing IStreamStore sync methods on FileStore:
RemoveMsg, EraseMsg, SkipMsg, SkipMsgs, LoadMsg, LoadLastMsg,
LoadNextMsg, AllLastSeqs, MultiLastSeqs, SubjectForSeq, NumPending.

Adds MsgBlock.WriteSkip() for tombstone sequence reservation.
Adds IDisposable to FileStore for synchronous test disposal.
2026-02-24 14:43:06 -05:00
Joseph Doherty
d0068b121f feat(storage): add write cache and TTL scheduling (Go parity)
Add MsgBlock write cache (mirrors Go's msgBlock.cache) to serve reads
for recently-written records without disk I/O; cleared on block seal via
RotateBlock. Add HashWheel-based TTL expiry in FileStore (ExpireFromWheel /
RegisterTtl), replacing the O(n) linear scan on every append with an
O(expired) wheel scan. Implement StoreMsg sync method with per-message TTL
override support. Add 10 tests covering cache hits/eviction, wheel expiry,
retention, StoreMsg seq/ts, per-msg TTL, and recovery re-registration.
2026-02-24 13:54:37 -05:00
Joseph Doherty
b0b64292b3 feat(storage): add tombstone tracking and purge operations (Go parity)
Implement PurgeEx, Compact, Truncate, FilteredState, SubjectsState,
SubjectsTotals, State, FastState, GetSeqFromTime on FileStore. Add
MsgBlock.IsDeleted, DeletedSequences, EnumerateNonDeleted. Includes
wildcard subject support via SubjectMatch for all filtered operations.
2026-02-24 13:45:17 -05:00
Joseph Doherty
2816e8f048 feat(storage): rewrite FileStore to use block-based MsgBlock storage
Replace JSONL persistence with real MsgBlock-based block files (.blk).
FileStore now acts as a block manager that creates, seals, and rotates
MsgBlocks while maintaining an in-memory cache for fast reads/queries.

Key changes:
- AppendAsync writes transformed payloads to MsgBlock via WriteAt
- Block rotation occurs when active block reaches size limit
- Recovery scans .blk files and rebuilds in-memory state from records
- Legacy JSONL migration: existing messages.jsonl data is automatically
  converted to block files on first open, then JSONL is deleted
- PurgeAsync disposes and deletes all block files
- RewriteBlocks rebuilds blocks from cache (used by trim/restore)
- InvalidDataException propagates during recovery (wrong encryption key)

MsgBlock.WriteAt added to support explicit sequence numbers and timestamps,
needed when rewriting blocks with non-contiguous sequences (after removes).

Tests updated:
- New FileStoreBlockTests.cs with 9 tests for block-specific behavior
- JetStreamFileStoreCompressionEncryptionParityTests updated to read
  FSV1 magic from .blk files instead of messages.jsonl
- JetStreamFileStoreDurabilityParityTests updated to verify .blk files
  instead of index.manifest.json

All 3,562 tests pass (3,535 passed + 27 skipped, 0 failures).
2026-02-24 12:39:32 -05:00
Joseph Doherty
09252b8c79 feat(storage): add MsgBlock block-based message storage unit
MsgBlock is the unit of storage in the file store — a single append-only
block file containing sequentially written binary message records. Blocks
are sealed (read-only) when they reach a configurable byte-size limit.

Key features:
- Write: appends MessageRecord-encoded messages with auto-incrementing
  sequence numbers and configurable first sequence offset
- Read: positional I/O via RandomAccess.Read for concurrent reader safety
- Delete: soft-delete with on-disk persistence (re-encodes flags byte +
  checksum so deletions survive recovery)
- Recovery: rebuilds in-memory index by scanning block file using
  MessageRecord.MeasureRecord for record boundary detection
- Thread safety: ReaderWriterLockSlim allows concurrent reads during writes

Also adds MessageRecord.MeasureRecord() — computes a record's byte length
by parsing varint field headers without full decode, needed for sequential
record scanning during block recovery.

Reference: golang/nats-server/server/filestore.go:217-267 (msgBlock struct)

12 tests covering write, read, delete, seal, recovery, concurrency,
and custom sequence offsets.
2026-02-24 12:21:33 -05:00
Joseph Doherty
17731e2af5 feat(storage): add binary message record encoding (Go parity)
Add MessageRecord class with Encode/Decode for the binary wire format
used in JetStream file store blocks. Uses varint-encoded lengths,
XxHash64 checksums, and a flags byte for deletion markers.

Go reference: filestore.go:6720-6724, 8180-8250, 8770-8777

13 tests covering round-trip, headers, checksum validation, corruption
detection, varint encoding, deleted flag, empty/large payloads.
2026-02-24 12:12:15 -05:00
Joseph Doherty
2a240c6355 docs: add implementation plan for all 15 structure gaps
50 tasks across 5 parallel tracks (A-E) with full TDD steps,
Go reference citations, file paths, and test_parity.db update
protocol. Task persistence file for session resumption.
2026-02-24 12:05:22 -05:00
Joseph Doherty
f1e42f1b5f docs: add full Go parity design for all 15 structure gaps
5-track parallel architecture (Storage, Consensus, Protocol,
Networking, Services) covering all CRITICAL/HIGH/MEDIUM gaps
identified in structuregaps.md. Feature-first approach with
test_parity.db updates. Targets ~1,194 additional Go test mappings.
2026-02-24 11:57:15 -05:00
Joseph Doherty
0a9db430d5 docs: add test_mappings table with FK relationships
Many-to-many mapping between go_tests and dotnet_tests via
test_mappings table. 988 mappings linking 857 Go tests to
690 .NET tests. Confidence levels: exact, comment_ref, keyword,
manual, auto.
2026-02-24 10:14:58 -05:00
Joseph Doherty
bff24d29c7 docs: add SQLite parity tracking database
test_parity.db contains go_tests (2,937 rows) and dotnet_tests
(2,966 rows) tables for querying Go-to-.NET test mapping across
Claude sessions. 857 mapped, 2,080 unmapped.
2026-02-24 10:12:42 -05:00
Joseph Doherty
0dc2b38415 docs: add Go-to-.NET gap analysis and test mapping
Research documents covering implementation gaps (structuregaps.md)
and full test function mapping (testmapping.md + CSV files) between
the Go NATS server and .NET port. 857/2937 Go tests mapped (29.2%),
2080 unmatched, 2966 .NET-only tests.
2026-02-24 10:07:29 -05:00
Joseph Doherty
1743cfc550 merge: integrate full Go parity worktree — 3,501 tests passing
Phase 1: RAFT wire format, NatsRaftTransport, JetStreamService orchestrator,
FileStore S2 compression + AEAD encryption (IronSnappy, ChaCha20/AesGcm)

Phase 2: JetStream cluster fixture + 5 cluster test suites (316 tests),
JetStream core tests (110), FileStore permutation tests (120)

Phase 3: Stress/NoRace (55), Accounts/Auth (37), Message Trace (23),
Config/Reload (40), Events (16)

Total: 895 new tests added (2,606 → 3,501)
2026-02-24 09:27:29 -05:00
Joseph Doherty
c881bf1ed8 docs: mark all 17 tasks completed in task persistence file 2026-02-24 09:25:14 -05:00
Joseph Doherty
99058350c0 feat: add stress/NoRace tests for concurrent operations (Go parity)
Adds 55 new tests across three files in a new Stress/ directory,
covering concurrent pub/sub SubList thread safety, slow consumer
detection under real NatsServer connections, and clustered JetStream
operations under concurrency. All tests carry [Trait("Category",
"Stress")] for selective execution. Go ref: norace_1_test.go,
norace_2_test.go.
2026-02-24 09:15:17 -05:00
Joseph Doherty
fde1710eb0 feat: add auth callout and account limit tests (Go parity)
Adds 37 tests in AuthCalloutTests.cs covering auth callout handler
registration/invocation, timeout, account assignment, max-connections
and max-subscriptions enforcement, user revocation (including wildcard
revocation), and cross-account service import/export communication.
2026-02-24 09:05:28 -05:00
Joseph Doherty
9317b92a9c feat: add message trace tests (Go parity)
23 tests covering MessageTraceContext population, NatsHeaderParser trace
header parsing, HPUB/HMSG Nats-Trace-Dest header propagation through
plain/wildcard/queue-group subscriptions, and server trace option
defaults. References golang/nats-server/server/msgtrace_test.go.
2026-02-24 09:03:05 -05:00
Joseph Doherty
51e47fbe67 feat: add server event and advisory tests (Go parity)
16 tests in tests/NATS.Server.Tests/Events/ServerEventTests.cs covering
server lifecycle stats, account stats isolation, slow consumer / stale
connection counters, JetStream API counters, EventSubjects format
validation, InternalEventSystem sequence generation, and
BuildEventServerInfo identity. References events_test.go.
2026-02-24 09:00:01 -05:00
Joseph Doherty
ec1a9295f9 feat: add advanced config/reload tests (Go parity)
Ports 40 tests from Go's opts_test.go and reload_test.go covering:
NatsOptions defaults, ConfigProcessor parsing round-trips,
ConfigReloader diff/validate semantics, CLI override precedence,
and runtime reload rejection of host/cluster/JetStream changes.
2026-02-24 08:58:24 -05:00
Joseph Doherty
163667bbe2 feat: add JetStream cluster consumer replication tests (Go parity)
Add 60 tests in JsClusterConsumerReplicationTests covering consumer
creation, fetch/delivery, ack tracking, leader failover, state
consistency, and edge cases. Ported from Go jetstream_cluster_2_test.go.
2026-02-24 08:39:32 -05:00
Joseph Doherty
3862f009ba feat: add JetStream cluster meta-cluster governance tests (Go parity) 2026-02-24 07:54:00 -05:00
Joseph Doherty
c33e5e3009 feat: add JetStream cluster advanced and long-running tests (Go parity)
Adds two new test files covering Task 10 of the full Go parity plan:

JsClusterAdvancedTests.cs (27 tests):
- Large 7-node cluster with R5 stream
- Stream with 20+ subjects and wildcard '>' subject
- 1000-message publish to R3 and R1 streams
- Stream state accuracy after 1000 messages
- 10 streams with mixed replica counts
- Create/publish/delete/recreate cycle (3x)
- Consumer on 1000-message stream with batch fetch
- AckAll for all 1000 messages
- Stream info consistency after 50 interleaved ops
- Meta state after creating and deleting 10 streams
- 5 independent consumers with correct pending counts
- Consumer with wildcard filter subject
- Stream update adding subjects after publishes
- Stream purge then republish
- Fetch empty after purge
- Stream delete cascades consumer removal
- Node removal preserves data reads
- Node restart lifecycle markers
- Leader stepdown with monotonic sequence verification
- Stream info after stepdown with 1000 messages

JsClusterLongRunningTests.cs (15 tests, [Trait("Category", "LongRunning")]):
- 5000 messages in R3 stream maintain consistency
- 100 sequential fetches of 50 messages each
- 50 consumers on same stream all see all messages
- 20 streams in 5-node cluster all independent
- Publish-ack-fetch cycle 100 times
- 10 stepdowns during continuous publishing
- Alternating publish and stepdown (20 iterations)
- Create-publish-delete 20 streams sequentially
- Consumer ack tracking after 10 leader failovers
- Fetch with batch=1 iterated 500 times
- Mixed operations across 5 streams
- Rapid meta stepdowns (20) with version verification
- 10000 small messages in R1 stream
- Stream with max_messages=100 enforces limit after 1000 publishes
- Consumer on max-messages stream tracks correct pending

All 42 tests pass (27 advanced + 15 long-running).
2026-02-24 07:53:50 -05:00
Joseph Doherty
5a22fd3213 feat: add JetStream cluster stream replication and placement tests (Go parity)
Adds 97 tests across two new files covering stream replication semantics
(R1/R3 creation, replica group size, publish preservation, state accuracy,
purge, update, delete, max limits, subjects, wildcards, storage type) and
placement semantics (replica caps at cluster size, various cluster sizes,
concurrent creation, stepdown resilience, long names, re-create after delete).
2026-02-24 07:53:28 -05:00
Joseph Doherty
4fa0be2281 feat: add JetStreamClusterFixture for multi-node cluster tests (Go parity)
Adds a unified JetStreamClusterFixture consolidating the capabilities of all 7
per-suite fixtures (ClusterFormationFixture, ClusterStreamFixture, LeaderFailoverFixture, etc.)
into a single reusable helper for Tasks 6-10. Includes new Go-parity helpers
(WaitOnStreamLeaderAsync, WaitOnConsumerLeaderAsync, GetConsumerLeaderId,
StepDownMetaLeader, SimulateNodeRestart, RemoveNode) matching jetstream_helpers_test.go.
27 smoke tests verify all capabilities pass.
2026-02-24 07:36:32 -05:00
Joseph Doherty
543b791cb5 feat: port remaining JetStream core tests from Go (edge cases, preconditions, direct get)
Adds 110 new tests across 5 files covering gaps identified from Go's jetstream_test.go:

- JetStreamStreamEdgeCaseTests (29 tests): max msgs/bytes enforcement, discard
  old/new policies, max msg size, max msgs per subject, sealed/deny-delete/deny-purge
  config, work queue and interest retention, state tracking, CRUD edges.

- JetStreamConsumerDeliveryEdgeTests (25 tests): AckProcessor unit tests (register,
  drop, ack floor, expiry, redelivery), push consumer heartbeat/flow-control frames,
  pull fetch no-wait, batch limit, filter delivery, wildcard filter, ack explicit
  pending tracking, ack-all clearing, work queue pull consumer.

- JetStreamPublishPreconditionTests (21 tests): expected-last-seq match/mismatch,
  duplicate window dedup acceptance/rejection, window expiry allows re-publish,
  PublishPreconditions unit tests (IsDuplicate, Record, TrimOlderThan,
  CheckExpectedLastSeq), pub ack stream/seq fields, sequential writes enforcement.

- JetStreamAccountLimitTests (17 tests): max streams per account (1/3/unlimited),
  slot freed on delete, Account.TryReserveStream/ReleaseStream unit tests,
  JetStreamStreamCount tracking, account info stream/consumer counts, stream names
  sorted, consumer names list, error code 10027 on limit exceeded.

- JetStreamDirectGetTests (18 tests): direct get by sequence (first/middle/last),
  subject preservation, non-existent sequence error, empty stream error, zero seq
  error, multiple independent retrieves, STREAM.MSG.GET API, get-after-delete,
  get-after-purge, memory storage, backend type reporting, consistency between
  direct get and stream msg get.

Go reference: golang/nats-server/server/jetstream_test.go
2026-02-24 06:47:17 -05:00