|
| 1 | +// |
| 2 | +// DISCLAIMER |
| 3 | +// |
| 4 | +// Copyright 2018 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 | +// TestDockerClusterUpgrade runs 3 arangodb starters in docker with default settings. |
| 34 | +// Once running it starts a database upgrade. |
| 35 | +func TestDockerClusterUpgrade(t *testing.T) { |
| 36 | + needTestMode(t, testModeDocker) |
| 37 | + needStarterMode(t, starterModeCluster) |
| 38 | + if os.Getenv("IP") == "" { |
| 39 | + t.Fatal("IP envvar must be set to IP address of this machine") |
| 40 | + } |
| 41 | + /* |
| 42 | + docker volume create arangodb1 |
| 43 | + docker run -i --name=adb1 --rm -p 8528:8528 \ |
| 44 | + -v arangodb1:/data \ |
| 45 | + -v /var/run/docker.sock:/var/run/docker.sock \ |
| 46 | + arangodb/arangodb-starter \ |
| 47 | + --docker.container=adb1 \ |
| 48 | + --starter.address=$IP |
| 49 | + */ |
| 50 | + volID1 := createDockerID("vol-starter-test-cluster-upgrade1-") |
| 51 | + createDockerVolume(t, volID1) |
| 52 | + defer removeDockerVolume(t, volID1) |
| 53 | + |
| 54 | + volID2 := createDockerID("vol-starter-test-cluster-upgrade2-") |
| 55 | + createDockerVolume(t, volID2) |
| 56 | + defer removeDockerVolume(t, volID2) |
| 57 | + |
| 58 | + volID3 := createDockerID("vol-starter-test-cluster-upgrade3-") |
| 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-cluster-upgrade1-") |
| 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 | + createEnvironmentStarterOptions(), |
| 81 | + }, " ")) |
| 82 | + defer dockerRun1.Close() |
| 83 | + defer removeDockerContainer(t, cID1) |
| 84 | + |
| 85 | + cID2 := createDockerID("starter-test-cluster-upgrade2-") |
| 86 | + dockerRun2 := Spawn(t, strings.Join([]string{ |
| 87 | + "docker run -i", |
| 88 | + "--label starter-test=true", |
| 89 | + "--name=" + cID2, |
| 90 | + "--rm", |
| 91 | + fmt.Sprintf("-p %d:%d", basePort+(1*portIncrement), basePort), |
| 92 | + fmt.Sprintf("-v %s:/data", volID2), |
| 93 | + "-v /var/run/docker.sock:/var/run/docker.sock", |
| 94 | + "arangodb/arangodb-starter", |
| 95 | + "--docker.container=" + cID2, |
| 96 | + "--starter.address=$IP", |
| 97 | + createEnvironmentStarterOptions(), |
| 98 | + fmt.Sprintf("--starter.join=$IP:%d", basePort), |
| 99 | + }, " ")) |
| 100 | + defer dockerRun2.Close() |
| 101 | + defer removeDockerContainer(t, cID2) |
| 102 | + |
| 103 | + cID3 := createDockerID("starter-test-cluster-upgrade3-") |
| 104 | + dockerRun3 := Spawn(t, strings.Join([]string{ |
| 105 | + "docker run -i", |
| 106 | + "--label starter-test=true", |
| 107 | + "--name=" + cID3, |
| 108 | + "--rm", |
| 109 | + fmt.Sprintf("-p %d:%d", basePort+(2*portIncrement), basePort), |
| 110 | + fmt.Sprintf("-v %s:/data", volID3), |
| 111 | + "-v /var/run/docker.sock:/var/run/docker.sock", |
| 112 | + "arangodb/arangodb-starter", |
| 113 | + "--docker.container=" + cID3, |
| 114 | + "--starter.address=$IP", |
| 115 | + createEnvironmentStarterOptions(), |
| 116 | + fmt.Sprintf("--starter.join=$IP:%d", basePort), |
| 117 | + }, " ")) |
| 118 | + defer dockerRun3.Close() |
| 119 | + defer removeDockerContainer(t, cID3) |
| 120 | + |
| 121 | + if ok := WaitUntilStarterReady(t, whatCluster, 3, dockerRun1, dockerRun2, dockerRun3); ok { |
| 122 | + t.Logf("Cluster start took %s", time.Since(start)) |
| 123 | + testCluster(t, insecureStarterEndpoint(0*portIncrement), false) |
| 124 | + testCluster(t, insecureStarterEndpoint(1*portIncrement), false) |
| 125 | + testCluster(t, insecureStarterEndpoint(2*portIncrement), false) |
| 126 | + } |
| 127 | + |
| 128 | + testUpgradeProcess(t, insecureStarterEndpoint(0*portIncrement)) |
| 129 | + |
| 130 | + if isVerbose { |
| 131 | + t.Log("Waiting for termination") |
| 132 | + } |
| 133 | + ShutdownStarter(t, insecureStarterEndpoint(0*portIncrement)) |
| 134 | + ShutdownStarter(t, insecureStarterEndpoint(1*portIncrement)) |
| 135 | + ShutdownStarter(t, insecureStarterEndpoint(2*portIncrement)) |
| 136 | +} |
0 commit comments