Skip to content

Commit

Permalink
export Qout len
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Sidorin committed Jul 27, 2021
1 parent 80e7530 commit 18f69b2
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions GobMQCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,8 @@ func (c *GobMQCache) Delete(key string) {
func (c *GobMQCache) Len() (totalLen int64, queuesLen []int64) {
return c.cache.Len()
}

//LenQout - return size of Qout
func (c *GobMQCache) LenQout() int {
return c.cache.LenQout()
}
14 changes: 14 additions & 0 deletions GobMQCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mqcache

import (
"github.com/stretchr/testify/suite"
"strconv"
"testing"
"time"
)
Expand Down Expand Up @@ -38,3 +39,16 @@ func (s *gobMQCacheTestSuite) TestBasic() {
s.Equal(2, slice[1])
s.Equal(3, slice[2])
}

func (s *gobMQCacheTestSuite) TestEvictions() {
opts := NewRecommendedOptions(42, 1, time.Millisecond)
cache, err := NewGobMQCache(opts)
s.Nil(err)
s.NotNil(cache)
for i := 0; i < 1000; i++ {
_, _ = cache.Set(strconv.Itoa(i), i)
}
size, _ := cache.Len()
s.Equal(int64(42), size)
s.Equal(4 * 42, cache.LenQout())
}
7 changes: 7 additions & 0 deletions MQCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ func (c *MQCache) Len() (totalLen int64, queuesLen []int64) {
return totalLen, c.queuesLen
}

//LenQout - return size of Qout
func (c *MQCache) LenQout() int {
c.lock.Lock()
defer c.lock.Unlock()
return c.qOut.len()
}

//GetSize return size of item in the cache
func (c *MQCache) GetSize(s SizeComputer) int64 {
if nil == s {
Expand Down
5 changes: 5 additions & 0 deletions SimpleMQCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ func (c *SimpleMQCache) Delete(key string) {
func (c *SimpleMQCache) Len() (totalLen int64, queuesLen []int64) {
return c.cache.Len()
}

//LenQout - return size of Qout
func (c *SimpleMQCache) LenQout() int {
return c.cache.LenQout()
}
15 changes: 15 additions & 0 deletions SimpleMQCache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mqcache

import (
"github.com/stretchr/testify/suite"
"strconv"
"testing"
"time"
)
Expand Down Expand Up @@ -70,3 +71,17 @@ func (s *simpleMqCacheTestSuite) TestContainer() {
r2 := c.GetValue()
s.Equal("123", r2.(string))
}


func (s *simpleMqCacheTestSuite) TestEvictions() {
opts := NewRecommendedOptions(3, 1, time.Millisecond)
cache, err := NewSimpleMQCache(opts)
s.Nil(err)
s.NotNil(cache)
for i := 0; i < 1000; i++ {
cache.Set(strconv.Itoa(i), i)
}
size, _ := cache.Len()
s.Equal(int64(3), size)
s.Equal(12, cache.LenQout())
}
4 changes: 4 additions & 0 deletions timeoutFifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func (f *timeoutFifo) delete(key string) {
delete(f.values, e.Value.(*timeoutFifoNode).key)
}
}

func (f *timeoutFifo) len() int {
return f.queue.Len()
}

0 comments on commit 18f69b2

Please sign in to comment.