The eight Go test functions H2 added become subtests of existing tests (catalogue's state test, the bundle's state test, the views test, the process state test, the testbus bus test, the seal byte-for-byte test), and four more are folded beside them (two seal, two process watch); the two TypeScript seal tests become one, and two more TypeScript tests are folded into their neighbours. No assertion is lost. Builds: design 47 H2 §819
63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package process
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
|
|
stdio "git.novox.be/novox/mesh-sdk/go"
|
|
)
|
|
|
|
// pruneKV is a fakeKV with a cap: its bytes are what its current values put (stdio.PutBytes), its Status says them
|
|
// with the cap, WatchAll hands every current value, and Purge removes a key.
|
|
type pruneKV struct {
|
|
*fakeKV
|
|
cap int64
|
|
statuss int
|
|
}
|
|
|
|
type pruneStatus struct {
|
|
jetstream.KeyValueStatus
|
|
bytes uint64
|
|
cap int64
|
|
}
|
|
|
|
func (s pruneStatus) Bytes() uint64 { return s.bytes }
|
|
func (s pruneStatus) Config() jetstream.KeyValueConfig {
|
|
return jetstream.KeyValueConfig{MaxBytes: s.cap}
|
|
}
|
|
|
|
func (f *pruneKV) held() uint64 {
|
|
f.mu.Lock()
|
|
defer f.mu.Unlock()
|
|
var n uint64
|
|
for k, v := range f.values {
|
|
n += stdio.PutBytes(k, v)
|
|
}
|
|
return n
|
|
}
|
|
|
|
func (f *pruneKV) Status(context.Context) (jetstream.KeyValueStatus, error) {
|
|
f.statuss++
|
|
return pruneStatus{bytes: f.held(), cap: f.cap}, nil
|
|
}
|
|
|
|
func (f *pruneKV) WatchAll(context.Context, ...jetstream.WatchOpt) (jetstream.KeyWatcher, error) {
|
|
f.mu.Lock()
|
|
defer f.mu.Unlock()
|
|
w := &fakeWatcher{updates: make(chan jetstream.KeyValueEntry, len(f.values)+1)}
|
|
for k, v := range f.values {
|
|
w.updates <- putEntry{fakeEntry{key: k, value: v, rev: f.revs[k]}}
|
|
}
|
|
w.updates <- nil
|
|
return w, nil
|
|
}
|
|
|
|
func (f *pruneKV) Purge(ctx context.Context, key string, _ ...jetstream.KVDeleteOpt) error {
|
|
return f.Delete(ctx, key)
|
|
}
|
|
|
|
type putEntry struct{ fakeEntry }
|
|
|
|
func (putEntry) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePut }
|