-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from Shopify/offset-manager
OffsetManager Implementation
- Loading branch information
Showing
5 changed files
with
907 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package sarama | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestFuncOffsetManager(t *testing.T) { | ||
checkKafkaVersion(t, "0.8.2") | ||
setupFunctionalTest(t) | ||
defer teardownFunctionalTest(t) | ||
|
||
client, err := NewClient(kafkaBrokers, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
offsetManager, err := NewOffsetManagerFromClient("sarama.TestFuncOffsetManager", client) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if _, err := offsetManager.ManagePartition("does_not_exist", 123); err != ErrUnknownTopicOrPartition { | ||
t.Fatal("Expected ErrUnknownTopicOrPartition when starting a partition offset manager for a partition that does not exist, got:", err) | ||
} | ||
|
||
pom1, err := offsetManager.ManagePartition("test.1", 0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
pom1.MarkOffset(10, "test metadata") | ||
safeClose(t, pom1) | ||
|
||
pom2, err := offsetManager.ManagePartition("test.1", 0) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
offset, metadata := pom2.NextOffset() | ||
|
||
if offset != 10+1 { | ||
t.Errorf("Expected the next offset to be 11, found %d.", offset) | ||
} | ||
if metadata != "test metadata" { | ||
t.Errorf("Expected metadata to be 'test metadata', found %s.", metadata) | ||
} | ||
|
||
safeClose(t, pom2) | ||
safeClose(t, offsetManager) | ||
safeClose(t, client) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.