aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/cache
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-01-16 13:12:58 +0000
committerJavi Fontan <jfontan@gmail.com>2018-01-16 13:12:58 +0000
commit0f6c06db068acb7a8eab639df20b72fa717232c8 (patch)
tree571dc4b1531475c8dd0cf8e7492b2a58eb5a126f /plumbing/cache
parentc281165b48d9901d391c583b6d7c28d37edb4ff5 (diff)
downloadgo-git-0f6c06db068acb7a8eab639df20b72fa717232c8.tar.gz
Test eviction of more than one object
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/cache')
-rw-r--r--plumbing/cache/object_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/plumbing/cache/object_test.go b/plumbing/cache/object_test.go
index ec01d60..ac3f0a3 100644
--- a/plumbing/cache/object_test.go
+++ b/plumbing/cache/object_test.go
@@ -19,6 +19,7 @@ type ObjectSuite struct {
bObject plumbing.EncodedObject
cObject plumbing.EncodedObject
dObject plumbing.EncodedObject
+ eObject plumbing.EncodedObject
}
var _ = Suite(&ObjectSuite{})
@@ -28,6 +29,7 @@ func (s *ObjectSuite) SetUpTest(c *C) {
s.bObject = newObject("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 3*Byte)
s.cObject = newObject("cccccccccccccccccccccccccccccccccccccccc", 1*Byte)
s.dObject = newObject("dddddddddddddddddddddddddddddddddddddddd", 1*Byte)
+ s.eObject = newObject("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 2*Byte)
s.c = make(map[string]Object)
s.c["two_bytes"] = NewObjectLRU(2 * Byte)
@@ -70,6 +72,24 @@ func (s *ObjectSuite) TestPutCacheOverflow(c *C) {
c.Assert(obj, NotNil)
}
+func (s *ObjectSuite) TestEvictMultipleObjects(c *C) {
+ o := s.c["two_bytes"]
+
+ o.Put(s.cObject)
+ o.Put(s.dObject) // now cache is full with two objects
+ o.Put(s.eObject) // this put should evict all previous objects
+
+ obj, ok := o.Get(s.cObject.Hash())
+ c.Assert(ok, Equals, false)
+ c.Assert(obj, IsNil)
+ obj, ok = o.Get(s.dObject.Hash())
+ c.Assert(ok, Equals, false)
+ c.Assert(obj, IsNil)
+ obj, ok = o.Get(s.eObject.Hash())
+ c.Assert(ok, Equals, true)
+ c.Assert(obj, NotNil)
+}
+
func (s *ObjectSuite) TestClear(c *C) {
for _, o := range s.c {
o.Put(s.aObject)