Atlas › Test

TestMap_GetOrSet

Exact test identity: go.temporal.io/server/common/collection/TestMap_GetOrSet

Package
go.temporal.io/server/common/collection
Suite / test hierarchy
TestMap_GetOrSet
Test
TestMap_GetOrSet
Introduced at
sync_map.go ×1 Frontier kind: Joint frontier
Covered ranges
7
Covered lines
30
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/collection/sync_map.go 30 covered LOC · 7 ranges

Open complete file

15 }
16
17 > func NewSyncMap[K comparable, V any]() SyncMap[K, V] { sync_map.go
18 > return SyncMap[K, V]{
19 > RWMutex: &sync.RWMutex{},
20 > contents: make(map[K]V),
21 > }
22 > }
23
24 > func (m *SyncMap[K, V]) Get(key K) (value V, ok bool) { sync_map.go
25 > m.RLock()
26 > defer m.RUnlock()
27 > value, ok = m.contents[key]
28 > return
29 > }
30
31 > func (m *SyncMap[K, V]) GetOrSet(key K, value V) (v V, exist bool) { sync_map.go
32 > m.RLock()
33 > currentValue, ok := m.contents[key]
34 > m.RUnlock()
35 > if ok {
36 > return currentValue, ok sync_map.go
37 > }
38
39 > m.Lock() sync_map.go
40 > defer m.Unlock()
41 > currentValue, ok = m.contents[key]
42 > if ok {
43 return currentValue, ok
44 }
45 > m.contents[key] = value sync_map.go
46 > return value, false
47 }
48
49 > func (m *SyncMap[K, V]) Set(key K, value V) { sync_map.go
50 > m.Lock()
51 > defer m.Unlock()
52 > m.contents[key] = value
53 > }
54
55 func (m *SyncMap[K, V]) Delete(key K) {