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

Function TestKeyValueHistory

jetstream/test/kv_test.go:231–269  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

229}
230
231func TestKeyValueHistory(t *testing.T) {
232 s := RunBasicJetStreamServer()
233 defer shutdownJSServerAndRemoveStorage(t, s)
234
235 nc, js := jsClient(t, s)
236 defer nc.Close()
237 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
238 defer cancel()
239
240 kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "LIST", History: 10})
241 expectOk(t, err)
242
243 for i := 0; i < 50; i++ {
244 age := strconv.FormatUint(uint64(i+22), 10)
245 _, err := kv.Put(ctx, "age", []byte(age))
246 expectOk(t, err)
247 }
248
249 vl, err := kv.History(ctx, "age")
250 expectOk(t, err)
251
252 if len(vl) != 10 {
253 t.Fatalf("Expected %d values, got %d", 10, len(vl))
254 }
255 for i, v := range vl {
256 if v.Key() != "age" {
257 t.Fatalf("Expected key of %q, got %q", "age", v.Key())
258 }
259 if v.Revision() != uint64(i+41) {
260 // History of 10, sent 50..
261 t.Fatalf("Expected revision of %d, got %d", i+41, v.Revision())
262 }
263 age, err := strconv.Atoi(string(v.Value()))
264 expectOk(t, err)
265 if age != i+62 {
266 t.Fatalf("Expected data value of %d, got %d", i+62, age)
267 }
268 }
269}
270
271func TestKeyValueWatch(t *testing.T) {
272 expectUpdateF := func(t *testing.T, watcher jetstream.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