functional_offset_manager_test.go 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package sarama
  2. import (
  3. "testing"
  4. )
  5. func TestFuncOffsetManager(t *testing.T) {
  6. checkKafkaVersion(t, "0.8.2")
  7. setupFunctionalTest(t)
  8. defer teardownFunctionalTest(t)
  9. client, err := NewClient(kafkaBrokers, nil)
  10. if err != nil {
  11. t.Fatal(err)
  12. }
  13. offsetManager, err := NewOffsetManagerFromClient("sarama.TestFuncOffsetManager", client)
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. pom1, err := offsetManager.ManagePartition("test.1", 0)
  18. if err != nil {
  19. t.Fatal(err)
  20. }
  21. pom1.MarkOffset(10, "test metadata")
  22. safeClose(t, pom1)
  23. pom2, err := offsetManager.ManagePartition("test.1", 0)
  24. if err != nil {
  25. t.Fatal(err)
  26. }
  27. offset, metadata := pom2.NextOffset()
  28. if offset != 10 {
  29. t.Errorf("Expected the next offset to be 10, found %d.", offset)
  30. }
  31. if metadata != "test metadata" {
  32. t.Errorf("Expected metadata to be 'test metadata', found %s.", metadata)
  33. }
  34. safeClose(t, pom2)
  35. safeClose(t, offsetManager)
  36. safeClose(t, client)
  37. }