The fill was a listing of every description in the store, deleted chunks' leftovers included; a receiver reading it per chunk made one connection read about 14 MB/s. The fill is now one stream info request: its bytes, its cap, and its live subjects as the count. Builds: design 47 H H-A-227
89 lines
3.8 KiB
Go
89 lines
3.8 KiB
Go
package bus
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
// novox/hq ADR 0363 §2, §3: an event goes to the stream whose pattern carries it, as the bus matches subjects.
|
|
func TestAnEventFallsUnderAStreamsPatternAsTheBusMatchesIt(t *testing.T) {
|
|
for _, c := range []struct {
|
|
pattern, event string
|
|
want bool
|
|
}{
|
|
{"mail.*.message.added", "mail.home.message.added", true},
|
|
{"mail.*.message.added", "mail.home.message.removed", false},
|
|
{"mail.*.message.added", "mail.home.work.message.added", false},
|
|
{"mail.>", "mail.home.message.added", true},
|
|
{"mail.**", "mail.home", true},
|
|
{"mail.>", "mail", false},
|
|
{"status", "status", true},
|
|
{"status", "status.changed", false},
|
|
{"", "status", false},
|
|
} {
|
|
if got := eventMatches(c.pattern, c.event); got != c.want {
|
|
t.Errorf("%q under %q: %v, want %v", c.event, c.pattern, got, c.want)
|
|
}
|
|
}
|
|
// Design 47 G §347, §59, §462: a sent object is read by the reference that carried it, from a sender's sent store only; a
|
|
// state's objects, and a reference that is none are refused before the bus is asked.
|
|
t.Run("SentGetRefusesWhatIsNoSentObjectsReference", func(t *testing.T) {
|
|
digest := "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
|
for _, c := range []struct {
|
|
name string
|
|
req buscalls.ObjectsSentGetRequest
|
|
want string
|
|
}{
|
|
{"no digest", buscalls.ObjectsSentGetRequest{Store: "m_sent-objects", Object: "o", Size: 3}, "named by the reference"},
|
|
{"a state's objects", buscalls.ObjectsSentGetRequest{Store: "m_asks-objects", Object: "o", Size: 3, Digest: digest}, "no sent store"},
|
|
} {
|
|
_, err := (&Conn{}).SentGet(c.req)
|
|
if err == nil || !strings.Contains(err.Error(), c.want) {
|
|
t.Errorf("%s: got %v, want an error containing %q", c.name, err, c.want)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
// A membership naming no stream publishes every event on EVENTS, exactly as before (issue 725).
|
|
func TestAnEventNoStreamCarriesIsPublishedOnEvents(t *testing.T) {
|
|
mail := &Membership{Module: "mail", Streams: []StreamIssued{{Stream: "MAIL", Events: []string{"mail.*.message.added"},
|
|
Subject: "mesh.stream.mail.event.{event}"}}}
|
|
for _, c := range []struct {
|
|
m *Membership
|
|
event string
|
|
want string
|
|
}{
|
|
{nil, "mail.home.message.added", "mesh.mod.mail.event.mail.home.message.added"},
|
|
{&Membership{Module: "mail"}, "mail.home.message.added", "mesh.mod.mail.event.mail.home.message.added"},
|
|
{mail, "mail.home.message.added", "mesh.stream.mail.event.mail.home.message.added"},
|
|
{mail, "status", "mesh.mod.mail.event.status"},
|
|
} {
|
|
if got := eventSubject(c.m, "mail", c.event); got != c.want {
|
|
t.Errorf("%s: %s, want %s", c.event, got, c.want)
|
|
}
|
|
}
|
|
if got := keyOf("mesh.stream.mail.event.mail.home.message.added"); got != "mail.mail.home.message.added" {
|
|
t.Errorf("a stream's event reaches its consumer as %q, not as on EVENTS", got)
|
|
}
|
|
}
|
|
|
|
// Design 47 H lead answers H-A-227: an object store's fill is the figures the bus keeps for its stream, its live
|
|
// subjects as the count, never a count of its descriptions: a store holding twenty thousand messages, deleted chunks'
|
|
// leftovers among them, answers its bytes, its cap and its four live subjects.
|
|
func TestAnObjectStoresFillIsItsStreamsOwnFigures(t *testing.T) {
|
|
info := &jetstream.StreamInfo{
|
|
Config: jetstream.StreamConfig{MaxBytes: 8 << 30},
|
|
State: jetstream.StreamState{Msgs: 20653, Bytes: 1 << 30, NumSubjects: 4, FirstSeq: 9, LastSeq: 20661},
|
|
}
|
|
if got, want := objectsFillOf(info), (buscalls.Fill{Count: 4, Bytes: 1 << 30, MaxBytes: 8 << 30}); got != want {
|
|
t.Fatalf("fill %+v, want %+v", got, want)
|
|
}
|
|
if got := objectsFillOf(&jetstream.StreamInfo{State: jetstream.StreamState{Bytes: 7}}); got != (buscalls.Fill{Bytes: 7}) {
|
|
t.Fatalf("a store with no cap and no live subject: fill %+v", got)
|
|
}
|
|
}
|