functional_consumer_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package sarama
  2. import (
  3. "math"
  4. "testing"
  5. )
  6. func TestFuncConsumerOffsetOutOfRange(t *testing.T) {
  7. setupFunctionalTest(t)
  8. defer teardownFunctionalTest(t)
  9. consumer, err := NewConsumer(kafkaBrokers, nil)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. if _, err := consumer.ConsumePartition("test.1", 0, -10); err != ErrOffsetOutOfRange {
  14. t.Error("Expected ErrOffsetOutOfRange, got:", err)
  15. }
  16. if _, err := consumer.ConsumePartition("test.1", 0, math.MaxInt64); err != ErrOffsetOutOfRange {
  17. t.Error("Expected ErrOffsetOutOfRange, got:", err)
  18. }
  19. safeClose(t, consumer)
  20. }
  21. func TestConsumerHighWaterMarkOffset(t *testing.T) {
  22. setupFunctionalTest(t)
  23. defer teardownFunctionalTest(t)
  24. p, err := NewSyncProducer(kafkaBrokers, nil)
  25. if err != nil {
  26. t.Fatal(err)
  27. }
  28. defer safeClose(t, p)
  29. _, offset, err := p.SendMessage(&ProducerMessage{Topic: "test.1", Value: StringEncoder("Test")})
  30. if err != nil {
  31. t.Fatal(err)
  32. }
  33. c, err := NewConsumer(kafkaBrokers, nil)
  34. if err != nil {
  35. t.Fatal(err)
  36. }
  37. defer safeClose(t, c)
  38. pc, err := c.ConsumePartition("test.1", 0, OffsetOldest)
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. <-pc.Messages()
  43. if hwmo := pc.HighWaterMarkOffset(); hwmo != offset+1 {
  44. t.Logf("Last produced offset %d; high water mark should be one higher but found %d.", offset, hwmo)
  45. }
  46. safeClose(t, pc)
  47. }