Pass around slices of nodes as cluster
parent
252286d035
commit
567fd2bfef
|
@ -22,9 +22,11 @@ import (
|
||||||
main "github.com/influxdb/influxdb/cmd/influxd"
|
main "github.com/influxdb/influxdb/cmd/influxd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// node represents a node under test, which is both a broker and data node.
|
||||||
type node struct {
|
type node struct {
|
||||||
broker *messaging.Broker
|
broker *messaging.Broker
|
||||||
server *influxdb.Server
|
server *influxdb.Server
|
||||||
|
url *url.URL
|
||||||
}
|
}
|
||||||
|
|
||||||
// createCombinedNodeCluster creates a cluster of nServers nodes, each of which
|
// createCombinedNodeCluster creates a cluster of nServers nodes, each of which
|
||||||
|
@ -65,7 +67,11 @@ func createCombinedNodeCluster(t *testing.T, testName string, nNodes, basePort i
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Test %s: failed to create leader data node on port %d", testName, basePort)
|
t.Fatalf("Test %s: failed to create leader data node on port %d", testName, basePort)
|
||||||
}
|
}
|
||||||
nodes = append(nodes, node{broker: b, server: s})
|
nodes = append(nodes, node{
|
||||||
|
broker: b,
|
||||||
|
server: s,
|
||||||
|
url: &url.URL{Scheme: "http", Host: "localhost:" + strconv.Itoa(basePort)},
|
||||||
|
})
|
||||||
|
|
||||||
// Create subsequent nodes, which join to first node.
|
// Create subsequent nodes, which join to first node.
|
||||||
for i := 1; i < nNodes; i++ {
|
for i := 1; i < nNodes; i++ {
|
||||||
|
@ -82,15 +88,22 @@ func createCombinedNodeCluster(t *testing.T, testName string, nNodes, basePort i
|
||||||
if s == nil {
|
if s == nil {
|
||||||
t.Fatalf("Test %s: failed to create following data node on port %d", testName, basePort)
|
t.Fatalf("Test %s: failed to create following data node on port %d", testName, basePort)
|
||||||
}
|
}
|
||||||
nodes = append(nodes, node{broker: b, server: s})
|
|
||||||
|
nodes = append(nodes, node{
|
||||||
|
broker: b,
|
||||||
|
server: s,
|
||||||
|
url: &url.URL{Scheme: "http", Host: "localhost:" + strconv.Itoa(nextPort)},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return nodes
|
return nodes
|
||||||
}
|
}
|
||||||
|
|
||||||
// createDatabase creates a database, and verifies that the creation was successful.
|
// createDatabase creates a database, and verifies that the creation was successful.
|
||||||
func createDatabase(t *testing.T, testName string, serverURL *url.URL, database string) {
|
func createDatabase(t *testing.T, testName string, nodes []node, database string) {
|
||||||
t.Logf("Test: %s: creating database %s", testName, database)
|
t.Logf("Test: %s: creating database %s", testName, database)
|
||||||
|
serverURL := nodes[0].url
|
||||||
|
|
||||||
u := urlFor(serverURL, "query", url.Values{"q": []string{"CREATE DATABASE foo"}})
|
u := urlFor(serverURL, "query", url.Values{"q": []string{"CREATE DATABASE foo"}})
|
||||||
resp, err := http.Get(u.String())
|
resp, err := http.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -153,9 +166,11 @@ func createDatabase(t *testing.T, testName string, serverURL *url.URL, database
|
||||||
}
|
}
|
||||||
|
|
||||||
// createRetentionPolicy creates a retetention policy and verifies that the creation was successful.
|
// createRetentionPolicy creates a retetention policy and verifies that the creation was successful.
|
||||||
func createRetentionPolicy(t *testing.T, testName string, serverURL *url.URL, database, retention string, replicaN int) {
|
func createRetentionPolicy(t *testing.T, testName string, nodes []node, database, retention string, replicaN int) {
|
||||||
t.Log("Creating retention policy")
|
t.Log("Creating retention policy")
|
||||||
|
serverURL := nodes[0].url
|
||||||
replication := fmt.Sprintf("CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION %d DEFAULT", replicaN)
|
replication := fmt.Sprintf("CREATE RETENTION POLICY bar ON foo DURATION 1h REPLICATION %d DEFAULT", replicaN)
|
||||||
|
|
||||||
u := urlFor(serverURL, "query", url.Values{"q": []string{replication}})
|
u := urlFor(serverURL, "query", url.Values{"q": []string{replication}})
|
||||||
resp, err := http.Get(u.String())
|
resp, err := http.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,8 +199,9 @@ func createRetentionPolicy(t *testing.T, testName string, serverURL *url.URL, da
|
||||||
|
|
||||||
// simpleWriteAndQuery creates a simple database, retention policy, and replicates
|
// simpleWriteAndQuery creates a simple database, retention policy, and replicates
|
||||||
// the data across all nodes. It then ensures a series of writes and queries are OK.
|
// the data across all nodes. It then ensures a series of writes and queries are OK.
|
||||||
func simpleWriteAndQuery(t *testing.T, testname string, serverURL *url.URL, nNodes int) {
|
func simpleWriteAndQuery(t *testing.T, testname string, nodes []node, nNodes int) {
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
serverURL := nodes[0].url
|
||||||
var results client.Results
|
var results client.Results
|
||||||
|
|
||||||
// Write Data
|
// Write Data
|
||||||
|
@ -262,48 +278,33 @@ func Test_ServerSingleIntegration(t *testing.T) {
|
||||||
nNodes := 1
|
nNodes := 1
|
||||||
basePort := 8090
|
basePort := 8090
|
||||||
testName := "single node"
|
testName := "single node"
|
||||||
createCombinedNodeCluster(t, "single node", nNodes, basePort)
|
nodes := createCombinedNodeCluster(t, "single node", nNodes, basePort)
|
||||||
|
|
||||||
serverURL := &url.URL{
|
createDatabase(t, testName, nodes, "foo")
|
||||||
Scheme: "http",
|
createRetentionPolicy(t, testName, nodes, "foo", "bar", nNodes)
|
||||||
Host: "localhost:" + strconv.Itoa(basePort),
|
simpleWriteAndQuery(t, testName, nodes, nNodes)
|
||||||
}
|
|
||||||
|
|
||||||
createDatabase(t, testName, serverURL, "foo")
|
|
||||||
createRetentionPolicy(t, testName, serverURL, "foo", "bar", nNodes)
|
|
||||||
simpleWriteAndQuery(t, testName, serverURL, nNodes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Server3NodeIntegration(t *testing.T) {
|
func Test_Server3NodeIntegration(t *testing.T) {
|
||||||
nNodes := 3
|
nNodes := 3
|
||||||
basePort := 8190
|
basePort := 8190
|
||||||
testName := "3 node"
|
testName := "3 node"
|
||||||
createCombinedNodeCluster(t, testName, nNodes, basePort)
|
nodes := createCombinedNodeCluster(t, testName, nNodes, basePort)
|
||||||
|
|
||||||
serverURL := &url.URL{
|
createDatabase(t, testName, nodes, "foo")
|
||||||
Scheme: "http",
|
createRetentionPolicy(t, testName, nodes, "foo", "bar", nNodes)
|
||||||
Host: "localhost:" + strconv.Itoa(basePort),
|
simpleWriteAndQuery(t, testName, nodes, nNodes)
|
||||||
}
|
|
||||||
|
|
||||||
createDatabase(t, testName, serverURL, "foo")
|
|
||||||
createRetentionPolicy(t, testName, serverURL, "foo", "bar", nNodes)
|
|
||||||
simpleWriteAndQuery(t, testName, serverURL, nNodes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_Server5NodeIntegration(t *testing.T) {
|
func Test_Server5NodeIntegration(t *testing.T) {
|
||||||
nNodes := 5
|
nNodes := 5
|
||||||
basePort := 8290
|
basePort := 8290
|
||||||
testName := "5 node"
|
testName := "5 node"
|
||||||
createCombinedNodeCluster(t, testName, nNodes, basePort)
|
nodes := createCombinedNodeCluster(t, testName, nNodes, basePort)
|
||||||
|
|
||||||
serverURL := &url.URL{
|
createDatabase(t, testName, nodes, "foo")
|
||||||
Scheme: "http",
|
createRetentionPolicy(t, testName, nodes, "foo", "bar", nNodes)
|
||||||
Host: "localhost:" + strconv.Itoa(basePort),
|
simpleWriteAndQuery(t, testName, nodes, nNodes)
|
||||||
}
|
|
||||||
|
|
||||||
createDatabase(t, testName, serverURL, "foo")
|
|
||||||
createRetentionPolicy(t, testName, serverURL, "foo", "bar", nNodes)
|
|
||||||
simpleWriteAndQuery(t, testName, serverURL, nNodes)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func urlFor(u *url.URL, path string, params url.Values) *url.URL {
|
func urlFor(u *url.URL, path string, params url.Values) *url.URL {
|
||||||
|
|
Loading…
Reference in New Issue