Skip to content

Commit

Permalink
Use native time type for ThrottleTime
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellLuo committed May 4, 2018
1 parent 0f1c3e9 commit 7d531e2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
13 changes: 8 additions & 5 deletions delete_groups_response.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package sarama

import (
"time"
)

type DeleteGroupsResponse struct {
ThrottleTimeMs int32
ThrottleTime time.Duration
GroupErrorCodes map[string]KError
}

func (r *DeleteGroupsResponse) encode(pe packetEncoder) error {
pe.putInt32(r.ThrottleTimeMs)
pe.putInt32(int32(r.ThrottleTime / time.Millisecond))

if err := pe.putArrayLength(len(r.GroupErrorCodes)); err != nil {
return err
Expand All @@ -22,12 +26,11 @@ func (r *DeleteGroupsResponse) encode(pe packetEncoder) error {
}

func (r *DeleteGroupsResponse) decode(pd packetDecoder, version int16) error {
throttleTimeMs, err := pd.getInt32()
throttleTime, err := pd.getInt32()
if err != nil {
return err
}

r.ThrottleTimeMs = throttleTimeMs
r.ThrottleTime = time.Duration(throttleTime) * time.Millisecond

n, err := pd.getArrayLength()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions delete_groups_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestDeleteGroupsResponse(t *testing.T) {

response = new(DeleteGroupsResponse)
testVersionDecodable(t, "empty", response, emptyDeleteGroupsResponse, 0)
if response.ThrottleTimeMs != 0 {
if response.ThrottleTime != 0 {
t.Error("Expected no violation")
}
if len(response.GroupErrorCodes) != 0 {
Expand All @@ -39,7 +39,7 @@ func TestDeleteGroupsResponse(t *testing.T) {

response = new(DeleteGroupsResponse)
testVersionDecodable(t, "error", response, errorDeleteGroupsResponse, 0)
if response.ThrottleTimeMs != 0 {
if response.ThrottleTime != 0 {
t.Error("Expected no violation")
}
if response.GroupErrorCodes["foo"] != ErrClusterAuthorizationFailed {
Expand All @@ -48,7 +48,7 @@ func TestDeleteGroupsResponse(t *testing.T) {

response = new(DeleteGroupsResponse)
testVersionDecodable(t, "no error", response, noErrorDeleteGroupsResponse, 0)
if response.ThrottleTimeMs != 0 {
if response.ThrottleTime != 0 {
t.Error("Expected no violation")
}
if response.GroupErrorCodes["foo"] != ErrNoError {
Expand Down

0 comments on commit 7d531e2

Please sign in to comment.