zhangzengfei
2021-11-12 33cc2473a3d6ca941717c557f8e72b9904fbdc4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package boltcache
 
import (
    "strconv"
    "testing"
    "time"
)
 
func TestInit(t *testing.T) {
    conf := NewDefaultConfig()
    ls, err := Init(conf)
    if err != nil {
        ls.printLog("Init err:", err)
        return
    }
 
    defer ls.Close()
 
    //go consume(ls)
    //
    for i := 0; i < 100; i++ {
        ls.ApplyLog([]byte("hello world " + strconv.Itoa(i)))
        time.Sleep(time.Millisecond * 100)
    }
 
    ls.printLog("Size = ", ls.Size())
 
    ls.ForEach(func(v []byte) error {
        ls.printLog("val=:", string(v))
        return nil
    })
 
    consume(ls)
}
 
func consume(ls *LogStore) {
    for {
        lc := ls.Get()
        if lc != nil {
            ls.printLog(lc.conf.BucketName, " send old log:", string(lc.Log.Data))
            ls.Delete(lc)
        } else {
            return
        }
 
        time.Sleep(10 * time.Millisecond)
    }
}