| 1 | // Copyright (c) 2012, Suryandaru Triandana <[email protected]> |
| 2 | // All rights reserved. |
| 3 | // |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | |
| 7 | package cachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/ |
| 8 | |
| 9 | import ( |
| 10 | "math/randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/" |
| 11 | "runtimescip-go gomod github.com/golang/go/src go1.14 runtime/" |
| 12 | "syncscip-go gomod github.com/golang/go/src go1.14 sync/" |
| 13 | "sync/atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/" |
| 14 | "testingscip-go gomod github.com/golang/go/src go1.14 testing/" |
| 15 | "timescip-go gomod github.com/golang/go/src go1.14 time/" |
| 16 | "unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/" |
| 17 | ) |
| 18 | |
| 19 | type int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o# int32 |
| 20 | |
| 21 | func (o *int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#) acquirescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#acquire().() { |
| 22 | if atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt32().((*int32)(o), 1) != 1 { |
| 23 | panic("BUG: invalid ref") |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | func (o *int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#) Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#Release().() { |
| 28 | if atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt32().((*int32)(o), -1) != 0 { |
| 29 | panic("BUG: invalid ref") |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | type releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc# struct { |
| 34 | fnscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#fn. func() |
| 35 | valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#value. Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value# |
| 36 | } |
| 37 | |
| 38 | func (r releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#) Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#Release().() { |
| 39 | if r.fnscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#fn. != nil { |
| 40 | r.fnscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#fn.() |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c *Cachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#, ns, key uint64, value Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#, charge int, relf func()) *Handlescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle# { |
| 45 | return c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(ns, key, func() (int, Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#) { |
| 46 | if relf != nil { |
| 47 | return charge, releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#{relf, value} |
| 48 | } |
| 49 | return charge, value |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | type cacheMapTestParamsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams# struct { |
| 54 | nobjectsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#nobjects., nhandlesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#nhandles., concurrentscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#concurrent., repeatscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#repeat. int |
| 55 | } |
| 56 | |
| 57 | func TestCacheMapscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestCacheMap().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 58 | runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.14 runtime/GOMAXPROCS().(runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.NumCPUscip-go gomod github.com/golang/go/src go1.14 runtime/NumCPU().()) |
| 59 | |
| 60 | var params []cacheMapTestParamsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams# |
| 61 | if testingscip-go gomod github.com/golang/go/src go1.14 testing/.Shortscip-go gomod github.com/golang/go/src go1.14 testing/Short().() { |
| 62 | params = []cacheMapTestParamsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#{ |
| 63 | {1000, 100, 20, 3}, |
| 64 | {10000, 300, 50, 10}, |
| 65 | } |
| 66 | } else { |
| 67 | params = []cacheMapTestParamsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#{ |
| 68 | {10000, 400, 50, 3}, |
| 69 | {100000, 1000, 100, 10}, |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | var ( |
| 74 | objects [][]int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o# |
| 75 | handles [][]unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer |
| 76 | ) |
| 77 | |
| 78 | for _, x := range params { |
| 79 | objects = append(objects, make([]int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#, x.nobjectsscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#nobjects.)) |
| 80 | handles = append(handles, make([]unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer, x.nhandlesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#nhandles.)) |
| 81 | } |
| 82 | |
| 83 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(nil) |
| 84 | |
| 85 | wg := new(syncscip-go gomod github.com/golang/go/src go1.14 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#) |
| 86 | var done int32 |
| 87 | |
| 88 | for ns, x := range params { |
| 89 | for i := 0; i < x.concurrentscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#concurrent.; i++ { |
| 90 | wg.Addscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Add().(1) |
| 91 | go func(ns, i, repeat int, objects []int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#, handles []unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer) { |
| 92 | defer wg.Donescip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Done().() |
| 93 | r := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.14 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.14 `math/rand`/NewSource().(timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.14 time/Time#UnixNano().())) |
| 94 | |
| 95 | for j := len(objects) * repeat; j >= 0; j-- { |
| 96 | key := uint64(r.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Rand#Intn().(len(objects))) |
| 97 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(uint64(ns), key, func() (int, Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#) { |
| 98 | o := &objects[key] |
| 99 | o.acquirescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#acquire().() |
| 100 | return 1, o |
| 101 | }) |
| 102 | if v := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(*int32oscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/int32o#); v != &objects[key] { |
| 103 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("#%d invalid value: want=%p got=%p", ns, &objects[key], v) |
| 104 | } |
| 105 | if objects[key] != 1 { |
| 106 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("#%d invalid object %d: %d", ns, key, objects[key]) |
| 107 | } |
| 108 | if !atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.CompareAndSwapPointerscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/CompareAndSwapPointer().(&handles[r.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Rand#Intn().(len(handles))], nil, unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer(h)) { |
| 109 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 110 | } |
| 111 | } |
| 112 | }(ns, i, x.repeatscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/cacheMapTestParams#repeat., objects[ns], handles[ns]) |
| 113 | } |
| 114 | |
| 115 | go func(handles []unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer) { |
| 116 | r := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.14 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.14 `math/rand`/NewSource().(timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.14 time/Time#UnixNano().())) |
| 117 | |
| 118 | for atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadInt32().(&done) == 0 { |
| 119 | i := r.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Rand#Intn().(len(handles)) |
| 120 | h := (*Handlescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#)(atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadPointerscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadPointer().(&handles[i])) |
| 121 | if h != nil && atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.CompareAndSwapPointerscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/CompareAndSwapPointer().(&handles[i], unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer(h), nil) { |
| 122 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 123 | } |
| 124 | timescip-go gomod github.com/golang/go/src go1.14 time/.Sleepscip-go gomod github.com/golang/go/src go1.14 time/Sleep().(timescip-go gomod github.com/golang/go/src go1.14 time/.Millisecondscip-go gomod github.com/golang/go/src go1.14 time/Millisecond.) |
| 125 | } |
| 126 | }(handles[ns]) |
| 127 | } |
| 128 | |
| 129 | go func() { |
| 130 | handles := make([]*Handlescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#, 100000) |
| 131 | for atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadInt32().(&done) == 0 { |
| 132 | for i := range handles { |
| 133 | handles[i] = c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(999999999, uint64(i), func() (int, Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#) { |
| 134 | return 1, 1 |
| 135 | }) |
| 136 | } |
| 137 | for _, h := range handles { |
| 138 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 139 | } |
| 140 | } |
| 141 | }() |
| 142 | |
| 143 | wg.Waitscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Wait().() |
| 144 | |
| 145 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.StoreInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/StoreInt32().(&done, 1) |
| 146 | |
| 147 | for _, handles0 := range handles { |
| 148 | for i := range handles0 { |
| 149 | h := (*Handlescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#)(atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadPointerscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadPointer().(&handles0[i])) |
| 150 | if h != nil && atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.CompareAndSwapPointerscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/CompareAndSwapPointer().(&handles0[i], unsafescip-go gomod github.com/golang/go/src go1.14 unsafe/.Pointer(h), nil) { |
| 151 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | for ns, objects0 := range objects { |
| 157 | for i, o := range objects0 { |
| 158 | if o != 0 { |
| 159 | t.Fatalfscip-go gomod github.com/golang/go/src go1.14 testing/common#Fatalf().("invalid object #%d.%d: ref=%d", ns, i, o) |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | func TestCacheMap_NodesAndSizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestCacheMap_NodesAndSize().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 166 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(nil) |
| 167 | if c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().() != 0 { |
| 168 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid nodes counter: want=%d got=%d", 0, c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().()) |
| 169 | } |
| 170 | if c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().() != 0 { |
| 171 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid size counter: want=%d got=%d", 0, c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().()) |
| 172 | } |
| 173 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, nil) |
| 174 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 2, nil) |
| 175 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 1, 1, 3, 3, nil) |
| 176 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 1, 4, 1, nil) |
| 177 | if c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().() != 4 { |
| 178 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid nodes counter: want=%d got=%d", 4, c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().()) |
| 179 | } |
| 180 | if c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().() != 7 { |
| 181 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid size counter: want=%d got=%d", 4, c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().()) |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func TestLRUCache_Capacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_Capacity().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 186 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(10)) |
| 187 | if c.Capacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Capacity().() != 10 { |
| 188 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid capacity: want=%d got=%d", 10, c.Capacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Capacity().()) |
| 189 | } |
| 190 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 191 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 2, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 192 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 1, 1, 3, 3, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 193 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 1, 4, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 194 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 2, 5, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 195 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 3, 6, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 196 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 4, 7, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 197 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 5, 8, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 198 | if c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().() != 7 { |
| 199 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid nodes counter: want=%d got=%d", 7, c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().()) |
| 200 | } |
| 201 | if c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().() != 10 { |
| 202 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid size counter: want=%d got=%d", 10, c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().()) |
| 203 | } |
| 204 | c.SetCapacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#SetCapacity().(9) |
| 205 | if c.Capacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Capacity().() != 9 { |
| 206 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid capacity: want=%d got=%d", 9, c.Capacityscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Capacity().()) |
| 207 | } |
| 208 | if c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().() != 6 { |
| 209 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid nodes counter: want=%d got=%d", 6, c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().()) |
| 210 | } |
| 211 | if c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().() != 8 { |
| 212 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid size counter: want=%d got=%d", 8, c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().()) |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | func TestCacheMap_NilValuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestCacheMap_NilValue().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 217 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(10)) |
| 218 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 0, func() (size int, value Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#) { |
| 219 | return 1, nil |
| 220 | }) |
| 221 | if h != nil { |
| 222 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("cache handle is non-nil") |
| 223 | } |
| 224 | if c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().() != 0 { |
| 225 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid nodes counter: want=%d got=%d", 0, c.Nodesscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Nodes().()) |
| 226 | } |
| 227 | if c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().() != 0 { |
| 228 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid size counter: want=%d got=%d", 0, c.Sizescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Size().()) |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | func TestLRUCache_GetLatencyscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_GetLatency().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 233 | runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.GOMAXPROCSscip-go gomod github.com/golang/go/src go1.14 runtime/GOMAXPROCS().(runtimescip-go gomod github.com/golang/go/src go1.14 runtime/.NumCPUscip-go gomod github.com/golang/go/src go1.14 runtime/NumCPU().()) |
| 234 | |
| 235 | const ( |
| 236 | concurrentSet = 30 |
| 237 | concurrentGet = 3 |
| 238 | duration = 3 * timescip-go gomod github.com/golang/go/src go1.14 time/.Secondscip-go gomod github.com/golang/go/src go1.14 time/Second. |
| 239 | delay = 3 * timescip-go gomod github.com/golang/go/src go1.14 time/.Millisecondscip-go gomod github.com/golang/go/src go1.14 time/Millisecond. |
| 240 | maxkey = 100000 |
| 241 | ) |
| 242 | |
| 243 | var ( |
| 244 | set, getHit, getAll int32 |
| 245 | getMaxLatency, getDuration int64 |
| 246 | ) |
| 247 | |
| 248 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(5000)) |
| 249 | wg := &syncscip-go gomod github.com/golang/go/src go1.14 sync/.WaitGroupscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#{} |
| 250 | until := timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().Addscip-go gomod github.com/golang/go/src go1.14 time/Time#Add().(duration) |
| 251 | for i := 0; i < concurrentSet; i++ { |
| 252 | wg.Addscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Add().(1) |
| 253 | go func(i int) { |
| 254 | defer wg.Donescip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Done().() |
| 255 | r := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.14 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.14 `math/rand`/NewSource().(timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.14 time/Time#UnixNano().())) |
| 256 | for timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().Beforescip-go gomod github.com/golang/go/src go1.14 time/Time#Before().(until) { |
| 257 | c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, uint64(r.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Rand#Intn().(maxkey)), func() (int, Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Value#) { |
| 258 | timescip-go gomod github.com/golang/go/src go1.14 time/.Sleepscip-go gomod github.com/golang/go/src go1.14 time/Sleep().(delay) |
| 259 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt32().(&set, 1) |
| 260 | return 1, 1 |
| 261 | }).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 262 | } |
| 263 | }(i) |
| 264 | } |
| 265 | for i := 0; i < concurrentGet; i++ { |
| 266 | wg.Addscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Add().(1) |
| 267 | go func(i int) { |
| 268 | defer wg.Donescip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Done().() |
| 269 | r := randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.Newscip-go gomod github.com/golang/go/src go1.14 `math/rand`/New().(randscip-go gomod github.com/golang/go/src go1.14 `math/rand`/.NewSourcescip-go gomod github.com/golang/go/src go1.14 `math/rand`/NewSource().(timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().UnixNanoscip-go gomod github.com/golang/go/src go1.14 time/Time#UnixNano().())) |
| 270 | for { |
| 271 | mark := timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().() |
| 272 | if mark.Beforescip-go gomod github.com/golang/go/src go1.14 time/Time#Before().(until) { |
| 273 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, uint64(r.Intnscip-go gomod github.com/golang/go/src go1.14 `math/rand`/Rand#Intn().(maxkey)), nil) |
| 274 | latency := int64(timescip-go gomod github.com/golang/go/src go1.14 time/.Nowscip-go gomod github.com/golang/go/src go1.14 time/Now().().Subscip-go gomod github.com/golang/go/src go1.14 time/Time#Sub().(mark)) |
| 275 | m := atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.LoadInt64scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/LoadInt64().(&getMaxLatency) |
| 276 | if latency > m { |
| 277 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.CompareAndSwapInt64scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/CompareAndSwapInt64().(&getMaxLatency, m, latency) |
| 278 | } |
| 279 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt64scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt64().(&getDuration, latency) |
| 280 | if h != nil { |
| 281 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt32().(&getHit, 1) |
| 282 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 283 | } |
| 284 | atomicscip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/.AddInt32scip-go gomod github.com/golang/go/src go1.14 `sync/atomic`/AddInt32().(&getAll, 1) |
| 285 | } else { |
| 286 | break |
| 287 | } |
| 288 | } |
| 289 | }(i) |
| 290 | } |
| 291 | |
| 292 | wg.Waitscip-go gomod github.com/golang/go/src go1.14 sync/WaitGroup#Wait().() |
| 293 | getAvglatency := timescip-go gomod github.com/golang/go/src go1.14 time/.Durationscip-go gomod github.com/golang/go/src go1.14 time/Duration#(getDuration) / timescip-go gomod github.com/golang/go/src go1.14 time/.Durationscip-go gomod github.com/golang/go/src go1.14 time/Duration#(getAll) |
| 294 | t.Logfscip-go gomod github.com/golang/go/src go1.14 testing/common#Logf().("set=%d getHit=%d getAll=%d getMaxLatency=%v getAvgLatency=%v", |
| 295 | set, getHit, getAll, timescip-go gomod github.com/golang/go/src go1.14 time/.Durationscip-go gomod github.com/golang/go/src go1.14 time/Duration#(getMaxLatency), getAvglatency) |
| 296 | |
| 297 | if getAvglatency > delay/3 { |
| 298 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("get avg latency > %v: got=%v", delay/3, getAvglatency) |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | func TestLRUCache_HitMissscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_HitMiss().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 303 | cases := []struct { |
| 304 | key uint64 |
| 305 | value string |
| 306 | }{ |
| 307 | {1, "vvvvvvvvv"}, |
| 308 | {100, "v1"}, |
| 309 | {0, "v2"}, |
| 310 | {12346, "v3"}, |
| 311 | {777, "v4"}, |
| 312 | {999, "v5"}, |
| 313 | {7654, "v6"}, |
| 314 | {2, "v7"}, |
| 315 | {3, "v8"}, |
| 316 | {9, "v9"}, |
| 317 | } |
| 318 | |
| 319 | setfin := 0 |
| 320 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(1000)) |
| 321 | for i, x := range cases { |
| 322 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, x.key, x.value, len(x.value), func() { |
| 323 | setfin++ |
| 324 | }).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 325 | for j, y := range cases { |
| 326 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, y.key, nil) |
| 327 | if j <= i { |
| 328 | // should hit |
| 329 | if h == nil { |
| 330 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' is miss", i, j) |
| 331 | } else { |
| 332 | if x := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#).valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#value..(string); x != y.value { |
| 333 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' has invalid value got '%s', want '%s'", i, j, x, y.value) |
| 334 | } |
| 335 | } |
| 336 | } else { |
| 337 | // should miss |
| 338 | if h != nil { |
| 339 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' is hit , value '%s'", i, j, h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#).valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#value..(string)) |
| 340 | } |
| 341 | } |
| 342 | if h != nil { |
| 343 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | for i, x := range cases { |
| 349 | finalizerOk := false |
| 350 | c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, x.key, func() { |
| 351 | finalizerOk = true |
| 352 | }) |
| 353 | |
| 354 | if !finalizerOk { |
| 355 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case %d delete finalizer not executed", i) |
| 356 | } |
| 357 | |
| 358 | for j, y := range cases { |
| 359 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, y.key, nil) |
| 360 | if j > i { |
| 361 | // should hit |
| 362 | if h == nil { |
| 363 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' is miss", i, j) |
| 364 | } else { |
| 365 | if x := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#).valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#value..(string); x != y.value { |
| 366 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' has invalid value got '%s', want '%s'", i, j, x, y.value) |
| 367 | } |
| 368 | } |
| 369 | } else { |
| 370 | // should miss |
| 371 | if h != nil { |
| 372 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("case '%d' iteration '%d' is hit, value '%s'", i, j, h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(releaserFuncscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#).valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/releaserFunc#value..(string)) |
| 373 | } |
| 374 | } |
| 375 | if h != nil { |
| 376 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | if setfin != len(cases) { |
| 382 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("some set finalizer may not be executed, want=%d got=%d", len(cases), setfin) |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | func TestLRUCache_Evictionscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_Eviction().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 387 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(12)) |
| 388 | o1 := setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, nil) |
| 389 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 390 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 3, 3, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 391 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 4, 4, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 392 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 5, 5, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 393 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 2, nil); h != nil { // 1,3,4,5,2 |
| 394 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 395 | } |
| 396 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 9, 9, 10, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() // 5,2,9 |
| 397 | |
| 398 | for _, key := range []uint64{9, 2, 5, 1} { |
| 399 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, key, nil) |
| 400 | if h == nil { |
| 401 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("miss for key '%d'", key) |
| 402 | } else { |
| 403 | if x := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(int); x != int(key) { |
| 404 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid value for key '%d' want '%d', got '%d'", key, key, x) |
| 405 | } |
| 406 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 407 | } |
| 408 | } |
| 409 | o1.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 410 | for _, key := range []uint64{1, 2, 5} { |
| 411 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, key, nil) |
| 412 | if h == nil { |
| 413 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("miss for key '%d'", key) |
| 414 | } else { |
| 415 | if x := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(int); x != int(key) { |
| 416 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid value for key '%d' want '%d', got '%d'", key, key, x) |
| 417 | } |
| 418 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 419 | } |
| 420 | } |
| 421 | for _, key := range []uint64{3, 4, 9} { |
| 422 | h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, key, nil) |
| 423 | if h != nil { |
| 424 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("hit for key '%d'", key) |
| 425 | if x := h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().().(int); x != int(key) { |
| 426 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("invalid value for key '%d' want '%d', got '%d'", key, key, x) |
| 427 | } |
| 428 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | func TestLRUCache_Evictscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_Evict().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 434 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(6)) |
| 435 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 436 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 437 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 1, 1, 4, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 438 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 1, 2, 5, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 439 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 1, 6, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 440 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 2, 2, 7, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 441 | |
| 442 | for ns := 0; ns < 3; ns++ { |
| 443 | for key := 1; key < 3; key++ { |
| 444 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(uint64(ns), uint64(key), nil); h != nil { |
| 445 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 446 | } else { |
| 447 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #%d.%d return nil", ns, key) |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | if ok := c.Evictscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Evict().(0, 1); !ok { |
| 453 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("first Cache.Evict on #0.1 return false") |
| 454 | } |
| 455 | if ok := c.Evictscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Evict().(0, 1); ok { |
| 456 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("second Cache.Evict on #0.1 return true") |
| 457 | } |
| 458 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 1, nil); h != nil { |
| 459 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #0.1 return non-nil: %v", h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 460 | } |
| 461 | |
| 462 | c.EvictNSscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#EvictNS().(1) |
| 463 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(1, 1, nil); h != nil { |
| 464 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #1.1 return non-nil: %v", h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 465 | } |
| 466 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(1, 2, nil); h != nil { |
| 467 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #1.2 return non-nil: %v", h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 468 | } |
| 469 | |
| 470 | c.EvictAllscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#EvictAll().() |
| 471 | for ns := 0; ns < 3; ns++ { |
| 472 | for key := 1; key < 3; key++ { |
| 473 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(uint64(ns), uint64(key), nil); h != nil { |
| 474 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #%d.%d return non-nil: %v", ns, key, h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | func TestLRUCache_Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_Delete().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 481 | delFuncCalled := 0 |
| 482 | delFunc := func() { |
| 483 | delFuncCalled++ |
| 484 | } |
| 485 | |
| 486 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(2)) |
| 487 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 488 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 489 | |
| 490 | if ok := c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, 1, delFunc); !ok { |
| 491 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("Cache.Delete on #1 return false") |
| 492 | } |
| 493 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 1, nil); h != nil { |
| 494 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #1 return non-nil: %v", h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 495 | } |
| 496 | if ok := c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, 1, delFunc); ok { |
| 497 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("Cache.Delete on #1 return true") |
| 498 | } |
| 499 | |
| 500 | h2 := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 2, nil) |
| 501 | if h2 == nil { |
| 502 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("Cache.Get on #2 return nil") |
| 503 | } |
| 504 | if ok := c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, 2, delFunc); !ok { |
| 505 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("(1) Cache.Delete on #2 return false") |
| 506 | } |
| 507 | if ok := c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, 2, delFunc); !ok { |
| 508 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("(2) Cache.Delete on #2 return false") |
| 509 | } |
| 510 | |
| 511 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 3, 3, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 512 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 4, 4, 1, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 513 | c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 2, nil).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 514 | |
| 515 | for key := 2; key <= 4; key++ { |
| 516 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, uint64(key), nil); h != nil { |
| 517 | h.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 518 | } else { |
| 519 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #%d return nil", key) |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | h2.Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 524 | if h := c.Getscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Get().(0, 2, nil); h != nil { |
| 525 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("Cache.Get on #2 return non-nil: %v", h.Valuescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Value().()) |
| 526 | } |
| 527 | |
| 528 | if delFuncCalled != 4 { |
| 529 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("delFunc isn't called 4 times: got=%d", delFuncCalled) |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | func TestLRUCache_Closescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/TestLRUCache_Close().(t *testingscip-go gomod github.com/golang/go/src go1.14 testing/.Tscip-go gomod github.com/golang/go/src go1.14 testing/T#) { |
| 534 | relFuncCalled := 0 |
| 535 | relFunc := func() { |
| 536 | relFuncCalled++ |
| 537 | } |
| 538 | delFuncCalled := 0 |
| 539 | delFunc := func() { |
| 540 | delFuncCalled++ |
| 541 | } |
| 542 | |
| 543 | c := NewCachescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewCache().(NewLRUscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/NewLRU().(2)) |
| 544 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 1, 1, 1, relFunc).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 545 | setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 2, 2, 1, relFunc).Releasescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Handle#Release().() |
| 546 | |
| 547 | h3 := setscip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/set().(c, 0, 3, 3, 1, relFunc) |
| 548 | if h3 == nil { |
| 549 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("Cache.Get on #3 return nil") |
| 550 | } |
| 551 | if ok := c.Deletescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Delete().(0, 3, delFunc); !ok { |
| 552 | t.Errorscip-go gomod github.com/golang/go/src go1.14 testing/common#Error().("Cache.Delete on #3 return false") |
| 553 | } |
| 554 | |
| 555 | c.Closescip-go gomod github.com/syndtr/goleveldb . `github.com/syndtr/goleveldb/leveldb/cache`/Cache#Close().() |
| 556 | |
| 557 | if relFuncCalled != 3 { |
| 558 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("relFunc isn't called 3 times: got=%d", relFuncCalled) |
| 559 | } |
| 560 | if delFuncCalled != 1 { |
| 561 | t.Errorfscip-go gomod github.com/golang/go/src go1.14 testing/common#Errorf().("delFunc isn't called 1 times: got=%d", delFuncCalled) |
| 562 | } |
| 563 | } |