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.

41 lines
775 B

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