MCPcopy
hub / github.com/nats-io/nats.go / TestKeyValueHistory

Function TestKeyValueHistory

test/kv_test.go:114–150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestKeyValueHistory(t *testing.T) {
115 s := RunBasicJetStreamServer()
116 defer shutdownJSServerAndRemoveStorage(t, s)
117
118 nc, js := jsClient(t, s)
119 defer nc.Close()
120
121 kv, err := js.CreateKeyValue(&nats.KeyValueConfig{Bucket: "LIST", History: 10})
122 expectOk(t, err)
123
124 for i := 0; i < 50; i++ {
125 age := strconv.FormatUint(uint64(i+22), 10)
126 _, err := kv.Put("age", []byte(age))
127 expectOk(t, err)
128 }
129
130 vl, err := kv.History("age")
131 expectOk(t, err)
132
133 if len(vl) != 10 {
134 t.Fatalf("Expected %d values, got %d", 10, len(vl))
135 }
136 for i, v := range vl {
137 if v.Key() != "age" {
138 t.Fatalf("Expected key of %q, got %q", "age", v.Key())
139 }
140 if v.Revision() != uint64(i+41) {
141 // History of 10, sent 50..
142 t.Fatalf("Expected revision of %d, got %d", i+41, v.Revision())
143 }
144 age, err := strconv.Atoi(string(v.Value()))
145 expectOk(t, err)
146 if age != i+62 {
147 t.Fatalf("Expected data value of %d, got %d", i+22, age)
148 }
149 }
150}
151
152func TestKeyValueWatch(t *testing.T) {
153 expectUpdateF := func(t *testing.T, watcher nats.KeyWatcher) func(key, value string, revision uint64) {

Callers

nothing calls this directly

Calls 12

FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
expectOkFunction · 0.70
CreateKeyValueMethod · 0.65
PutMethod · 0.65
HistoryMethod · 0.65
KeyMethod · 0.65
RevisionMethod · 0.65
ValueMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected