seaweedfs/weed/util/log_buffer/log_buffer_test.go

43 lines
817 B
Go
Raw Permalink Normal View History

package log_buffer
import (
2020-04-20 10:08:10 +00:00
"fmt"
"math/rand"
"testing"
"time"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
)
2020-04-20 09:54:21 +00:00
func TestNewLogBufferFirstBuffer(t *testing.T) {
2021-06-27 12:51:28 +00:00
lb := NewLogBuffer("test", time.Minute, func(startTime, stopTime time.Time, buf []byte) {
}, func() {
})
startTime := time.Now()
messageSize := 1024
messageCount := 5000
var buf = make([]byte, messageSize)
for i := 0; i < messageCount; i++ {
rand.Read(buf)
lb.AddToBuffer(nil, buf, 0)
}
receivedmessageCount := 0
2021-06-27 12:51:28 +00:00
lb.LoopProcessLogData("test", startTime, func() bool {
// stop if no more messages
return false
}, func(logEntry *filer_pb.LogEntry) error {
receivedmessageCount++
return nil
})
if receivedmessageCount != messageCount {
2020-04-20 10:08:10 +00:00
fmt.Printf("sent %d received %d\n", messageCount, receivedmessageCount)
}
}