From 33cc2473a3d6ca941717c557f8e72b9904fbdc4f Mon Sep 17 00:00:00 2001 From: zhangzengfei <zhangzengfei@smartai.com> Date: 星期五, 12 十一月 2021 15:20:58 +0800 Subject: [PATCH] add foreach, size api --- store_test.go | 26 ++++++++++++++++++-------- 1 files changed, 18 insertions(+), 8 deletions(-) diff --git a/store_test.go b/store_test.go index f1ba8f5..870c869 100644 --- a/store_test.go +++ b/store_test.go @@ -16,23 +16,33 @@ defer ls.Close() - go consume(ls) - - for i:=0; i<10000; i++{ - ls.ApplyLog([]byte("hello world "+strconv.Itoa(i))) - time.Sleep(time.Second * 1) + //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.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