(t *testing.T)
| 229 | } |
| 230 | |
| 231 | func 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 | |
| 271 | func TestKeyValueWatch(t *testing.T) { |
| 272 | expectUpdateF := func(t *testing.T, watcher jetstream.KeyWatcher) func(key, value string, revision uint64) { |
nothing calls this directly
no test coverage detected