package boltcache import ( "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 < 10; i++ { // ls.ApplyLog([]byte("hello world " + strconv.Itoa(i))) // time.Sleep(time.Millisecond * 100) //} ls.printLog("Size = ", ls.Size()) var logs []*LogCon ls.ForEach(func(log *LogCon) error { ls.printLog("val=:", string(log.GetData())) logs = append(logs, log) time.Sleep(time.Millisecond * 100) return nil }) for _, log := range logs { ls.Delete(log) } //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) } }