Make configuration values injectable rather than hardcoded
Add config structs with sensible defaults for tunable parameters: - JetStreamConfig for stream retention (1 year) and replica count (1) - HashRingConfig for virtual nodes per physical node (150) - ShardConfig for shard count (1024) and replication factor (1) Each component gets a new WithConfig constructor that accepts custom configuration, while the original constructors continue to work with defaults. Zero values in configs fall back to defaults for backward compatibility. Closes #38 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit was merged in pull request #43.
This commit is contained in:
46
store/config_test.go
Normal file
46
store/config_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestDefaultJetStreamConfig(t *testing.T) {
|
||||
config := DefaultJetStreamConfig()
|
||||
|
||||
if config.StreamRetention != DefaultStreamRetention {
|
||||
t.Errorf("expected StreamRetention=%v, got %v", DefaultStreamRetention, config.StreamRetention)
|
||||
}
|
||||
if config.ReplicaCount != DefaultReplicaCount {
|
||||
t.Errorf("expected ReplicaCount=%d, got %d", DefaultReplicaCount, config.ReplicaCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJetStreamConfigDefaults(t *testing.T) {
|
||||
t.Run("default stream retention is 1 year", func(t *testing.T) {
|
||||
expected := 365 * 24 * time.Hour
|
||||
if DefaultStreamRetention != expected {
|
||||
t.Errorf("expected DefaultStreamRetention=%v, got %v", expected, DefaultStreamRetention)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("default replica count is 1", func(t *testing.T) {
|
||||
if DefaultReplicaCount != 1 {
|
||||
t.Errorf("expected DefaultReplicaCount=1, got %d", DefaultReplicaCount)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestJetStreamConfigCustomValues(t *testing.T) {
|
||||
config := JetStreamConfig{
|
||||
StreamRetention: 30 * 24 * time.Hour, // 30 days
|
||||
ReplicaCount: 3,
|
||||
}
|
||||
|
||||
if config.StreamRetention != 30*24*time.Hour {
|
||||
t.Errorf("expected StreamRetention=30 days, got %v", config.StreamRetention)
|
||||
}
|
||||
if config.ReplicaCount != 3 {
|
||||
t.Errorf("expected ReplicaCount=3, got %d", config.ReplicaCount)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user