-
Notifications
You must be signed in to change notification settings - Fork 199
/
shardedDataCacheNotifierMock.go
129 lines (103 loc) · 2.97 KB
/
shardedDataCacheNotifierMock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package testscommon
import (
"sync"
"github.com/multiversx/mx-chain-core-go/core/counting"
"github.com/multiversx/mx-chain-go/storage"
)
// ShardedDataCacheNotifierMock -
type ShardedDataCacheNotifierMock struct {
mutCaches sync.RWMutex
caches map[string]storage.Cacher
}
// NewShardedDataCacheNotifierMock -
func NewShardedDataCacheNotifierMock() *ShardedDataCacheNotifierMock {
return &ShardedDataCacheNotifierMock{
caches: make(map[string]storage.Cacher),
}
}
// RegisterOnAdded -
func (mock *ShardedDataCacheNotifierMock) RegisterOnAdded(_ func(key []byte, value interface{})) {
}
// ShardDataStore -
func (mock *ShardedDataCacheNotifierMock) ShardDataStore(cacheId string) (c storage.Cacher) {
mock.mutCaches.Lock()
defer mock.mutCaches.Unlock()
cache, found := mock.caches[cacheId]
if !found {
cache = NewCacherMock()
mock.caches[cacheId] = cache
}
return cache
}
// AddData -
func (mock *ShardedDataCacheNotifierMock) AddData(key []byte, data interface{}, sizeInBytes int, cacheId string) {
cache := mock.ShardDataStore(cacheId)
cache.HasOrAdd(key, data, sizeInBytes)
}
// SearchFirstData -
func (mock *ShardedDataCacheNotifierMock) SearchFirstData(key []byte) (interface{}, bool) {
mock.mutCaches.RLock()
defer mock.mutCaches.RUnlock()
for _, cache := range mock.caches {
buff, ok := cache.Get(key)
if ok {
return buff, true
}
}
return nil, false
}
// RemoveData -
func (mock *ShardedDataCacheNotifierMock) RemoveData(key []byte, cacheId string) {
cache := mock.ShardDataStore(cacheId)
cache.Remove(key)
}
// RemoveSetOfDataFromPool -
func (mock *ShardedDataCacheNotifierMock) RemoveSetOfDataFromPool(keys [][]byte, cacheId string) {
cache := mock.ShardDataStore(cacheId)
for _, key := range keys {
cache.Remove(key)
}
}
// ImmunizeSetOfDataAgainstEviction -
func (mock *ShardedDataCacheNotifierMock) ImmunizeSetOfDataAgainstEviction(_ [][]byte, _ string) {
}
// RemoveDataFromAllShards -
func (mock *ShardedDataCacheNotifierMock) RemoveDataFromAllShards(key []byte) {
mock.mutCaches.RLock()
defer mock.mutCaches.RUnlock()
for _, cache := range mock.caches {
cache.Remove(key)
}
}
// MergeShardStores -
func (mock *ShardedDataCacheNotifierMock) MergeShardStores(_, _ string) {
}
// Clear -
func (mock *ShardedDataCacheNotifierMock) Clear() {
mock.mutCaches.Lock()
defer mock.mutCaches.Unlock()
mock.caches = make(map[string]storage.Cacher)
}
// ClearShardStore -
func (mock *ShardedDataCacheNotifierMock) ClearShardStore(cacheId string) {
cache := mock.ShardDataStore(cacheId)
cache.Clear()
}
// GetCounts -
func (mock *ShardedDataCacheNotifierMock) GetCounts() counting.CountsWithSize {
return nil
}
// Keys -
func (mock *ShardedDataCacheNotifierMock) Keys() [][]byte {
mock.mutCaches.Lock()
defer mock.mutCaches.Unlock()
keys := make([][]byte, 0)
for _, cache := range mock.caches {
keys = append(keys, cache.Keys()...)
}
return keys
}
// IsInterfaceNil -
func (mock *ShardedDataCacheNotifierMock) IsInterfaceNil() bool {
return mock == nil
}