Skip to content

Commit

Permalink
Add a getter for replica ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Oct 26, 2018
1 parent ab3ad49 commit 8869e90
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions offset_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ func (r *OffsetRequest) SetReplicaID(id int32) {
r.replicaID = &r.storeReplicaID
}

func (r *OffsetRequest) ReplicaID() int32 {
if r.replicaID == nil {
return -1
}
return r.storeReplicaID
}

func (r *OffsetRequest) AddBlock(topic string, partitionID int32, time int64, maxOffsets int32) {
if r.blocks == nil {
r.blocks = make(map[string]map[int32]*offsetRequestBlock)
Expand Down
8 changes: 7 additions & 1 deletion offset_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ func TestOffsetRequestV1(t *testing.T) {

func TestOffsetRequestReplicaID(t *testing.T) {
request := new(OffsetRequest)
request.SetReplicaID(42)
replicaID := int32(42)
request.SetReplicaID(replicaID)

if found := request.ReplicaID(); found != replicaID {
t.Errorf("replicaID: expected %v, found %v", replicaID, found)
}

testRequest(t, "with replica ID", request, offsetRequestReplicaID)
}

0 comments on commit 8869e90

Please sign in to comment.