|
@@ -2,6 +2,10 @@ package sarama
|
|
|
|
|
|
import (
|
|
|
"errors"
|
|
|
+ "fmt"
|
|
|
+ "io/ioutil"
|
|
|
+ "log"
|
|
|
+ "os"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
)
|
|
@@ -511,6 +515,61 @@ func TestClusterAdminDescribeConfig(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// TestClusterAdminDescribeBrokerConfig ensures that a describe broker config
|
|
|
+// is sent to the broker in the resource struct, _not_ the controller
|
|
|
+func TestClusterAdminDescribeBrokerConfig(t *testing.T) {
|
|
|
+ Logger = log.New(os.Stdout, fmt.Sprintf("[%s] ", t.Name()), log.LstdFlags)
|
|
|
+ defer func() { Logger = log.New(ioutil.Discard, "[Sarama] ", log.LstdFlags) }()
|
|
|
+
|
|
|
+ controllerBroker := NewMockBroker(t, 1)
|
|
|
+ defer controllerBroker.Close()
|
|
|
+ configBroker := NewMockBroker(t, 2)
|
|
|
+ defer configBroker.Close()
|
|
|
+
|
|
|
+ controllerBroker.SetHandlerByMap(map[string]MockResponse{
|
|
|
+ "MetadataRequest": NewMockMetadataResponse(t).
|
|
|
+ SetController(controllerBroker.BrokerID()).
|
|
|
+ SetBroker(controllerBroker.Addr(), controllerBroker.BrokerID()).
|
|
|
+ SetBroker(configBroker.Addr(), configBroker.BrokerID()),
|
|
|
+ })
|
|
|
+
|
|
|
+ configBroker.SetHandlerByMap(map[string]MockResponse{
|
|
|
+ "MetadataRequest": NewMockMetadataResponse(t).
|
|
|
+ SetController(controllerBroker.BrokerID()).
|
|
|
+ SetBroker(controllerBroker.Addr(), controllerBroker.BrokerID()).
|
|
|
+ SetBroker(configBroker.Addr(), configBroker.BrokerID()),
|
|
|
+ "DescribeConfigsRequest": NewMockDescribeConfigsResponse(t),
|
|
|
+ })
|
|
|
+
|
|
|
+ config := NewConfig()
|
|
|
+ config.Version = V1_0_0_0
|
|
|
+ admin, err := NewClusterAdmin(
|
|
|
+ []string{
|
|
|
+ controllerBroker.Addr(),
|
|
|
+ configBroker.Addr(),
|
|
|
+ }, config)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, resourceType := range []ConfigResourceType{BrokerResource, BrokerLoggerResource} {
|
|
|
+ resource := ConfigResource{Name: "2", Type: resourceType}
|
|
|
+ entries, err := admin.DescribeConfig(resource)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(entries) <= 0 {
|
|
|
+ t.Fatal(errors.New("no resource present"))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = admin.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestClusterAdminAlterConfig(t *testing.T) {
|
|
|
seedBroker := NewMockBroker(t, 1)
|
|
|
defer seedBroker.Close()
|
|
@@ -544,6 +603,60 @@ func TestClusterAdminAlterConfig(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestClusterAdminAlterBrokerConfig(t *testing.T) {
|
|
|
+ controllerBroker := NewMockBroker(t, 1)
|
|
|
+ defer controllerBroker.Close()
|
|
|
+ configBroker := NewMockBroker(t, 2)
|
|
|
+ defer configBroker.Close()
|
|
|
+
|
|
|
+ controllerBroker.SetHandlerByMap(map[string]MockResponse{
|
|
|
+ "MetadataRequest": NewMockMetadataResponse(t).
|
|
|
+ SetController(controllerBroker.BrokerID()).
|
|
|
+ SetBroker(controllerBroker.Addr(), controllerBroker.BrokerID()).
|
|
|
+ SetBroker(configBroker.Addr(), configBroker.BrokerID()),
|
|
|
+ })
|
|
|
+ configBroker.SetHandlerByMap(map[string]MockResponse{
|
|
|
+ "MetadataRequest": NewMockMetadataResponse(t).
|
|
|
+ SetController(controllerBroker.BrokerID()).
|
|
|
+ SetBroker(controllerBroker.Addr(), controllerBroker.BrokerID()).
|
|
|
+ SetBroker(configBroker.Addr(), configBroker.BrokerID()),
|
|
|
+ "AlterConfigsRequest": NewMockAlterConfigsResponse(t),
|
|
|
+ })
|
|
|
+
|
|
|
+ config := NewConfig()
|
|
|
+ config.Version = V1_0_0_0
|
|
|
+ admin, err := NewClusterAdmin(
|
|
|
+ []string{
|
|
|
+ controllerBroker.Addr(),
|
|
|
+ configBroker.Addr(),
|
|
|
+ }, config)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var value string
|
|
|
+ entries := make(map[string]*string)
|
|
|
+ value = "3"
|
|
|
+ entries["min.insync.replicas"] = &value
|
|
|
+
|
|
|
+ for _, resourceType := range []ConfigResourceType{BrokerResource, BrokerLoggerResource} {
|
|
|
+ resource := ConfigResource{Name: "2", Type: resourceType}
|
|
|
+ err = admin.AlterConfig(
|
|
|
+ resource.Type,
|
|
|
+ resource.Name,
|
|
|
+ entries,
|
|
|
+ false)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ err = admin.Close()
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal(err)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestClusterAdminCreateAcl(t *testing.T) {
|
|
|
seedBroker := NewMockBroker(t, 1)
|
|
|
defer seedBroker.Close()
|