From 533de70cbd64280d8d25460b94174823c5da624f Mon Sep 17 00:00:00 2001 From: Cody Soyland Date: Tue, 26 Jun 2018 11:22:48 -0500 Subject: [PATCH] Allow passing slice of CommandOptions to MustRunMainWithCluster, each slice going to one Command --- http/translator_test.go | 6 +++--- server/handler_test.go | 3 ++- server_test.go | 3 ++- test/pilosa.go | 13 ++++++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/http/translator_test.go b/http/translator_test.go index 5236c43db..15aef62a4 100644 --- a/http/translator_test.go +++ b/http/translator_test.go @@ -54,7 +54,7 @@ func TestTranslateStore_Reader(t *testing.T) { } opts := server.OptCommandServerOptions(pilosa.OptServerPrimaryTranslateStore(translateStore)) - main := test.MustRunMainWithCluster(t, 1, opts)[0] + main := test.MustRunMainWithCluster(t, 1, []server.CommandOption{opts})[0] defer main.Close() // Connect to server and stream all available data. @@ -98,7 +98,7 @@ func TestTranslateStore_Reader(t *testing.T) { } opts := server.OptCommandServerOptions(pilosa.OptServerPrimaryTranslateStore(translateStore)) - main := test.MustRunMainWithCluster(t, 1, opts)[0] + main := test.MustRunMainWithCluster(t, 1, []server.CommandOption{opts})[0] defer main.Close() defer close(done) @@ -127,7 +127,7 @@ func TestTranslateStore_Reader(t *testing.T) { } opts := server.OptCommandServerOptions(pilosa.OptServerPrimaryTranslateStore(translateStore)) - main := test.MustRunMainWithCluster(t, 1, opts)[0] + main := test.MustRunMainWithCluster(t, 1, []server.CommandOption{opts})[0] _, err := http.NewTranslateStore(main.Server.URI.String()).Reader(context.Background(), 0) if err != pilosa.ErrNotImplemented { diff --git a/server/handler_test.go b/server/handler_test.go index 070a3176a..cc21b8825 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -31,6 +31,7 @@ import ( "github.com/pilosa/pilosa" "github.com/pilosa/pilosa/http" "github.com/pilosa/pilosa/internal" + "github.com/pilosa/pilosa/server" "github.com/pilosa/pilosa/test" ) @@ -565,7 +566,7 @@ func TestHandler_Endpoints(t *testing.T) { t.Fatalf("CORS preflight status should be 405, but is %v", result.StatusCode) } - clus := test.MustRunMainWithCluster(t, 1, test.OptAllowedOrigins([]string{"http://test/"})) + clus := test.MustRunMainWithCluster(t, 1, []server.CommandOption{test.OptAllowedOrigins([]string{"http://test/"})}) w = httptest.NewRecorder() h := clus[0].Handler.(*http.Handler).Handler h.ServeHTTP(w, req) diff --git a/server_test.go b/server_test.go index 402d4de7d..9a94da8a2 100644 --- a/server_test.go +++ b/server_test.go @@ -20,6 +20,7 @@ import ( "time" "github.com/pilosa/pilosa" + "github.com/pilosa/pilosa/server" "github.com/pilosa/pilosa/test" ) @@ -27,7 +28,7 @@ import ( // pilosa.Server was not having its remoteClient field set by an option and so // it was using a nil client in monitorAntiEntropy. func TestMonitorAntiEntropy(t *testing.T) { - cluster := test.MustRunMainWithCluster(t, 3, test.OptAntiEntropyInterval(time.Millisecond*20)) + cluster := test.MustRunMainWithCluster(t, 3, []server.CommandOption{test.OptAntiEntropyInterval(time.Millisecond * 20)}) client := cluster[1].Client() err := client.CreateIndex(context.Background(), "balh", pilosa.IndexOptions{}) if err != nil { diff --git a/test/pilosa.go b/test/pilosa.go index 64514e0ab..3aa671801 100644 --- a/test/pilosa.go +++ b/test/pilosa.go @@ -97,7 +97,7 @@ func NewMainWithCluster(isCoordinator bool, opts ...server.CommandOption) *Main // MustRunMainWithCluster ruturns a running array of *Main where // all nodes are joined via memberlist (i.e. clustering enabled). -func MustRunMainWithCluster(t *testing.T, size int, opts ...server.CommandOption) []*Main { +func MustRunMainWithCluster(t *testing.T, size int, opts ...[]server.CommandOption) []*Main { ma, err := runMainWithCluster(size, opts...) if err != nil { t.Fatalf("new main array with cluster: %v", err) @@ -107,10 +107,13 @@ func MustRunMainWithCluster(t *testing.T, size int, opts ...server.CommandOption // runMainWithCluster runs an array of *Main where all nodes are // joined via memberlist (i.e. clustering enabled). -func runMainWithCluster(size int, opts ...server.CommandOption) ([]*Main, error) { +func runMainWithCluster(size int, opts ...[]server.CommandOption) ([]*Main, error) { if size == 0 { return nil, errors.New("cluster must contain at least one node") } + if len(opts) != size && len(opts) != 0 && len(opts) != 1 { + return nil, errors.New("Slice of CommandOptions must be of length 0, 1, or equal to the number of cluster nodes") + } mains := make([]*Main, size) @@ -120,7 +123,11 @@ func runMainWithCluster(size int, opts ...server.CommandOption) ([]*Main, error) var gossipSeeds = make([]string, size) for i := 0; i < size; i++ { - m := NewMainWithCluster(i == 0, opts...) + var commandOpts []server.CommandOption + if len(opts) > 0 { + commandOpts = opts[i%len(opts)] + } + m := NewMainWithCluster(i == 0, commandOpts...) m.Config.Cluster.Disabled = false gossipSeeds[i], err = m.RunWithTransport(gossipHost, gossipPort, gossipSeeds[:i])