From d30c71bd61f2501330e16c362f167d31008bfce8 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:39:54 +0200 Subject: [PATCH 01/12] Tests: update stats_tests to match new API --- stats_test.go | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/stats_test.go b/stats_test.go index 1a6543a..2802713 100644 --- a/stats_test.go +++ b/stats_test.go @@ -41,7 +41,11 @@ func TestCacheStats(t *testing.T) { }{ { builder: func() Cache { - cc := New(32).Simple().Build() + cc, err := New(32).Simple().Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -51,7 +55,11 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32).LRU().Build() + cc, err := New(32).LRU().Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -61,7 +69,11 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32).LFU().Build() + cc, err := New(32).LFU().Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -71,7 +83,11 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32).ARC().Build() + cc, err := New(32).ARC().Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -81,10 +97,14 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32). + cc, err := New(32). Simple(). LoaderFunc(getter). Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -94,10 +114,14 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32). + cc, err := New(32). LRU(). LoaderFunc(getter). Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -107,10 +131,14 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32). + cc, err := New(32). LFU(). LoaderFunc(getter). Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) @@ -120,10 +148,14 @@ func TestCacheStats(t *testing.T) { }, { builder: func() Cache { - cc := New(32). + cc, err := New(32). ARC(). LoaderFunc(getter). Build() + if err != nil { + t.Error(err) + } + cc.Set(0, 0) cc.Get(0) cc.Get(1) From bd23325d808cc5109c41fb010817fc8d530ec3bd Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:40:11 +0200 Subject: [PATCH 02/12] Tests: update singleflight tests to match new API --- singleflight_test.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/singleflight_test.go b/singleflight_test.go index 81b9490..716fbe4 100644 --- a/singleflight_test.go +++ b/singleflight_test.go @@ -27,7 +27,13 @@ import ( func TestDo(t *testing.T) { var g Group - g.cache = New(32).Build() + var err error + + g.cache, err = New(32).Build() + if err != nil { + t.Error(err) + } + v, _, err := g.Do("key", func() (interface{}, error) { return "bar", nil }, true) @@ -41,7 +47,13 @@ func TestDo(t *testing.T) { func TestDoErr(t *testing.T) { var g Group - g.cache = New(32).Build() + var err error + + g.cache, err = New(32).Build() + if err != nil { + t.Error(err) + } + someErr := errors.New("Some error") v, _, err := g.Do("key", func() (interface{}, error) { return nil, someErr @@ -56,7 +68,13 @@ func TestDoErr(t *testing.T) { func TestDoDupSuppress(t *testing.T) { var g Group - g.cache = New(32).Build() + var err error + + g.cache, err = New(32).Build() + if err != nil { + t.Error(err) + } + c := make(chan string) var calls int32 fn := func() (interface{}, error) { From 42479fe73a233dc89e00a7591b210c9ae58b0bde Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:40:30 +0200 Subject: [PATCH 03/12] Tests: update test helpers to match new API --- helpers_test.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index 3761853..1c9b7d2 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -16,8 +16,8 @@ func testSetCache(t *testing.T, gc Cache, numbers int) { value, err := loader(key) if err != nil { t.Error(err) - return } + gc.Set(key, value) } } @@ -37,7 +37,7 @@ func testGetCache(t *testing.T, gc Cache, numbers int) { } func testGetIFPresent(t *testing.T, evT string) { - cache := + cache, err := New(8). EvictType(evT). LoaderFunc( @@ -46,6 +46,10 @@ func testGetIFPresent(t *testing.T, evT string) { }). Build() + if err != nil { + t.Error(err) + } + v, err := cache.GetIFPresent("key") if err != KeyNotFoundError { t.Errorf("err should not be %v", err) @@ -64,11 +68,16 @@ func testGetIFPresent(t *testing.T, evT string) { func testGetALL(t *testing.T, evT string) { size := 8 - cache := + cache, err := New(size). Expiration(time.Millisecond). EvictType(evT). Build() + + if err != nil { + t.Error(err) + } + for i := 0; i < size; i++ { cache.Set(i, i*i) } From 238797c46889c6f2c26dda305e6bfad128410af3 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:40:47 +0200 Subject: [PATCH 04/12] Tests: update SimpleCache to match new API --- simple_test.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/simple_test.go b/simple_test.go index 22793b0..ec04dff 100644 --- a/simple_test.go +++ b/simple_test.go @@ -5,14 +5,14 @@ import ( "testing" ) -func buildSimpleCache(size int) Cache { +func buildSimpleCache(size int) (Cache, error) { return New(size). Simple(). EvictedFunc(evictedFuncForSimple). Build() } -func buildLoadingSimpleCache(size int, loader LoaderFunc) Cache { +func buildLoadingSimpleCache(size int, loader LoaderFunc) (Cache, error) { return New(size). LoaderFunc(loader). Simple(). @@ -26,7 +26,11 @@ func evictedFuncForSimple(key, value interface{}) { func TestSimpleGet(t *testing.T) { size := 1000 - gc := buildSimpleCache(size) + gc, err := buildSimpleCache(size) + if err != nil { + t.Error(err) + } + testSetCache(t, gc, size) testGetCache(t, gc, size) } @@ -34,11 +38,20 @@ func TestSimpleGet(t *testing.T) { func TestLoadingSimpleGet(t *testing.T) { size := 1000 numbers := 1000 - testGetCache(t, buildLoadingSimpleCache(size, loader), numbers) + gc, err := buildLoadingSimpleCache(size, loader) + if err != nil { + t.Error(err) + } + + testGetCache(t, gc, numbers) } func TestSimpleLength(t *testing.T) { - gc := buildLoadingSimpleCache(1000, loader) + gc, err := buildLoadingSimpleCache(1000, loader) + if err != nil { + t.Error(err) + } + gc.Get("test1") gc.Get("test2") length := gc.Len() @@ -51,7 +64,10 @@ func TestSimpleLength(t *testing.T) { func TestSimpleEvictItem(t *testing.T) { cacheSize := 10 numbers := 11 - gc := buildLoadingSimpleCache(cacheSize, loader) + gc, err := buildLoadingSimpleCache(cacheSize, loader) + if err != nil { + t.Error(err) + } for i := 0; i < numbers; i++ { _, err := gc.Get(fmt.Sprintf("Key-%d", i)) @@ -64,7 +80,10 @@ func TestSimpleEvictItem(t *testing.T) { func TestSimpleUnboundedNoEviction(t *testing.T) { numbers := 1000 size_tracker := 0 - gcu := buildLoadingSimpleCache(0, loader) + gcu, err := buildLoadingSimpleCache(0, loader) + if err != nil { + t.Error(err) + } for i := 0; i < numbers; i++ { current_size := gcu.Len() From 6189cd46e1b4d8a4a2cf63f62c3d3f388a971f4c Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:40:56 +0200 Subject: [PATCH 05/12] Tests: update ARC to match new API --- arc_test.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/arc_test.go b/arc_test.go index 1ccc6f2..58abb10 100644 --- a/arc_test.go +++ b/arc_test.go @@ -6,14 +6,14 @@ import ( "time" ) -func buildARCache(size int) Cache { +func buildARCache(size int) (Cache, error) { return New(size). ARC(). EvictedFunc(evictedFuncForARC). Build() } -func buildLoadingARCache(size int) Cache { +func buildLoadingARCache(size int) (Cache, error) { return New(size). ARC(). LoaderFunc(loader). @@ -21,7 +21,7 @@ func buildLoadingARCache(size int) Cache { Build() } -func buildLoadingARCacheWithExpiration(size int, ep time.Duration) Cache { +func buildLoadingARCacheWithExpiration(size int, ep time.Duration) (Cache, error) { return New(size). ARC(). Expiration(ep). @@ -36,7 +36,10 @@ func evictedFuncForARC(key, value interface{}) { func TestARCGet(t *testing.T) { size := 1000 - gc := buildARCache(size) + gc, err := buildARCache(size) + if err != nil { + t.Error(err) + } testSetCache(t, gc, size) testGetCache(t, gc, size) } @@ -44,11 +47,19 @@ func TestARCGet(t *testing.T) { func TestLoadingARCGet(t *testing.T) { size := 1000 numbers := 1000 - testGetCache(t, buildLoadingARCache(size), numbers) + gc, err := buildLoadingARCache(size) + if err != nil { + t.Error(err) + } + testGetCache(t, gc, numbers) } func TestARCLength(t *testing.T) { - gc := buildLoadingARCacheWithExpiration(2, time.Millisecond) + gc, err := buildLoadingARCacheWithExpiration(2, time.Millisecond) + if err != nil { + t.Error(err) + } + gc.Get("test1") gc.Get("test2") gc.Get("test3") @@ -69,7 +80,10 @@ func TestARCLength(t *testing.T) { func TestARCEvictItem(t *testing.T) { cacheSize := 10 numbers := cacheSize + 1 - gc := buildLoadingARCache(cacheSize) + gc, err := buildLoadingARCache(cacheSize) + if err != nil { + t.Error(err) + } for i := 0; i < numbers; i++ { _, err := gc.Get(fmt.Sprintf("Key-%d", i)) @@ -82,7 +96,7 @@ func TestARCEvictItem(t *testing.T) { func TestARCPurgeCache(t *testing.T) { cacheSize := 10 purgeCount := 0 - gc := New(cacheSize). + gc, err := New(cacheSize). ARC(). LoaderFunc(loader). PurgeVisitorFunc(func(k, v interface{}) { @@ -90,6 +104,10 @@ func TestARCPurgeCache(t *testing.T) { }). Build() + if err != nil { + t.Error(err) + } + for i := 0; i < cacheSize; i++ { _, err := gc.Get(fmt.Sprintf("Key-%d", i)) if err != nil { From 8276f0940ed9bf7b9833f6a828a004ac4062afbf Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:41:04 +0200 Subject: [PATCH 06/12] Tests: update LRU to match new API --- lru_test.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/lru_test.go b/lru_test.go index 9292d8c..82b852c 100644 --- a/lru_test.go +++ b/lru_test.go @@ -10,7 +10,7 @@ func evictedFuncForLRU(key, value interface{}) { fmt.Printf("[LRU] Key:%v Value:%v will be evicted.\n", key, value) } -func buildLRUCache(size int) Cache { +func buildLRUCache(size int) (Cache, error) { return New(size). LRU(). EvictedFunc(evictedFuncForLRU). @@ -18,7 +18,7 @@ func buildLRUCache(size int) Cache { Build() } -func buildLoadingLRUCache(size int, loader LoaderFunc) Cache { +func buildLoadingLRUCache(size int, loader LoaderFunc) (Cache, error) { return New(size). LRU(). LoaderFunc(loader). @@ -29,19 +29,30 @@ func buildLoadingLRUCache(size int, loader LoaderFunc) Cache { func TestLRUGet(t *testing.T) { size := 1000 - gc := buildLRUCache(size) + gc, err := buildLRUCache(size) + if err != nil { + t.Error(err) + } + testSetCache(t, gc, size) testGetCache(t, gc, size) } func TestLoadingLRUGet(t *testing.T) { size := 1000 - gc := buildLoadingLRUCache(size, loader) + gc, err := buildLoadingLRUCache(size, loader) + if err != nil { + t.Error(err) + } + testGetCache(t, gc, size) } func TestLRULength(t *testing.T) { - gc := buildLoadingLRUCache(1000, loader) + gc, err := buildLoadingLRUCache(1000, loader) + if err != nil { + t.Error(err) + } gc.Get("test1") gc.Get("test2") length := gc.Len() @@ -54,7 +65,10 @@ func TestLRULength(t *testing.T) { func TestLRUEvictItem(t *testing.T) { cacheSize := 10 numbers := 11 - gc := buildLoadingLRUCache(cacheSize, loader) + gc, err := buildLoadingLRUCache(cacheSize, loader) + if err != nil { + t.Error(err) + } for i := 0; i < numbers; i++ { _, err := gc.Get(fmt.Sprintf("Key-%d", i)) From 55880eaa6e8600b24c372221fe4f71894c2b46f0 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:41:09 +0200 Subject: [PATCH 07/12] Tests: update LFU to match new API --- lfu_test.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lfu_test.go b/lfu_test.go index d8c9b99..498e4ca 100644 --- a/lfu_test.go +++ b/lfu_test.go @@ -10,7 +10,7 @@ func evictedFuncForLFU(key, value interface{}) { fmt.Printf("[LFU] Key:%v Value:%v will be evicted.\n", key, value) } -func buildLFUCache(size int) Cache { +func buildLFUCache(size int) (Cache, error) { return New(size). LFU(). EvictedFunc(evictedFuncForLFU). @@ -18,7 +18,7 @@ func buildLFUCache(size int) Cache { Build() } -func buildLoadingLFUCache(size int, loader LoaderFunc) Cache { +func buildLoadingLFUCache(size int, loader LoaderFunc) (Cache, error) { return New(size). LFU(). LoaderFunc(loader). @@ -31,7 +31,11 @@ func TestLFUGet(t *testing.T) { size := 1000 numbers := 1000 - gc := buildLoadingLFUCache(size, loader) + gc, err := buildLoadingLFUCache(size, loader) + if err != nil { + t.Error(err) + } + testSetCache(t, gc, numbers) testGetCache(t, gc, numbers) } @@ -40,12 +44,20 @@ func TestLoadingLFUGet(t *testing.T) { size := 1000 numbers := 1000 - gc := buildLoadingLFUCache(size, loader) + gc, err := buildLoadingLFUCache(size, loader) + if err != nil { + t.Error(err) + } + testGetCache(t, gc, numbers) } func TestLFULength(t *testing.T) { - gc := buildLoadingLFUCache(1000, loader) + gc, err := buildLoadingLFUCache(1000, loader) + if err != nil { + t.Error(err) + } + gc.Get("test1") gc.Get("test2") length := gc.Len() @@ -58,7 +70,10 @@ func TestLFULength(t *testing.T) { func TestLFUEvictItem(t *testing.T) { cacheSize := 10 numbers := 11 - gc := buildLoadingLFUCache(cacheSize, loader) + gc, err := buildLoadingLFUCache(cacheSize, loader) + if err != nil { + t.Error(err) + } for i := 0; i < numbers; i++ { _, err := gc.Get(fmt.Sprintf("Key-%d", i)) From 7deb15d72b99f62edc7672755c3b4000c0bf7a95 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:41:27 +0200 Subject: [PATCH 08/12] Update lib examples --- examples/autoloading_cache.go | 6 +++--- examples/custom_expiration.go | 2 +- examples/example.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/autoloading_cache.go b/examples/autoloading_cache.go index 5200b46..949cb14 100644 --- a/examples/autoloading_cache.go +++ b/examples/autoloading_cache.go @@ -6,11 +6,11 @@ import ( ) func main() { - gc := gcache.New(10). + gc, _ := gcache.New(10). LFU(). LoaderFunc(func(key interface{}) (interface{}, error) { - return fmt.Sprintf("%v-value", key), nil - }). + return fmt.Sprintf("%v-value", key), nil + }). Build() v, err := gc.Get("key") diff --git a/examples/custom_expiration.go b/examples/custom_expiration.go index 54f12a6..d62c97e 100644 --- a/examples/custom_expiration.go +++ b/examples/custom_expiration.go @@ -7,7 +7,7 @@ import ( ) func main() { - gc := gcache.New(10). + gc, _ := gcache.New(10). LFU(). Build() diff --git a/examples/example.go b/examples/example.go index 97c1b32..a34a70d 100644 --- a/examples/example.go +++ b/examples/example.go @@ -6,7 +6,7 @@ import ( ) func main() { - gc := gcache.New(10). + gc, _ := gcache.New(10). LFU(). Build() gc.Set("key", "ok") From cc13e91a153792b1c1d719ca36a08241bb114b84 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:41:55 +0200 Subject: [PATCH 09/12] Create errors for invalid cache size/type --- cache.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cache.go b/cache.go index b56d9d1..3e0dfe1 100644 --- a/cache.go +++ b/cache.go @@ -15,6 +15,8 @@ const ( ) var KeyNotFoundError = errors.New("Key not found.") +var InvalidCacheSizeError = errors.New("Invalid Cache size") +var UnknownCacheTypeError = errors.New("Unknown Cache type") type Cache interface { Set(interface{}, interface{}) error From c02994b3674143c2f8375203663d05e9d090f76d Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:42:16 +0200 Subject: [PATCH 10/12] Remove runtime panics when building cache --- cache.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/cache.go b/cache.go index 3e0dfe1..a033465 100644 --- a/cache.go +++ b/cache.go @@ -155,7 +155,6 @@ func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder { func (cb *CacheBuilder) Build() Cache { if cb.size <= 0 && cb.tp != TYPE_SIMPLE { - panic("gcache: Cache size <= 0") } return cb.build() @@ -172,7 +171,6 @@ func (cb *CacheBuilder) build() Cache { case TYPE_ARC: return newARC(cb) default: - panic("gcache: Unknown type " + cb.tp) } } From ae8ebeca4ed0c034208a163a57a9d3fbabe90c08 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:42:42 +0200 Subject: [PATCH 11/12] Fail building cache when type or size are invalid --- cache.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cache.go b/cache.go index a033465..35d56cc 100644 --- a/cache.go +++ b/cache.go @@ -153,24 +153,26 @@ func (cb *CacheBuilder) Expiration(expiration time.Duration) *CacheBuilder { return cb } -func (cb *CacheBuilder) Build() Cache { +func (cb *CacheBuilder) Build() (Cache, error) { if cb.size <= 0 && cb.tp != TYPE_SIMPLE { + return newSimpleCache(cb), InvalidCacheSizeError } return cb.build() } -func (cb *CacheBuilder) build() Cache { +func (cb *CacheBuilder) build() (Cache, error) { switch cb.tp { case TYPE_SIMPLE: - return newSimpleCache(cb) + return newSimpleCache(cb), nil case TYPE_LRU: - return newLRUCache(cb) + return newLRUCache(cb), nil case TYPE_LFU: - return newLFUCache(cb) + return newLFUCache(cb), nil case TYPE_ARC: - return newARC(cb) + return newARC(cb), nil default: + return newSimpleCache(cb), UnknownCacheTypeError } } From 5c236ac9ff39d774446cbc49583b5be0c92912e5 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 11 Oct 2017 14:44:04 +0200 Subject: [PATCH 12/12] Tests: Verify that cache don't build when given an invalid size --- cache_test.go | 59 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/cache_test.go b/cache_test.go index 5a458d6..c50f2eb 100644 --- a/cache_test.go +++ b/cache_test.go @@ -9,6 +9,36 @@ import ( "time" ) +func TestInvalidCacheSize(t *testing.T) { + var invalidBuilders = []*CacheBuilder{ + New(0).ARC(), + New(-1).ARC(), + New(0).LFU(), + New(-1).LFU(), + New(0).LRU(), + New(-1).LRU(), + } + + for _, builder := range invalidBuilders { + _, err := builder.Build() + if err == nil { + t.Errorf("Building a %v-cache with size %v should fail", builder.tp, builder.size) + } + } + + var validBuilders = []*CacheBuilder{ + New(0).Simple(), + New(-1).Simple(), + } + + for _, builder := range validBuilders { + _, err := builder.Build() + if err != nil { + t.Errorf("Build a SimpleCache with size %v <= 0 is a valid operation", builder.size) + } + } +} + func TestLoaderFunc(t *testing.T) { size := 2 var testCaches = []*CacheBuilder{ @@ -20,7 +50,7 @@ func TestLoaderFunc(t *testing.T) { for _, builder := range testCaches { var testCounter int64 counter := 1000 - cache := builder. + cache, err := builder. LoaderFunc(func(key interface{}) (interface{}, error) { time.Sleep(10 * time.Millisecond) return atomic.AddInt64(&testCounter, 1), nil @@ -29,6 +59,10 @@ func TestLoaderFunc(t *testing.T) { panic(key) }).Build() + if err != nil { + t.Error(err) + } + var wg sync.WaitGroup for i := 0; i < counter; i++ { wg.Add(1) @@ -59,7 +93,7 @@ func TestLoaderExpireFuncWithoutExpire(t *testing.T) { for _, builder := range testCaches { var testCounter int64 counter := 1000 - cache := builder. + cache, err := builder. LoaderExpireFunc(func(key interface{}) (interface{}, *time.Duration, error) { return atomic.AddInt64(&testCounter, 1), nil, nil }). @@ -67,6 +101,9 @@ func TestLoaderExpireFuncWithoutExpire(t *testing.T) { panic(key) }).Build() + if err != nil { + t.Error(err) + } var wg sync.WaitGroup for i := 0; i < counter; i++ { wg.Add(1) @@ -99,12 +136,16 @@ func TestLoaderExpireFuncWithExpire(t *testing.T) { var testCounter int64 counter := 1000 expire := 200 * time.Millisecond - cache := builder. + cache, err := builder. LoaderExpireFunc(func(key interface{}) (interface{}, *time.Duration, error) { return atomic.AddInt64(&testCounter, 1), &expire, nil }). Build() + if err != nil { + t.Error(err) + } + var wg sync.WaitGroup for i := 0; i < counter; i++ { wg.Add(1) @@ -163,7 +204,7 @@ func TestLoaderPurgeVisitorFunc(t *testing.T) { for _, test := range tests { var purgeCounter, evictCounter, loaderCounter int64 counter := 1000 - cache := test.cacheBuilder. + cache, err := test.cacheBuilder. LoaderFunc(func(key interface{}) (interface{}, error) { return atomic.AddInt64(&loaderCounter, 1), nil }). @@ -175,6 +216,10 @@ func TestLoaderPurgeVisitorFunc(t *testing.T) { }). Build() + if err != nil { + t.Error(err) + } + var wg sync.WaitGroup for i := 0; i < counter; i++ { i := i @@ -218,7 +263,7 @@ func TestDeserializeFunc(t *testing.T) { for _, cs := range cases { key1, value1 := "key1", "value1" key2, value2 := "key2", "value2" - cc := New(32). + cc, err := New(32). EvictType(cs.tp). LoaderFunc(func(k interface{}) (interface{}, error) { return value1, nil @@ -239,6 +284,10 @@ func TestDeserializeFunc(t *testing.T) { return buf.Bytes(), err }). Build() + + if err != nil { + t.Error(err) + } v, err := cc.Get(key1) if err != nil { t.Fatal(err)