From c3ed6822b959e78bae3673b86b9b990ae92e1cc5 Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期二, 18 十月 2022 11:19:51 +0800 Subject: [PATCH] 添加bolt源码 --- store_test.go | 35 ++++++++++++++++++++++++++--------- 1 files changed, 26 insertions(+), 9 deletions(-) diff --git a/store_test.go b/store_test.go index f1ba8f5..bea420d 100644 --- a/store_test.go +++ b/store_test.go @@ -1,7 +1,6 @@ package boltcache import ( - "strconv" "testing" "time" ) @@ -16,23 +15,41 @@ defer ls.Close() - go consume(ls) + //go consume(ls) + // + //for i := 0; i < 10; i++ { + // ls.ApplyLog([]byte("hello world " + strconv.Itoa(i))) + // time.Sleep(time.Millisecond * 100) + //} - for i:=0; i<10000; i++{ - ls.ApplyLog([]byte("hello world "+strconv.Itoa(i))) - time.Sleep(time.Second * 1) + 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.printLog(lc.conf.BucketName, " send old log:", string(lc.Log.Data)) ls.Delete(lc) + } else { + return } - time.Sleep(10 * time.Second) + time.Sleep(10 * time.Millisecond) } -} \ No newline at end of file +} -- Gitblit v1.8.0