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