log_buffer_test.go 801 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package log_buffer
  2. import (
  3. "fmt"
  4. "math/rand"
  5. "testing"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. )
  9. func TestNewLogBufferFirstBuffer(t *testing.T) {
  10. lb := NewLogBuffer(time.Minute, func(startTime, stopTime time.Time, buf []byte) {
  11. }, func() {
  12. })
  13. startTime := time.Now()
  14. messageSize := 1024
  15. messageCount := 5000
  16. var buf = make([]byte, messageSize)
  17. for i := 0; i < messageCount; i++ {
  18. rand.Read(buf)
  19. lb.AddToBuffer(nil, buf, 0)
  20. }
  21. receivedmessageCount := 0
  22. lb.LoopProcessLogData(startTime, func() bool {
  23. // stop if no more messages
  24. return false
  25. }, func(logEntry *filer_pb.LogEntry) error {
  26. receivedmessageCount++
  27. return nil
  28. })
  29. if receivedmessageCount != messageCount {
  30. fmt.Printf("sent %d received %d\n", messageCount, receivedmessageCount)
  31. }
  32. }