Skip to content

Commit 8054199

Browse files
committed
Adding resilientsingle tests
1 parent 8e192fb commit 8054199

File tree

4 files changed

+340
-5
lines changed

4 files changed

+340
-5
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
package test
24+
25+
import (
26+
"fmt"
27+
"os"
28+
"strings"
29+
"testing"
30+
"time"
31+
)
32+
33+
// TestDockerResilientSingleDefault runs 3 arangodb starters in docker with mode=resilientsingle
34+
// and otherwise default settings.
35+
func TestDockerResilientSingleDefault(t *testing.T) {
36+
needTestMode(t, testModeDocker)
37+
if os.Getenv("IP") == "" {
38+
t.Fatal("IP envvar must be set to IP address of this machine")
39+
}
40+
/*
41+
docker volume create arangodb1
42+
docker run -i --name=adb1 --rm -p 8528:8528 \
43+
-v arangodb1:/data \
44+
-v /var/run/docker.sock:/var/run/docker.sock \
45+
arangodb/arangodb-starter \
46+
--docker.container=adb1 \
47+
--starter.address=$IP \
48+
--starter.mode=resilientsingle
49+
*/
50+
volID1 := createDockerID("vol-starter-test-resilientsingle-default1-")
51+
createDockerVolume(t, volID1)
52+
defer removeDockerVolume(t, volID1)
53+
54+
volID2 := createDockerID("vol-starter-test-resilientsingle-default2-")
55+
createDockerVolume(t, volID2)
56+
defer removeDockerVolume(t, volID2)
57+
58+
volID3 := createDockerID("vol-starter-test-resilientsingle-default3-")
59+
createDockerVolume(t, volID3)
60+
defer removeDockerVolume(t, volID3)
61+
62+
// Cleanup of left over tests
63+
removeDockerContainersByLabel(t, "starter-test=true")
64+
removeStarterCreatedDockerContainers(t)
65+
66+
start := time.Now()
67+
68+
cID1 := createDockerID("starter-test-resilientsingle-default1-")
69+
dockerRun1 := Spawn(t, strings.Join([]string{
70+
"docker run -i",
71+
"--label starter-test=true",
72+
"--name=" + cID1,
73+
"--rm",
74+
fmt.Sprintf("-p %d:%d", basePort, basePort),
75+
fmt.Sprintf("-v %s:/data", volID1),
76+
"-v /var/run/docker.sock:/var/run/docker.sock",
77+
"arangodb/arangodb-starter",
78+
"--docker.container=" + cID1,
79+
"--starter.address=$IP",
80+
"--starter.mode=resilientsingle",
81+
createEnvironmentStarterOptions(),
82+
}, " "))
83+
defer dockerRun1.Close()
84+
defer removeDockerContainer(t, cID1)
85+
86+
cID2 := createDockerID("starter-test-resilientsingle-default2-")
87+
dockerRun2 := Spawn(t, strings.Join([]string{
88+
"docker run -i",
89+
"--label starter-test=true",
90+
"--name=" + cID2,
91+
"--rm",
92+
fmt.Sprintf("-p %d:%d", basePort+5, basePort),
93+
fmt.Sprintf("-v %s:/data", volID2),
94+
"-v /var/run/docker.sock:/var/run/docker.sock",
95+
"arangodb/arangodb-starter",
96+
"--docker.container=" + cID2,
97+
"--starter.address=$IP",
98+
"--starter.mode=resilientsingle",
99+
createEnvironmentStarterOptions(),
100+
fmt.Sprintf("--starter.join=$IP:%d", basePort),
101+
}, " "))
102+
defer dockerRun2.Close()
103+
defer removeDockerContainer(t, cID2)
104+
105+
cID3 := createDockerID("starter-test-resilientsingle-default3-")
106+
dockerRun3 := Spawn(t, strings.Join([]string{
107+
"docker run -i",
108+
"--label starter-test=true",
109+
"--name=" + cID3,
110+
"--rm",
111+
fmt.Sprintf("-p %d:%d", basePort+10, basePort),
112+
fmt.Sprintf("-v %s:/data", volID3),
113+
"-v /var/run/docker.sock:/var/run/docker.sock",
114+
"arangodb/arangodb-starter",
115+
"--docker.container=" + cID3,
116+
"--starter.address=$IP",
117+
"--starter.mode=resilientsingle",
118+
createEnvironmentStarterOptions(),
119+
fmt.Sprintf("--starter.join=$IP:%d", basePort),
120+
}, " "))
121+
defer dockerRun3.Close()
122+
defer removeDockerContainer(t, cID3)
123+
124+
if ok := WaitUntilStarterReady(t, whatCluster, dockerRun1, dockerRun2, dockerRun3); ok {
125+
t.Logf("Cluster start took %s", time.Since(start))
126+
testResilientSingle(t, insecureStarterEndpoint(0), false)
127+
testResilientSingle(t, insecureStarterEndpoint(5), false)
128+
testResilientSingle(t, insecureStarterEndpoint(10), false)
129+
}
130+
131+
if isVerbose {
132+
t.Log("Waiting for termination")
133+
}
134+
ShutdownStarter(t, insecureStarterEndpoint(0))
135+
ShutdownStarter(t, insecureStarterEndpoint(5))
136+
ShutdownStarter(t, insecureStarterEndpoint(10))
137+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
package test
24+
25+
import (
26+
"fmt"
27+
"os"
28+
"strings"
29+
"testing"
30+
"time"
31+
)
32+
33+
// TestDockerResilientSingleLocal runs the arangodb starter in docker with mode `resilientsingle` & `--starter.local`
34+
func TestDockerResilientSingleLocal(t *testing.T) {
35+
needTestMode(t, testModeDocker)
36+
if os.Getenv("IP") == "" {
37+
t.Fatal("IP envvar must be set to IP address of this machine")
38+
}
39+
/*
40+
docker volume create arangodb
41+
docker run -i --name=adb --rm -p 8528:8528 \
42+
-v arangodb:/data \
43+
-v /var/run/docker.sock:/var/run/docker.sock \
44+
arangodb/arangodb-starter \
45+
--docker.container=adb \
46+
--starter.address=$IP \
47+
--starter.mode=resilientsingle \
48+
--starter.local
49+
*/
50+
volID := createDockerID("vol-starter-test-local-resilientsingle-")
51+
createDockerVolume(t, volID)
52+
defer removeDockerVolume(t, volID)
53+
54+
// Cleanup of left over tests
55+
removeDockerContainersByLabel(t, "starter-test=true")
56+
removeStarterCreatedDockerContainers(t)
57+
58+
start := time.Now()
59+
60+
cID := createDockerID("starter-test-local-resilientsingle-")
61+
dockerRun := Spawn(t, strings.Join([]string{
62+
"docker run -i",
63+
"--label starter-test=true",
64+
"--name=" + cID,
65+
"--rm",
66+
fmt.Sprintf("-p %d:%d", basePort, basePort),
67+
fmt.Sprintf("-v %s:/data", volID),
68+
"-v /var/run/docker.sock:/var/run/docker.sock",
69+
"arangodb/arangodb-starter",
70+
"--docker.container=" + cID,
71+
"--starter.address=$IP",
72+
"--starter.mode=resilientsingle",
73+
"--starter.local",
74+
createEnvironmentStarterOptions(),
75+
}, " "))
76+
defer dockerRun.Close()
77+
defer removeDockerContainer(t, cID)
78+
79+
if ok := WaitUntilStarterReady(t, whatCluster, dockerRun); ok {
80+
t.Logf("ResilientSingle start took %s", time.Since(start))
81+
testResilientSingle(t, insecureStarterEndpoint(0), false)
82+
}
83+
84+
if isVerbose {
85+
t.Log("Waiting for termination")
86+
}
87+
ShutdownStarter(t, insecureStarterEndpoint(0))
88+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2017 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
// Author Ewout Prangsma
21+
//
22+
23+
package test
24+
25+
import (
26+
"os"
27+
"testing"
28+
"time"
29+
)
30+
31+
// TestProcessResilientSingleDefault starts a master starter, followed by 2 slave starters.
32+
// All are started in resilientsingle mode.
33+
func TestProcessResilientSingleDefault(t *testing.T) {
34+
removeArangodProcesses(t)
35+
needTestMode(t, testModeProcess)
36+
dataDirMaster := SetUniqueDataDir(t)
37+
defer os.RemoveAll(dataDirMaster)
38+
39+
start := time.Now()
40+
41+
master := Spawn(t, "${STARTER} --starter.mode=resilientsingle "+createEnvironmentStarterOptions())
42+
defer master.Close()
43+
44+
dataDirSlave1 := SetUniqueDataDir(t)
45+
defer os.RemoveAll(dataDirSlave1)
46+
slave1 := Spawn(t, "${STARTER} --starter.mode=resilientsingle --starter.join 127.0.0.1 "+createEnvironmentStarterOptions())
47+
defer slave1.Close()
48+
49+
dataDirSlave2 := SetUniqueDataDir(t)
50+
defer os.RemoveAll(dataDirSlave2)
51+
slave2 := Spawn(t, "${STARTER} --starter.mode=resilientsingle --starter.join 127.0.0.1 "+createEnvironmentStarterOptions())
52+
defer slave2.Close()
53+
54+
if ok := WaitUntilStarterReady(t, whatCluster, master, slave1, slave2); ok {
55+
t.Logf("Cluster start took %s", time.Since(start))
56+
testResilientSingle(t, insecureStarterEndpoint(0), false)
57+
testResilientSingle(t, insecureStarterEndpoint(5), false)
58+
testResilientSingle(t, insecureStarterEndpoint(10), false)
59+
}
60+
61+
if isVerbose {
62+
t.Log("Waiting for termination")
63+
}
64+
SendIntrAndWait(t, master, slave1, slave2)
65+
}
66+
67+
// TestProcessResilientSingleDefaultShutdownViaAPI starts a master starter, followed by 2 slave starters, shutting all down through the API.
68+
// All are started in resilientsingle mode.
69+
func TestProcessResilientSingleDefaultShutdownViaAPI(t *testing.T) {
70+
removeArangodProcesses(t)
71+
needTestMode(t, testModeProcess)
72+
dataDirMaster := SetUniqueDataDir(t)
73+
defer os.RemoveAll(dataDirMaster)
74+
75+
start := time.Now()
76+
77+
master := Spawn(t, "${STARTER} --starter.mode=resilientsingle "+createEnvironmentStarterOptions())
78+
defer master.Close()
79+
80+
dataDirSlave1 := SetUniqueDataDir(t)
81+
defer os.RemoveAll(dataDirSlave1)
82+
slave1 := Spawn(t, "${STARTER} --starter.mode=resilientsingle --starter.join 127.0.0.1 "+createEnvironmentStarterOptions())
83+
defer slave1.Close()
84+
85+
dataDirSlave2 := SetUniqueDataDir(t)
86+
defer os.RemoveAll(dataDirSlave2)
87+
slave2 := Spawn(t, "${STARTER} --starter.mode=resilientsingle --starter.join 127.0.0.1 "+createEnvironmentStarterOptions())
88+
defer slave2.Close()
89+
90+
if ok := WaitUntilStarterReady(t, whatCluster, master, slave1, slave2); ok {
91+
t.Logf("Cluster start took %s", time.Since(start))
92+
testResilientSingle(t, insecureStarterEndpoint(0), false)
93+
testResilientSingle(t, insecureStarterEndpoint(5), false)
94+
testResilientSingle(t, insecureStarterEndpoint(10), false)
95+
}
96+
97+
if isVerbose {
98+
t.Log("Waiting for termination")
99+
}
100+
ShutdownStarter(t, insecureStarterEndpoint(0))
101+
ShutdownStarter(t, insecureStarterEndpoint(5))
102+
ShutdownStarter(t, insecureStarterEndpoint(10))
103+
}

test/server_util.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ func testSingle(t *testing.T, starterEndpoint string, isSecure bool) client.API
8686
return c
8787
}
8888

89+
// testResilientSingle runs a series of tests to verify good resilientsingle servers.
90+
func testResilientSingle(t *testing.T, starterEndpoint string, isSecure bool) client.API {
91+
c := NewStarterClient(t, starterEndpoint)
92+
testProcesses(t, c, "resilientsingle", starterEndpoint, isSecure)
93+
return c
94+
}
95+
8996
// testProcesses runs a series of tests to verify a good series of database servers.
9097
func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isSecure bool) {
9198
ctx := context.Background()
@@ -125,8 +132,8 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
125132
if sp.IsSecure != isSecure {
126133
t.Errorf("Invalid IsSecure on coordinator. Expected %v, got %v", isSecure, sp.IsSecure)
127134
}
128-
if mode == "single" {
129-
t.Errorf("Found coordinator, not allowed in single mode")
135+
if mode == "single" || mode == "resilientsingle" {
136+
t.Errorf("Found coordinator, not allowed in single|resilientsingle mode")
130137
} else {
131138
if isVerbose {
132139
t.Logf("Found coordinator at %s:%d", sp.IP, sp.Port)
@@ -142,8 +149,8 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
142149
if sp.IsSecure != isSecure {
143150
t.Errorf("Invalid IsSecure on dbserver. Expected %v, got %v", isSecure, sp.IsSecure)
144151
}
145-
if mode == "single" {
146-
t.Errorf("Found dbserver, not allowed in single mode")
152+
if mode == "single" || mode == "resilientsingle" {
153+
t.Errorf("Found dbserver, not allowed in single|resilientsingle mode")
147154
} else {
148155
if isVerbose {
149156
t.Logf("Found dbserver at %s:%d", sp.IP, sp.Port)
@@ -167,7 +174,7 @@ func testProcesses(t *testing.T, c client.API, mode, starterEndpoint string, isS
167174
}
168175
testArangodReachable(t, sp)
169176
}
170-
} else if mode == "single" {
177+
} else if mode == "single" || mode == "resilientsingle" {
171178
t.Errorf("No single found in %s", starterEndpoint)
172179
}
173180
}

0 commit comments

Comments
 (0)