Skip to content

Commit a2285c6

Browse files
authored
Merge pull request #10 from FishGoddess/develop
v0.5.0
2 parents c2f0861 + 58665b6 commit a2285c6

File tree

19 files changed

+211
-197
lines changed

19 files changed

+211
-197
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ jobs:
99
test-project:
1010
runs-on: ubuntu-20.04
1111
steps:
12+
- name: Setup
13+
uses: actions/setup-go@v4
14+
with:
15+
go-version: "1.17"
16+
- run: go version
17+
1218
- name: Checkout
13-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
1420

1521
- name: Test
16-
run: make test
22+
run: make test

FUTURE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
### v0.5.x
44

5-
* [ ] 提供一个清空并设置全量值的方法,方便定时数据的全量替换
5+
* [ ] ~~提供一个清空并设置全量值的方法,方便定时数据的全量替换~~
6+
目前还找不到一个合适的设计去加入这个功能,并且也不是非常刚需,通过业务手段可以处理,所以先不加
7+
* [ ] 完善监控上报器,提供更多缓存信息查询的方法
68

79
### v0.4.x
810

@@ -24,7 +26,6 @@
2426
* [x] 给 Reporter 增加缓存类型方法,主要用于监控不同类型缓存的使用情况
2527
* [ ] ~~增加对不存在的数据做防穿透的机制~~
2628
经过实践,这个更适合业务方自己处理,所以这边就先去掉了
27-
* [ ] 完善监控上报器,提供更多缓存信息查询的方法
2829

2930
### v0.3.x
3031

HISTORY.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## ✒ 历史版本的特性介绍 (Features in old versions)
22

3+
### v0.5.0
4+
5+
> 此版本发布于 2023-11-30
6+
7+
* 调整单元测试代码
8+
* API 进入稳定观察期
9+
310
### v0.4.12
411

512
> 此版本发布于 2023-06-12

