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

Function TestKeyValueDeleteTombstones

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

Source from the content-addressed store, hash-verified

877}
878
879func TestKeyValueDeleteTombstones(t *testing.T) {
880 s := RunBasicJetStreamServer()
881 defer shutdownJSServerAndRemoveStorage(t, s)
882
883 nc, js := jsClient(t, s)
884 defer nc.Close()
885 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
886 defer cancel()
887
888 kv, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: "KVS", History: 10})
889 expectOk(t, err)
890
891 put := func(key, value string) {
892 t.Helper()
893 _, err := kv.Put(ctx, key, []byte(value))
894 expectOk(t, err)
895 }
896
897 v := strings.Repeat("ABC", 33)
898 for i := 1; i <= 100; i++ {
899 put(fmt.Sprintf("key-%d", i), v)
900 }
901 // Now delete them.
902 for i := 1; i <= 100; i++ {
903 err := kv.Delete(ctx, fmt.Sprintf("key-%d", i))
904 expectOk(t, err)
905 }
906
907 // Now cleanup.
908 err = kv.PurgeDeletes(ctx, jetstream.DeleteMarkersOlderThan(-1))
909 expectOk(t, err)
910
911 si, err := js.Stream(ctx, "KV_KVS")
912 expectOk(t, err)
913 if si.CachedInfo().State.Msgs != 0 {
914 t.Fatalf("Expected no stream msgs to be left, got %d", si.CachedInfo().State.Msgs)
915 }
916
917 // Try with context
918 ctx, cancel = context.WithTimeout(context.Background(), 1*time.Second)
919 defer cancel()
920 err = kv.PurgeDeletes(nats.Context(ctx))
921 expectOk(t, err)
922}
923
924func TestKeyValuePurgeDeletesMarkerThreshold(t *testing.T) {
925 s := RunBasicJetStreamServer()

Callers

nothing calls this directly

Calls 14

DeleteMarkersOlderThanTypeAlias · 0.92
FatalfMethod · 0.80
RunBasicJetStreamServerFunction · 0.70
jsClientFunction · 0.70
expectOkFunction · 0.70
CreateKeyValueMethod · 0.65
PutMethod · 0.65
DeleteMethod · 0.65
PurgeDeletesMethod · 0.65
StreamMethod · 0.65
CachedInfoMethod · 0.65

Tested by

no test coverage detected