@@ -129,6 +129,65 @@ func TestContainer_PurgeV3(t *testing.T) {
129
129
assert .Less (t , int64 (result ), int64 (container .limit ))
130
130
}
131
131
132
+ func TestContainer_PurgeV4 (t * testing.T ) {
133
+ logger , _ := zap .NewDevelopment ()
134
+
135
+ container := container {
136
+ limit : 1024 * 1024 * 1024 * 5 ,
137
+ lifetime : time .Second * 5 ,
138
+ mutex : & sync.Mutex {},
139
+ index : make (map [string ]indexItem ),
140
+ sortedIndex : make (indexItemList , 0 ),
141
+ logger : logger ,
142
+ } // limit 5MB
143
+ container .start ()
144
+
145
+ type dI struct {
146
+ name string
147
+ data []byte
148
+ index int
149
+ }
150
+
151
+ for i := 0 ; i < 1024 ; i ++ {
152
+ dI := dI {
153
+ name : fmt .Sprintf ("a%d" , i + 1 ),
154
+ data : make ([]byte , 1024 * (i + 1 )),
155
+ index : i ,
156
+ }
157
+
158
+ container .Upsert (dI .name , 0 , 0 , dI .data )
159
+ if i == 0 {
160
+ container .sortedIndex [i ].expiresAt = time .Now ().UTC ().Add (time .Second )
161
+ continue
162
+ }
163
+ container .sortedIndex [i ].expiresAt = time .Now ().UTC ().Add (time .Second * - 1 )
164
+ }
165
+ container .Purge ()
166
+
167
+ assert .Equal (t , int64 (1024 ), container .usage )
168
+ }
169
+
170
+ func TestContainer_PurgeV5 (t * testing.T ) {
171
+ logger , _ := zap .NewDevelopment ()
172
+
173
+ container := container {
174
+ limit : 1024 * 1024 * 5 ,
175
+ lifetime : time .Second ,
176
+ mutex : & sync.Mutex {},
177
+ index : make (map [string ]indexItem ),
178
+ sortedIndex : make (indexItemList , 0 ),
179
+ logger : logger ,
180
+ } // limit 5MB
181
+ container .start ()
182
+
183
+ container .Upsert ("a1" , 5 , 21 , make ([]byte , 21 - 5 ))
184
+ container .Upsert ("a1" , 22 , 25 , make ([]byte , 25 - 22 ))
185
+ container .Upsert ("a1" , 18 , 23 , make ([]byte , 23 - 18 ))
186
+ time .Sleep (time .Second * 2 )
187
+
188
+ assert .Equal (t , int64 (0 ), container .usage )
189
+ }
190
+
132
191
func TestIndexItem_MatchRangeV1 (t * testing.T ) {
133
192
item := indexItem {
134
193
sha512Hex : "test" ,
0 commit comments