TestLockFuncWithKey tests the LockFuncWithKey method
(t *testing.T)
| 625 | |
| 626 | // TestLockFuncWithKey tests the LockFuncWithKey method |
| 627 | func TestLockFuncWithKey(t *testing.T) { |
| 628 | slm := NewShardLockMaps() |
| 629 | slm.Set("key1", "value1") |
| 630 | slm.Set("key2", "value2") |
| 631 | |
| 632 | // Test modifying a specific key's shard |
| 633 | slm.LockFuncWithKey("key1", func(data map[string]interface{}) { |
| 634 | if val, ok := data["key1"]; ok { |
| 635 | data["key1"] = val.(string) + "_modified" |
| 636 | } |
| 637 | }) |
| 638 | |
| 639 | value, ok := slm.Get("key1") |
| 640 | if !ok || value != "value1_modified" { |
| 641 | t.Error("Expected key1 to be modified") |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | // TestRLockFuncWithKey tests the RLockFuncWithKey method |
| 646 | func TestRLockFuncWithKey(t *testing.T) { |
nothing calls this directly
no test coverage detected