|
| 1 | +import org.apache.tools.ant.taskdefs.condition.Os |
| 2 | +import org.elasticsearch.gradle.LoggedExec |
1 | 3 | import org.elasticsearch.gradle.MavenFilteringHack
|
2 | 4 | import org.elasticsearch.gradle.test.AntFixture
|
| 5 | +import org.elasticsearch.gradle.test.ClusterConfiguration |
| 6 | +import org.elasticsearch.gradle.test.RestIntegTestTask |
3 | 7 |
|
4 | 8 | /*
|
5 | 9 | * Licensed to Elasticsearch under one or more contributor
|
@@ -77,11 +81,158 @@ String s3BasePath = System.getenv("amazon_s3_base_path")
|
77 | 81 | if (!s3AccessKey && !s3SecretKey && !s3Bucket && !s3BasePath) {
|
78 | 82 | s3AccessKey = 's3_integration_test_access_key'
|
79 | 83 | s3SecretKey = 's3_integration_test_secret_key'
|
80 |
| - s3Bucket = 'bucket_test' |
| 84 | + s3Bucket = 'bucket-test' |
81 | 85 | s3BasePath = 'integration_test'
|
82 | 86 | useFixture = true
|
83 | 87 | }
|
84 | 88 |
|
| 89 | +final String minioVersion = 'RELEASE.2018-06-22T23-48-46Z' |
| 90 | +final String minioBinDir = "${buildDir}/minio/bin" |
| 91 | +final String minioDataDir = "${buildDir}/minio/data" |
| 92 | +final String minioAddress = "localhost:60920" |
| 93 | + |
| 94 | +final String minioDistribution |
| 95 | +final String minioCheckSum |
| 96 | +if (Os.isFamily(Os.FAMILY_MAC)) { |
| 97 | + minioDistribution = 'darwin-amd64' |
| 98 | + minioCheckSum = '96b0bcb2f590e8e65fb83d5c3e221f9bd1106b49fa6f22c6b726b80b845d7c60' |
| 99 | +} else if (Os.isFamily(Os.FAMILY_UNIX)) { |
| 100 | + minioDistribution = 'linux-amd64' |
| 101 | + minioCheckSum = '713dac7c105285eab3b92649be92b5e793b29d3525c7929fa7aaed99374fad99' |
| 102 | +} else { |
| 103 | + minioDistribution = null |
| 104 | + minioCheckSum = null |
| 105 | +} |
| 106 | + |
| 107 | +buildscript { |
| 108 | + repositories { |
| 109 | + maven { |
| 110 | + url 'https://plugins.gradle.org/m2/' |
| 111 | + } |
| 112 | + } |
| 113 | + dependencies { |
| 114 | + classpath 'de.undercouch:gradle-download-task:3.4.3' |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +if (minioDistribution) { |
| 119 | + apply plugin: 'de.undercouch.download' |
| 120 | + |
| 121 | + final String minioFileName = "minio.${minioVersion}" |
| 122 | + final String minioDownloadURL = "https://dl.minio.io/server/minio/release/${minioDistribution}/archive/${minioFileName}" |
| 123 | + final String minioFilePath = "${gradle.gradleUserHomeDir}/downloads/minio/${minioDistribution}/${minioFileName}" |
| 124 | + |
| 125 | + task downloadMinio(type: Download) { |
| 126 | + src minioDownloadURL |
| 127 | + dest minioFilePath |
| 128 | + onlyIfModified true |
| 129 | + } |
| 130 | + |
| 131 | + task verifyMinioChecksum(type: Verify, dependsOn: downloadMinio) { |
| 132 | + src minioFilePath |
| 133 | + algorithm 'SHA-256' |
| 134 | + checksum minioCheckSum |
| 135 | + } |
| 136 | + |
| 137 | + task installMinio(type: Sync, dependsOn: verifyMinioChecksum) { |
| 138 | + from minioFilePath |
| 139 | + into minioBinDir |
| 140 | + fileMode 0755 |
| 141 | + } |
| 142 | + |
| 143 | + long minioPid |
| 144 | + |
| 145 | + task startMinio { |
| 146 | + dependsOn installMinio |
| 147 | + doLast { |
| 148 | + new File("${minioDataDir}/${s3Bucket}").mkdirs() |
| 149 | + // we skip these tests on Windows so we do no need to worry about compatibility here |
| 150 | + final ProcessBuilder minio = new ProcessBuilder( |
| 151 | + "${minioBinDir}/${minioFileName}", |
| 152 | + "server", |
| 153 | + "--address", |
| 154 | + minioAddress, |
| 155 | + minioDataDir) |
| 156 | + minio.addShutdownHook { minio.destroy() } |
| 157 | + minio.environment().put('MINIO_ACCESS_KEY', s3AccessKey) |
| 158 | + minio.environment().put('MINIO_SECRET_KEY', s3SecretKey) |
| 159 | + minio.environment().put('MINIO_DOMAIN', 'localhost') |
| 160 | + final Process process = minio.start() |
| 161 | + minioPid = process.pid() |
| 162 | + |
| 163 | + new BufferedReader(new InputStreamReader(process.getInputStream())).withReader { br -> |
| 164 | + String line |
| 165 | + int httpPort = 0 |
| 166 | + while ((line = br.readLine()) != null) { |
| 167 | + logger.info(line) |
| 168 | + if (line.matches('.*Endpoint.*:\\d+$')) { |
| 169 | + assert httpPort == 0 |
| 170 | + final int index = line.lastIndexOf(":") |
| 171 | + assert index >= 0 |
| 172 | + httpPort = Integer.parseInt(line.substring(index + 1)) |
| 173 | + |
| 174 | + final File script = new File(project.buildDir, "minio/minio.killer.sh") |
| 175 | + script.setText( |
| 176 | + ["function shutdown {", |
| 177 | + " kill ${minioPid}", |
| 178 | + "}", |
| 179 | + "trap shutdown EXIT", |
| 180 | + // will wait indefinitely for input, but we never pass input, and the pipe is only closed when the build dies |
| 181 | + "read line\n"].join('\n'), 'UTF-8') |
| 182 | + final ProcessBuilder killer = new ProcessBuilder("bash", script.absolutePath) |
| 183 | + killer.start() |
| 184 | + break |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + assert httpPort > 0 |
| 189 | + } |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + task stopMinio(type: LoggedExec) { |
| 194 | + onlyIf { minioPid > 0 } |
| 195 | + |
| 196 | + doFirst { |
| 197 | + logger.info("Shutting down minio with pid ${minioPid}") |
| 198 | + } |
| 199 | + |
| 200 | + final Object pid = "${ -> minioPid }" |
| 201 | + |
| 202 | + // we skip these tests on Windows so we do no need to worry about compatibility here |
| 203 | + executable = 'kill' |
| 204 | + args('-9', pid) |
| 205 | + } |
| 206 | + |
| 207 | + RestIntegTestTask integTestMinio = project.tasks.create('integTestMinio', RestIntegTestTask.class) { |
| 208 | + description = "Runs REST tests using the Minio repository." |
| 209 | + } |
| 210 | + |
| 211 | + // The following closure must execute before the afterEvaluate block in the constructor of the following integrationTest tasks: |
| 212 | + project.afterEvaluate { |
| 213 | + ClusterConfiguration cluster = project.extensions.getByName('integTestMinioCluster') as ClusterConfiguration |
| 214 | + cluster.dependsOn(project.bundlePlugin) |
| 215 | + cluster.keystoreSetting 's3.client.integration_test.access_key', s3AccessKey |
| 216 | + cluster.keystoreSetting 's3.client.integration_test.secret_key', s3SecretKey |
| 217 | + cluster.setting 's3.client.integration_test.endpoint', "http://${minioAddress}" |
| 218 | + |
| 219 | + Task restIntegTestTask = project.tasks.getByName('integTestMinio') |
| 220 | + restIntegTestTask.clusterConfig.plugin(project.path) |
| 221 | + |
| 222 | + // Default jvm arguments for all test clusters |
| 223 | + String jvmArgs = "-Xms" + System.getProperty('tests.heap.size', '512m') + |
| 224 | + " " + "-Xmx" + System.getProperty('tests.heap.size', '512m') + |
| 225 | + " " + System.getProperty('tests.jvm.argline', '') |
| 226 | + |
| 227 | + restIntegTestTask.clusterConfig.jvmArgs = jvmArgs |
| 228 | + } |
| 229 | + |
| 230 | + integTestMinioRunner.dependsOn(startMinio) |
| 231 | + integTestMinioRunner.finalizedBy(stopMinio) |
| 232 | + |
| 233 | + project.check.dependsOn(integTestMinio) |
| 234 | +} |
| 235 | + |
85 | 236 | /** A task to start the AmazonS3Fixture which emulates an S3 service **/
|
86 | 237 | task s3Fixture(type: AntFixture) {
|
87 | 238 | dependsOn testClasses
|
|
0 commit comments