|
|
|
@@ -328,8 +328,13 @@ func TestEachTemplateIsPlannedUnderTheModulesNames(t *testing.T) {
|
|
|
|
|
refused string
|
|
|
|
|
}{
|
|
|
|
|
{name: "state", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"history": "5"}),
|
|
|
|
|
objects: "key-value mesh-knowledge_drafts {64 MiB, age 0, history 5, new, size 262144}",
|
|
|
|
|
objects: "key-value mesh-knowledge_drafts {64 MiB, age 0, history 5, new, size 262144}; object-store mesh-knowledge_drafts-objects {16 MiB, age 0, history 0, new, size 0}",
|
|
|
|
|
binding: "bucket mesh-knowledge_drafts"},
|
|
|
|
|
{name: "state naming objects-max-mib (§591)", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"objects-max-mib": "512"}),
|
|
|
|
|
objects: "key-value mesh-knowledge_drafts {64 MiB, age 0, history 1, new, size 262144}; object-store mesh-knowledge_drafts-objects {512 MiB, age 0, history 0, new, size 0}",
|
|
|
|
|
binding: "bucket mesh-knowledge_drafts"},
|
|
|
|
|
{name: "state naming objects-max-mib 0", entry: entry("drafts", catalogue.StorageKeyValue, catalogue.TemplateState, map[string]string{"objects-max-mib": "0"}),
|
|
|
|
|
refused: "not a size above 0"},
|
|
|
|
|
{name: "events, default age and cap", entry: entry("events", catalogue.StorageStream, catalogue.TemplateEvents, nil),
|
|
|
|
|
objects: "stream mesh-knowledge_events [mesh.bus.mesh-knowledge.events.>] {1024 MiB, age 604800, history 0, old, size 0}",
|
|
|
|
|
binding: "stream mesh-knowledge_events on mesh.bus.mesh-knowledge.events"},
|
|
|
|
@@ -434,7 +439,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
k.Heard(Accepted{Module: "m", Digest: "d1", Revision: 3, BusState: []catalogue.BusStateEntry{drafts, log}})
|
|
|
|
|
k.Heard(Accepted{Module: "m", Digest: "d1", Revision: 3, BusState: []catalogue.BusStateEntry{drafts, log}})
|
|
|
|
|
if want := "[KV_m_drafts m_log]"; fmt.Sprint(bus.created) != want {
|
|
|
|
|
if want := "[KV_m_drafts OBJ_m_drafts-objects m_log]"; fmt.Sprint(bus.created) != want {
|
|
|
|
|
t.Errorf("created %v, want %s", bus.created, want)
|
|
|
|
|
}
|
|
|
|
|
if want := "[created m drafts created m log]"; fmt.Sprint(out.events) != want {
|
|
|
|
@@ -455,7 +460,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
k.Sends("m")
|
|
|
|
|
k.Heard(Accepted{Module: "m", Digest: "d1", Revision: 3, BusState: []catalogue.BusStateEntry{drafts}})
|
|
|
|
|
k.Sends("m")
|
|
|
|
|
if want := "[OBJ_m_sent-objects KV_m_drafts]"; fmt.Sprint(bus.created) != want {
|
|
|
|
|
if want := "[OBJ_m_sent-objects KV_m_drafts OBJ_m_drafts-objects]"; fmt.Sprint(bus.created) != want {
|
|
|
|
|
t.Fatalf("created %v, want %s", bus.created, want)
|
|
|
|
|
}
|
|
|
|
|
if s := bus.held["OBJ_m_sent-objects"]; s.MaxBytes != 256*MiB || s.MaxAgeSeconds != 7*24*3600 || s.Discard != DiscardNew {
|
|
|
|
@@ -543,10 +548,22 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
t.Errorf("said %v %v: cleared once asked as held", out.events, out.conds)
|
|
|
|
|
}
|
|
|
|
|
}},
|
|
|
|
|
{"a bus that holds an entry the keeper never made is taken as made", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
|
|
|
|
{"a state made before its objects store existed gets the store and its binding said again (§58)", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
|
|
|
|
p, _ := PlanOf("m", drafts)
|
|
|
|
|
bus.held["KV_m_drafts"] = p.Objects[0].Settings
|
|
|
|
|
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{drafts}})
|
|
|
|
|
out.reset()
|
|
|
|
|
bus.created = nil
|
|
|
|
|
delete(bus.held, "OBJ_m_drafts-objects")
|
|
|
|
|
k.CheckAll()
|
|
|
|
|
if fmt.Sprint(bus.created) != "[OBJ_m_drafts-objects]" || fmt.Sprint(out.events) != "[created m drafts]" || out.bodies[0].Binding.Objects != "m_drafts-objects" {
|
|
|
|
|
t.Errorf("created %v, said %v: the missing store made, its binding said again", bus.created, out.events)
|
|
|
|
|
}
|
|
|
|
|
}},
|
|
|
|
|
{"a bus that holds an entry the keeper never made is taken as made", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
|
|
|
|
p, _ := PlanOf("m", drafts)
|
|
|
|
|
bus.held["KV_m_drafts"], bus.held["OBJ_m_drafts-objects"] = p.Objects[0].Settings, p.Objects[1].Settings
|
|
|
|
|
k.Heard(Accepted{Module: "m", Revision: 1, BusState: []catalogue.BusStateEntry{drafts}})
|
|
|
|
|
if len(bus.created) != 0 || fmt.Sprint(out.events) != "[created m drafts]" {
|
|
|
|
|
t.Errorf("created %v, said %v: its binding said, nothing made twice", bus.created, out.events)
|
|
|
|
|
}
|
|
|
|
@@ -696,7 +713,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
bus.snaps = nil
|
|
|
|
|
out.reset()
|
|
|
|
|
got := put(Request{ID: "r2", Verb: VerbDrop, Module: "m", Local: "drafts", Ask: "bus-1", Caller: "person.jo", Why: "unused"})
|
|
|
|
|
if got.Error != "" || fmt.Sprint(bus.snaps) != "[[KV_m_drafts]]" || fmt.Sprint(bus.deleted) != "[KV_m_drafts]" ||
|
|
|
|
|
if got.Error != "" || fmt.Sprint(bus.snaps) != "[[KV_m_drafts OBJ_m_drafts-objects]]" || fmt.Sprint(bus.deleted) != "[KV_m_drafts OBJ_m_drafts-objects]" ||
|
|
|
|
|
fmt.Sprint(out.events) != "[dropped m drafts]" || len(acts) != 1 || !strings.Contains(acts[0], "nats_drop: dropped drafts of m") ||
|
|
|
|
|
!strings.Contains(acts[0], "person.jo") {
|
|
|
|
|
t.Errorf("ended %+v, snapshots %v, deleted %v, said %v, recorded %v", got, bus.snaps, bus.deleted, out.events, acts)
|
|
|
|
@@ -733,7 +750,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
out.reset()
|
|
|
|
|
k.ActOnRequests()
|
|
|
|
|
got := get("r10")
|
|
|
|
|
if got.Path != "/snapshots/KV_m_drafts.tar" || got.Size != 100 || !strings.HasPrefix(got.Digest, "sha256:") || !got.Protected || got.Error != "" {
|
|
|
|
|
if got.Path != "/snapshots/KV_m_drafts+OBJ_m_drafts-objects.tar" || got.Size != 100 || !strings.HasPrefix(got.Digest, "sha256:") || !got.Protected || got.Error != "" {
|
|
|
|
|
t.Fatalf("the drop's record: %+v", got)
|
|
|
|
|
}
|
|
|
|
|
findings := k.Finding.(*findingLog)
|
|
|
|
@@ -753,7 +770,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
k.Now = func() time.Time { return base.AddDate(0, 0, 91) }
|
|
|
|
|
findings.calls = nil
|
|
|
|
|
k.ExpireSnapshots()
|
|
|
|
|
if _, _, found, _ := store.Get(StateRequests, "r10"); found || fmt.Sprint(files.removed) != "[/snapshots/m_log.tar /snapshots/KV_m_drafts.tar]" ||
|
|
|
|
|
if _, _, found, _ := store.Get(StateRequests, "r10"); found || fmt.Sprint(files.removed) != "[/snapshots/m_log.tar /snapshots/KV_m_drafts+OBJ_m_drafts-objects.tar]" ||
|
|
|
|
|
len(journal) != 1 || !strings.Contains(journal[0], "past its 90 days") || fmt.Sprint(findings.calls) != "[clear module.nats.snapshots.snapshots-filling]" {
|
|
|
|
|
t.Errorf("after 91 days: removed %v, journal %v, finding calls %v", files.removed, journal, findings.calls)
|
|
|
|
|
}
|
|
|
|
@@ -767,7 +784,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
{"a snapshot is restored in place, verified, refused while its names are live, cancelled, and its failure removes the partial stream", func(t *testing.T, k *Keeper, bus *fakeBus, out *said) {
|
|
|
|
|
store, files := k.Store.(*memStore), k.Files.(*memFiles)
|
|
|
|
|
out.sig = make(chan struct{}, 8)
|
|
|
|
|
path := "/snapshots/KV_m_drafts.tar"
|
|
|
|
|
path := "/snapshots/KV_m_drafts+OBJ_m_drafts-objects.tar"
|
|
|
|
|
bus.snapStreams = map[string][]string{path: {"KV_m_drafts"}}
|
|
|
|
|
files.missing = map[string]bool{"/snapshots/gone.tar": true}
|
|
|
|
|
digest := "sha256:" + hex.EncodeToString([]byte(path))
|
|
|
|
@@ -942,13 +959,13 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
_ = json.Unmarshal(raw, &got)
|
|
|
|
|
return got
|
|
|
|
|
}
|
|
|
|
|
if got := put("r5"); got.Error != "" || len(bus.deleted) != 1 {
|
|
|
|
|
if got := put("r5"); got.Error != "" || len(bus.deleted) != 2 {
|
|
|
|
|
t.Fatalf("the first drop: %+v, deleted %v", got, bus.deleted)
|
|
|
|
|
}
|
|
|
|
|
// The entry is asked for and orphaned again, so a second drop would remove it: the spent warrant refuses it.
|
|
|
|
|
k.Heard(Accepted{Module: "m", Revision: 3, BusState: []catalogue.BusStateEntry{drafts, log}})
|
|
|
|
|
k.Heard(Accepted{Module: "m", Revision: 4, BusState: []catalogue.BusStateEntry{log}})
|
|
|
|
|
if got := put("r6"); !strings.Contains(got.Error, "already acted (drop of m's drafts, request r5") || len(bus.deleted) != 1 {
|
|
|
|
|
if got := put("r6"); !strings.Contains(got.Error, "already acted (drop of m's drafts, request r5") || len(bus.deleted) != 2 {
|
|
|
|
|
t.Errorf("the second request on the same warrant: %+v, deleted %v", got, bus.deleted)
|
|
|
|
|
}
|
|
|
|
|
if raw, _, found, _ := store.Get(StateSpent, "bus-5"); !found || !strings.Contains(string(raw), `"request":"r5"`) {
|
|
|
|
@@ -960,7 +977,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
for _, key := range keys {
|
|
|
|
|
_ = store.Delete(StateRequests, key)
|
|
|
|
|
}
|
|
|
|
|
if got := put("r6b"); !strings.Contains(got.Error, "already acted") || len(bus.deleted) != 1 {
|
|
|
|
|
if got := put("r6b"); !strings.Contains(got.Error, "already acted") || len(bus.deleted) != 2 {
|
|
|
|
|
t.Errorf("with requests wiped, the spent warrant: %+v, deleted %v", got, bus.deleted)
|
|
|
|
|
}
|
|
|
|
|
}},
|
|
|
|
@@ -1080,7 +1097,7 @@ func TestTheKeeperMakesWhatAVerdictAsksForAndSaysIt(t *testing.T) {
|
|
|
|
|
raw, _, _, _ = store.Get(StateRequests, "r9")
|
|
|
|
|
var got Request
|
|
|
|
|
_ = json.Unmarshal(raw, &got)
|
|
|
|
|
if got.Outcome != "the first view answered at revision 8" || fmt.Sprint(bus.created) != "[KV_m_drafts]" ||
|
|
|
|
|
if got.Outcome != "the first view answered at revision 8" || fmt.Sprint(bus.created) != "[KV_m_drafts OBJ_m_drafts-objects]" ||
|
|
|
|
|
len(acts) != 1 || !strings.Contains(acts[0], "nats_first_view_again: asked mesh-delivery-indexer.indexer_bus_state again by hand") {
|
|
|
|
|
t.Errorf("ended %+v, created %v, recorded %v", got, bus.created, acts)
|
|
|
|
|
}
|
|
|
|
|