MCPcopy Create free account
hub / github.com/aceld/zinx / TestLockFunc

Function TestLockFunc

zutils/shard_lock_map_test.go:665–684  ·  view source on GitHub ↗

TestLockFunc tests the LockFunc method

(t *testing.T)

Source from the content-addressed store, hash-verified

663
664// TestLockFunc tests the LockFunc method
665func TestLockFunc(t *testing.T) {
666 slm := NewShardLockMaps()
667 slm.Set("key1", "value1")
668 slm.Set("key2", "value2")
669
670 // Test modifying all shards
671 slm.LockFunc(func(data map[string]interface{}) {
672 for key, val := range data {
673 if str, ok := val.(string); ok {
674 data[key] = str + "_modified"
675 }
676 }
677 })
678
679 value1, _ := slm.Get("key1")
680 value2, _ := slm.Get("key2")
681 if value1 != "value1_modified" || value2 != "value2_modified" {
682 t.Error("Expected all values to be modified")
683 }
684}
685
686// TestRLockFunc tests the RLockFunc method
687func TestRLockFunc(t *testing.T) {

Callers

nothing calls this directly

Calls 5

SetMethod · 0.95
LockFuncMethod · 0.95
GetMethod · 0.95
NewShardLockMapsFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected