Pārlūkot izejas kodu

Use native time type for ThrottleTime

RussellLuo 6 gadi atpakaļ
vecāks
revīzija
7d531e2557
2 mainītis faili ar 11 papildinājumiem un 8 dzēšanām
  1. 8 5
      delete_groups_response.go
  2. 3 3
      delete_groups_response_test.go

+ 8 - 5
delete_groups_response.go

@@ -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
@@ -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 {

+ 3 - 3
delete_groups_response_test.go

@@ -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 {
@@ -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 {
@@ -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 {