diff options
author | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-21 18:24:35 +0530 |
---|---|---|
committer | Marc Pervaz Boocha <marcpervaz@qburst.com> | 2025-02-21 18:24:35 +0530 |
commit | a470aa89cbdabba813636b8a29be8ae3836c03a0 (patch) | |
tree | 2551bebaff980cc93bf8fcf60dd8ff50bd7efc48 /store_test.go | |
parent | Add Tests and benchmarks (diff) | |
download | cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.gz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.bz2 cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.lz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.xz cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.tar.zst cache-a470aa89cbdabba813636b8a29be8ae3836c03a0.zip |
Added LTR Eviction
Diffstat (limited to '')
-rw-r--r-- | store_test.go (renamed from map_test.go) | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/map_test.go b/store_test.go index 5610d0a..3ad33e5 100644 --- a/map_test.go +++ b/store_test.go @@ -1,7 +1,9 @@ package cache import ( + "encoding/binary" "testing" + "time" "github.com/stretchr/testify/assert" ) @@ -23,12 +25,26 @@ func TestStoreGetSet(t *testing.T) { store := setupTestStore(t) want := []byte("Value") - store.Set([]byte("Key"), want, 0) - got, _, ok := store.Get([]byte("Key")) + store.Set([]byte("Key"), want, 1*time.Hour) + got, ttl, ok := store.Get([]byte("Key")) assert.Equal(t, want, got) + + now := time.Now() + assert.WithinDuration(t, now.Add(ttl), now.Add(1*time.Hour), 1*time.Millisecond) assert.True(t, ok) }) + t.Run("Exists TTL", func(t *testing.T) { + t.Parallel() + + store := setupTestStore(t) + + want := []byte("Value") + store.Set([]byte("Key"), want, time.Nanosecond) + _, _, ok := store.Get([]byte("Key")) + assert.False(t, ok) + }) + t.Run("Not Exists", func(t *testing.T) { t.Parallel() @@ -50,6 +66,31 @@ func TestStoreGetSet(t *testing.T) { assert.Equal(t, want, got) assert.True(t, ok) }) + + t.Run("Resize", func(t *testing.T) { + t.Parallel() + + store := setupTestStore(t) + + for i := range initialBucketSize { + key := binary.LittleEndian.AppendUint64(nil, i) + store.Set(key, key, 0) + } + + for i := range store.Length { + key := binary.LittleEndian.AppendUint64(nil, i) + _, _, ok := store.Get(key) + assert.True(t, ok, i) + } + + assert.Len(t, store.Bucket, int(initialBucketSize)*2) + + for i := range store.Length { + key := binary.LittleEndian.AppendUint64(nil, i) + _, _, ok := store.Get(key) + assert.True(t, ok, i) + } + }) } func TestStoreDelete(t *testing.T) { |