-
Notifications
You must be signed in to change notification settings - Fork 199
/
shardedDataStub.go
114 lines (95 loc) · 3.47 KB
/
shardedDataStub.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
package testscommon
import (
"github.com/ElrondNetwork/elrond-go-core/core/counting"
"github.com/ElrondNetwork/elrond-go/storage"
)
// ShardedDataStub -
type ShardedDataStub struct {
RegisterOnAddedCalled func(func(key []byte, value interface{}))
ShardDataStoreCalled func(cacheID string) storage.Cacher
AddDataCalled func(key []byte, data interface{}, sizeInBytes int, cacheID string)
SearchFirstDataCalled func(key []byte) (value interface{}, ok bool)
RemoveDataCalled func(key []byte, cacheID string)
RemoveDataFromAllShardsCalled func(key []byte)
MergeShardStoresCalled func(sourceCacheID, destCacheID string)
MoveDataCalled func(sourceCacheID, destCacheID string, key [][]byte)
ClearCalled func()
ClearShardStoreCalled func(cacheID string)
RemoveSetOfDataFromPoolCalled func(keys [][]byte, destCacheID string)
ImmunizeSetOfDataAgainstEvictionCalled func(keys [][]byte, cacheID string)
CreateShardStoreCalled func(destCacheID string)
GetCountsCalled func() counting.CountsWithSize
KeysCalled func() [][]byte
}
// NewShardedDataStub -
func NewShardedDataStub() *ShardedDataStub {
return &ShardedDataStub{}
}
// RegisterOnAdded -
func (sd *ShardedDataStub) RegisterOnAdded(handler func(key []byte, value interface{})) {
if sd.RegisterOnAddedCalled != nil {
sd.RegisterOnAddedCalled(handler)
}
}
// ShardDataStore -
func (sd *ShardedDataStub) ShardDataStore(cacheID string) storage.Cacher {
return sd.ShardDataStoreCalled(cacheID)
}
// AddData -
func (sd *ShardedDataStub) AddData(key []byte, data interface{}, sizeInBytes int, cacheID string) {
if sd.AddDataCalled != nil {
sd.AddDataCalled(key, data, sizeInBytes, cacheID)
}
}
// SearchFirstData -
func (sd *ShardedDataStub) SearchFirstData(key []byte) (value interface{}, ok bool) {
return sd.SearchFirstDataCalled(key)
}
// RemoveData -
func (sd *ShardedDataStub) RemoveData(key []byte, cacheID string) {
sd.RemoveDataCalled(key, cacheID)
}
// RemoveDataFromAllShards -
func (sd *ShardedDataStub) RemoveDataFromAllShards(key []byte) {
sd.RemoveDataFromAllShardsCalled(key)
}
// MergeShardStores -
func (sd *ShardedDataStub) MergeShardStores(sourceCacheID, destCacheID string) {
sd.MergeShardStoresCalled(sourceCacheID, destCacheID)
}
// Clear -
func (sd *ShardedDataStub) Clear() {
sd.ClearCalled()
}
// ClearShardStore -
func (sd *ShardedDataStub) ClearShardStore(cacheID string) {
sd.ClearShardStoreCalled(cacheID)
}
// RemoveSetOfDataFromPool -
func (sd *ShardedDataStub) RemoveSetOfDataFromPool(keys [][]byte, cacheID string) {
sd.RemoveSetOfDataFromPoolCalled(keys, cacheID)
}
// ImmunizeSetOfDataAgainstEviction -
func (sd *ShardedDataStub) ImmunizeSetOfDataAgainstEviction(keys [][]byte, cacheID string) {
if sd.ImmunizeSetOfDataAgainstEvictionCalled != nil {
sd.ImmunizeSetOfDataAgainstEvictionCalled(keys, cacheID)
}
}
// GetCounts -
func (sd *ShardedDataStub) GetCounts() counting.CountsWithSize {
if sd.GetCountsCalled != nil {
return sd.GetCountsCalled()
}
return &counting.NullCounts{}
}
// Keys -
func (sd *ShardedDataStub) Keys() [][]byte {
if sd.KeysCalled != nil {
return sd.KeysCalled()
}
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (sd *ShardedDataStub) IsInterfaceNil() bool {
return sd == nil
}