70 lines
2.0 KiB
Go
70 lines
2.0 KiB
Go
//go:build integration
|
|
|
|
package broker
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
func TestALogIsAssertedInPlaceAndNeverRemoved(t *testing.T) {
|
|
bus := aLiveBus(t)
|
|
l := Log{Module: "logtest", Name: "changes", MaxMiB: 1}
|
|
if _, err := RaiseLogs(bus, []Log{l}); err != nil {
|
|
t.Fatalf("a real server refused a module's log: %v", err)
|
|
}
|
|
js, err := jetstream.New(bus.Conn())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
ack, err := js.Publish(ctx, l.Subject()+".7", []byte(`{"op":"opened"}`))
|
|
if err != nil {
|
|
t.Fatalf("an append to the log was refused: %v", err)
|
|
}
|
|
stream, err := js.Stream(ctx, l.Stream())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
have := stream.CachedInfo().Config
|
|
want := l.Config()
|
|
if have.Storage != want.Storage || have.Retention != want.Retention || have.MaxAge != 0 ||
|
|
have.MaxMsgsPerSubject != -1 || have.MaxBytes != want.MaxBytes || have.MaxMsgSize != want.MaxMsgSize ||
|
|
have.Discard != jetstream.DiscardNew || !have.AllowDirect || !have.DenyDelete || !have.DenyPurge ||
|
|
have.Replicas != 1 || !slices.Equal(have.Subjects, want.Subjects) {
|
|
t.Fatalf("the server holds the log as %+v", have)
|
|
}
|
|
if err := stream.DeleteMsg(ctx, ack.Sequence); err == nil {
|
|
t.Fatal("an entry was deleted from a log")
|
|
}
|
|
l.MaxMiB = 2
|
|
if _, err := RaiseLogs(bus, []Log{l}); err != nil {
|
|
t.Fatalf("asserting the log again failed, so a restart would: %v", err)
|
|
}
|
|
info, err := stream.Info(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if info.Config.MaxBytes != 2*1024*1024 {
|
|
t.Fatalf("the changed cap was not brought to match: %d", info.Config.MaxBytes)
|
|
}
|
|
if info.State.Msgs < 1 {
|
|
t.Fatal("asserting the log again lost what it held")
|
|
}
|
|
undeclared, err := RaiseLogs(bus, nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.Contains(undeclared, l.Stream()) {
|
|
t.Fatalf("a log nothing declares was not reported: %v", undeclared)
|
|
}
|
|
if _, err := js.Stream(ctx, l.Stream()); err != nil {
|
|
t.Fatalf("a log nothing declares is gone: %v", err)
|
|
}
|
|
}
|