Skip to content

Commit

Permalink
Guard against using LZ4 with old kafka protocol versions
Browse files Browse the repository at this point in the history
  • Loading branch information
rtreffer-sc committed Nov 22, 2016
1 parent fea677b commit 645b029
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ func (c *Config) Validate() error {
return ConfigurationError("Producer.Retry.Backoff must be >= 0")
}

if c.Producer.Compression == CompressionLZ4 && (c.Version == V0_8_2_0 || c.Version == V0_8_2_1 ||
c.Version == V0_8_2_2 || c.Version == V0_9_0_0 ||
c.Version == V0_9_0_1) {
return ConfigurationError("lz4 compression requires Version >= V0_10_0_0")
}

// validate the Consumer values
switch {
case c.Consumer.Fetch.Min <= 0:
Expand Down
12 changes: 12 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ func TestEmptyClientIDConfigValidates(t *testing.T) {
}
}

func TestLZ4ConfigValidation(t *testing.T) {
config := NewConfig()
config.Producer.Compression = CompressionLZ4
if err := config.Validate(); string(err.(ConfigurationError)) != "lz4 compression requires Version >= V0_10_0_0" {
t.Error("Expected invalid lz4/kakfa version error, got ", err)
}
config.Version = V0_10_0_0
if err := config.Validate(); err != nil {
t.Error("Expected lz4 to work, got ", err)
}
}

// This example shows how to integrate with an existing registry as well as publishing metrics
// on the standard output
func ExampleConfig_metrics() {
Expand Down

0 comments on commit 645b029

Please sign in to comment.