Browse Source

Merge pull request #93 from eapache/tweak-consumer-metadata

Consumer Metadata fields no longer optional
Willem van Bergen 10 years ago
parent
commit
df455fc45d
2 changed files with 18 additions and 17 deletions
  1. 11 13
      consumer_metadata_response.go
  2. 7 4
      consumer_metadata_response_test.go

+ 11 - 13
consumer_metadata_response.go

@@ -14,21 +14,19 @@ func (r *ConsumerMetadataResponse) decode(pd packetDecoder) (err error) {
 	}
 	r.Err = KError(tmp)
 
-	if r.Err == NoError {
-		r.CoordinatorId, err = pd.getInt32()
-		if err != nil {
-			return err
-		}
+	r.CoordinatorId, err = pd.getInt32()
+	if err != nil {
+		return err
+	}
 
-		r.CoordinatorHost, err = pd.getString()
-		if err != nil {
-			return err
-		}
+	r.CoordinatorHost, err = pd.getString()
+	if err != nil {
+		return err
+	}
 
-		r.CoordinatorPort, err = pd.getInt32()
-		if err != nil {
-			return err
-		}
+	r.CoordinatorPort, err = pd.getInt32()
+	if err != nil {
+		return err
 	}
 
 	return nil

+ 7 - 4
consumer_metadata_response_test.go

@@ -4,7 +4,10 @@ import "testing"
 
 var (
 	consumerMetadataResponseError = []byte{
-		0x00, 0x0E}
+		0x00, 0x0E,
+		0x00, 0x00, 0x00, 0x00,
+		0x00, 0x00,
+		0x00, 0x00, 0x00, 0x00}
 
 	consumerMetadataResponseSuccess = []byte{
 		0x00, 0x00,
@@ -23,15 +26,15 @@ func TestConsumerMetadataResponseError(t *testing.T) {
 	}
 
 	if response.CoordinatorId != 0 {
-		t.Error("Decoding produced ID when the message contained an error.")
+		t.Error("Decoding produced incorrect ID.")
 	}
 
 	if len(response.CoordinatorHost) != 0 {
-		t.Error("Decoding produced host when the message contained an error.")
+		t.Error("Decoding produced incorrect host.")
 	}
 
 	if response.CoordinatorPort != 0 {
-		t.Error("Decoding produced port when the message contained an error.")
+		t.Error("Decoding produced incorrect port.")
 	}
 }