cache_test.go

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,27 @@ const (
2828
// go test -v -cover -run=^TestCacheType$
2929
func TestCacheType(t *testing.T) {
3030
if standard.String() != string(standard) {
31-
t.Errorf("standard.String() %s is wrong", standard.String())
31+
t.Fatalf("standard.String() %s is wrong", standard.String())
3232
}
3333

3434
if lru.String() != string(lru) {
35-
t.Errorf("lru.String() %s is wrong", lru.String())
35+
t.Fatalf("lru.String() %s is wrong", lru.String())
3636
}
3737

3838
if lfu.String() != string(lfu) {
39-
t.Errorf("lfu.String() %s is wrong", lfu.String())
39+
t.Fatalf("lfu.String() %s is wrong", lfu.String())
4040
}
4141

4242
if !standard.IsStandard() {
43-
t.Error("!standard.IsStandard()")
43+
t.Fatal("!standard.IsStandard()")
4444
}
4545

4646
if !lru.IsLRU() {
47-
t.Error("!standard.IsLRU()")
47+
t.Fatal("!standard.IsLRU()")
4848
}
4949

5050
if !lfu.IsLFU() {
51-
t.Error("!standard.IsLFU()")
51+
t.Fatal("!standard.IsLFU()")
5252
}
5353
}
5454

@@ -87,97 +87,97 @@ func (tc *testCache) Reset() {}
8787
func testCacheGet(t *testing.T, cache Cache) {
8888
value, found := cache.Get("key")
8989
if found {
90-
t.Errorf("get %+v should be not found", value)
90+
t.Fatalf("get %+v should be not found", value)
9191
}
9292

9393
cache.Set("key", "value", time.Millisecond)
9494

9595
value, found = cache.Get("key")
9696
if !found {
97-
t.Error("get should be found")
97+
t.Fatal("get should be found")
9898
}
9999

100100
if value.(string) != "value" {
101-
t.Errorf("value %+v is wrong", value)
101+
t.Fatalf("value %+v is wrong", value)
102102
}
103103

104104
time.Sleep(2 * time.Millisecond)
105105

106106
value, found = cache.Get("key")
107107
if found {
108-
t.Errorf("get %+v should be not found", value)
108+
t.Fatalf("get %+v should be not found", value)
109109
}
110110
}
111111

112112
func testCacheSet(t *testing.T, cache Cache) {
113113
value, found := cache.Get("key")
114114
if found {
115-
t.Errorf("get %+v should be not found", value)
115+
t.Fatalf("get %+v should be not found", value)
116116
}
117117

118118
cache.Set("key", "value", time.Millisecond)
119119

120120
value, found = cache.Get("key")
121121
if !found {
122-
t.Error("get should be found")
122+
t.Fatal("get should be found")
123123
}
124124

125125
if value.(string) != "value" {
126-
t.Errorf("value %+v is wrong", value)
126+
t.Fatalf("value %+v is wrong", value)
127127
}
128128

129129
time.Sleep(2 * time.Millisecond)
130130

131131
value, found = cache.Get("key")
132132
if found {
133-
t.Errorf("get %+v should be not found", value)
133+
t.Fatalf("get %+v should be not found", value)
134134
}
135135

136136
cache.Set("key", "value", NoTTL)
137137

138138
value, found = cache.Get("key")
139139
if !found {
140-
t.Error("get should be found")
140+
t.Fatal("get should be found")
141141
}
142142

143143
if value.(string) != "value" {
144-
t.Errorf("value %+v is wrong", value)
144+
t.Fatalf("value %+v is wrong", value)
145145
}
146146

147147
time.Sleep(2 * time.Millisecond)
148148

149149
value, found = cache.Get("key")
150150
if !found {
151-
t.Error("get should be found")
151+
t.Fatal("get should be found")
152152
}
153153
}
154154

155155
func testCacheRemove(t *testing.T, cache Cache) {
156156
removedValue := cache.Remove("key")
157157
if removedValue != nil {
158-
t.Errorf("removedValue %+v is wrong", removedValue)
158+
t.Fatalf("removedValue %+v is wrong", removedValue)
159159
}
160160

161161
cache.Set("key", "value", NoTTL)
162162

163163
removedValue = cache.Remove("key")
164164
if removedValue.(string) != "value" {
165-
t.Errorf("removedValue %+v is wrong", removedValue)
165+
t.Fatalf("removedValue %+v is wrong", removedValue)
166166
}
167167

168168
cache.Set("key", "value", time.Millisecond)
169169
time.Sleep(2 * time.Millisecond)
170170

171171
removedValue = cache.Remove("key")
172172
if removedValue == nil {
173-
t.Error("removedValue == nil")
173+
t.Fatal("removedValue == nil")
174174
}
175175
}
176176

177177
func testCacheSize(t *testing.T, cache Cache) {
178178
size := cache.Size()
179179
if size != 0 {
180-
t.Errorf("size %d is wrong", size)
180+
t.Fatalf("size %d is wrong", size)
181181
}
182182

183183
for i := int64(0); i < maxTestEntries; i++ {
@@ -186,14 +186,14 @@ func testCacheSize(t *testing.T, cache Cache) {
186186

187187
size = cache.Size()
188188
if size != maxTestEntries {
189-
t.Errorf("size %d is wrong", size)
189+
t.Fatalf("size %d is wrong", size)
190190
}
191191
}
192192

193193
func testCacheGC(t *testing.T, cache Cache) {
194194
size := cache.Size()
195195
if size != 0 {
196-
t.Errorf("size %d is wrong", size)
196+
t.Fatalf("size %d is wrong", size)
197197
}
198198

199199
for i := int64(0); i < maxTestEntries; i++ {
@@ -206,14 +206,14 @@ func testCacheGC(t *testing.T, cache Cache) {
206206

207207
size = cache.Size()
208208
if size != maxTestEntries {
209-
t.Errorf("size %d is wrong", size)
209+
t.Fatalf("size %d is wrong", size)
210210
}
211211

212212
cache.GC()
213213

214214
size = cache.Size()
215215
if size != maxTestEntries {
216-
t.Errorf("size %d is wrong", size)
216+
t.Fatalf("size %d is wrong", size)
217217
}
218218

219219
time.Sleep(2 * time.Millisecond)
@@ -222,7 +222,7 @@ func testCacheGC(t *testing.T, cache Cache) {
222222

223223
size = cache.Size()
224224
if size != maxTestEntries/2 {
225-
t.Errorf("size %d is wrong", size)
225+
t.Fatalf("size %d is wrong", size)
226226
}
227227
}
228228

@@ -234,31 +234,31 @@ func testCacheReset(t *testing.T, cache Cache) {
234234
for i := int64(0); i < maxTestEntries; i++ {
235235
value, found := cache.Get(strconv.FormatInt(i, 10))
236236
if !found {
237-
t.Errorf("get %d should be found", i)
237+
t.Fatalf("get %d should be found", i)
238238
}
239239

240240
if value.(int64) != i {
241-
t.Errorf("value %+v is wrong", value)
241+
t.Fatalf("value %+v is wrong", value)
242242
}
243243
}
244244

245245
size := cache.Size()
246246
if size != maxTestEntries {
247-
t.Errorf("size %d is wrong", size)
247+
t.Fatalf("size %d is wrong", size)
248248
}
249249

250250
cache.Reset()
251251

252252
for i := int64(0); i < maxTestEntries; i++ {
253253
value, found := cache.Get(strconv.FormatInt(i, 10))
254254
if found {
255-
t.Errorf("get %d, %+v should be not found", i, value)
255+
t.Fatalf("get %d, %+v should be not found", i, value)
256256
}
257257
}
258258

259259
size = cache.Size()
260260
if size != 0 {
261-
t.Errorf("size %d is wrong", size)
261+
t.Fatalf("size %d is wrong", size)
262262
}
263263
}
264264

@@ -279,38 +279,38 @@ func TestNewCache(t *testing.T) {
279279

280280
sc1, ok := cache.(*standardCache)
281281
if !ok {
282-
t.Errorf("cache.(*standardCache) %T not ok", cache)
282+
t.Fatalf("cache.(*standardCache) %T not ok", cache)
283283
}
284284

285285
if sc1 == nil {
286-
t.Error("sc1 == nil")
286+
t.Fatal("sc1 == nil")
287287
}
288288

289289
cache = NewCache(WithLRU(16))
290290

291291
sc2, ok := cache.(*lruCache)
292292
if !ok {
293-
t.Errorf("cache.(*lruCache) %T not ok", cache)
293+
t.Fatalf("cache.(*lruCache) %T not ok", cache)
294294
}
295295

296296
if sc2 == nil {
297-
t.Error("sc2 == nil")
297+
t.Fatal("sc2 == nil")
298298
}
299299

300300
cache = NewCache(WithShardings(64))
301301

302302
sc, ok := cache.(*shardingCache)
303303
if !ok {
304-
t.Errorf("cache.(*shardingCache) %T not ok", cache)
304+
t.Fatalf("cache.(*shardingCache) %T not ok", cache)
305305
}
306306

307307
if sc == nil {
308-
t.Error("sc == nil")
308+
t.Fatal("sc == nil")
309309
}
310310

311311
defer func() {
312312
if r := recover(); r == nil {
313-
t.Error("new should panic")
313+
t.Fatal("new should panic")
314314
}
315315
}()
316316

@@ -323,15 +323,15 @@ func TestNewCacheWithReport(t *testing.T) {
323323

324324
sc1, ok := cache.(*reportableCache)
325325
if !ok {
326-
t.Errorf("cache.(*reportableCache) %T not ok", cache)
326+
t.Fatalf("cache.(*reportableCache) %T not ok", cache)
327327
}
328328

329329
if sc1 == nil {
330-
t.Error("sc1 == nil")
330+
t.Fatal("sc1 == nil")
331331
}
332332

333333
if reporter == nil {
334-
t.Error("reporter == nil")
334+
t.Fatal("reporter == nil")
335335
}
336336
}
337337

@@ -341,7 +341,7 @@ func TestRunGCTask(t *testing.T) {
341341

342342
count := cache.currentCount()
343343
if count != 0 {
344-
t.Errorf("cache.currentCount() %d is wrong", count)
344+
t.Fatalf("cache.currentCount() %d is wrong", count)
345345
}
346346

347347
cancel := RunGCTask(cache, 10*time.Millisecond)
@@ -350,21 +350,21 @@ func TestRunGCTask(t *testing.T) {
350350

351351
count = cache.currentCount()
352352
if count != 10 {
353-
t.Errorf("cache.currentCount() %d is wrong", count)
353+
t.Fatalf("cache.currentCount() %d is wrong", count)
354354
}
355355

356356
time.Sleep(80 * time.Millisecond)
357357
cancel()
358358

359359
count = cache.currentCount()
360360
if count != 18 {
361-
t.Errorf("cache.currentCount() %d is wrong", count)
361+
t.Fatalf("cache.currentCount() %d is wrong", count)
362362
}
363363

364364
time.Sleep(time.Second)
365365

366366
count = cache.currentCount()
367367
if count != 18 {
368-
t.Errorf("cache.currentCount() %d is wrong", count)
368+
t.Fatalf("cache.currentCount() %d is wrong", count)
369369
}
370370
}

config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ func TestApplyOptions(t *testing.T) {
126126
})
127127

128128
if !isConfigEquals(got, expect) {
129-
t.Errorf("got %+v != expect %+v", got, expect)
129+
t.Fatalf("got %+v != expect %+v", got, expect)
130130
}
131131
}

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,4 @@ Package cachego provides an easy way to use foundation for your caching operatio
480480
package cachego // import "github.com/FishGoddess/cachego"
481481

482482
// Version is the version string representation of cachego.
483-
const Version = "v0.4.12"
483+
const Version = "v0.5.0"

0 commit comments

Comments
 (0)