allow max consumers to be set

Signed-off-by: R.I.Pienaar <rip@devco.net>
This commit is contained in:
R.I.Pienaar
2020-07-24 15:24:27 +02:00
parent aa67270ea5
commit ca0dc72841
2 changed files with 29 additions and 3 deletions

View File

@@ -796,10 +796,8 @@ func (jsa *jsAccount) checkLimits(config *StreamConfig) error {
return fmt.Errorf("replicas setting of %d not allowed", config.Replicas)
}
// Check MaxConsumers
if config.MaxConsumers > 0 && config.MaxConsumers > jsa.limits.MaxConsumers {
if config.MaxConsumers > 0 && jsa.limits.MaxConsumers > 0 && config.MaxConsumers > jsa.limits.MaxConsumers {
return fmt.Errorf("maximum consumers exceeds account limit")
} else {
config.MaxConsumers = jsa.limits.MaxConsumers
}
// Check storage, memory or disk.
if config.MaxBytes > 0 {

View File

@@ -699,6 +699,34 @@ func TestJetStreamAddStreamBadSubjects(t *testing.T) {
expectAPIErr(server.StreamConfig{Name: "MyStream", Subjects: []string{".>"}})
}
func TestJetStreamAddStreamMaxConsumers(t *testing.T) {
s := RunBasicJetStreamServer()
defer s.Shutdown()
if config := s.JetStreamConfig(); config != nil {
defer os.RemoveAll(config.StoreDir)
}
nc := clientConnectToServer(t, s)
defer nc.Close()
cfg := &server.StreamConfig{
Name: "MAXC",
Subjects: []string{"in.maxc.>"},
MaxConsumers: 1,
}
acc := s.GlobalAccount()
mset, err := acc.AddStream(cfg)
if err != nil {
t.Fatalf("Unexpected error adding stream: %v", err)
}
if mset.Config().MaxConsumers != 1 {
t.Fatalf("Expected 1 MaxConsumers, got %d", mset.Config().MaxConsumers)
}
}
func TestJetStreamAddStreamOverlappingSubjects(t *testing.T) {
mconfig := &server.StreamConfig{
Name: "ok",