You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
820 B

5 years ago
  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("test", 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("test", startTime, 0, 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. }