|
| 1 | +/* |
| 2 | + * Copyright 2016 Netflix, Inc. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * Unless required by applicable law or agreed to in writing, software |
| 8 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | + * See the License for the specific language governing permissions and |
| 11 | + * limitations under the License. |
| 12 | + */ |
| 13 | + |
| 14 | +import com.bmuschko.gradle.docker.tasks.DockerInfo |
| 15 | +import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage |
| 16 | +import com.bmuschko.gradle.docker.tasks.image.Dockerfile |
| 17 | + |
| 18 | +ext { |
| 19 | + if (project.hasProperty('startCluster')) { |
| 20 | + startCluster = Boolean.getBoolean('startCluster') |
| 21 | + } else { |
| 22 | + startCluster = true |
| 23 | + } |
| 24 | + logger.info("metacat-functional-tests: start cluster = '${startCluster}'") |
| 25 | + |
| 26 | + if (project.hasProperty('stopCluster')) { |
| 27 | + stopCluster = Boolean.getBoolean('stopCluster') |
| 28 | + } else { |
| 29 | + stopCluster = true |
| 30 | + } |
| 31 | + logger.info("metacat-functional-tests: stop cluster = '${stopCluster}'") |
| 32 | + |
| 33 | + if (project.hasProperty('dockerHost')) { |
| 34 | + dockerHost = project['dockerHost'] |
| 35 | + } else if (System.getenv('DOCKER_HOST')) { |
| 36 | + dockerHost = System.getenv('DOCKER_HOST')?.replace('tcp:', 'https:') |
| 37 | + } else { |
| 38 | + dockerHost = 'http://localhost:2375' |
| 39 | + } |
| 40 | + logger.info("metacat-functional-tests: docker host '${dockerHost}'") |
| 41 | + |
| 42 | + if (project.hasProperty('dockerIp')) { |
| 43 | + dockerIp = project['dockerIp'] |
| 44 | + } else if (System.getenv('DOCKER_IP')) { |
| 45 | + dockerIp = System.getenv('DOCKER_IP') |
| 46 | + } else if (System.getenv('DOCKER_HOST')?.startsWith('tcp') || System.getenv('DOCKER_HOST')?.startsWith('http')) { |
| 47 | + dockerIp = (System.getenv('DOCKER_HOST') =~ /:\/\/([0-9\.]+):/)[0][1] |
| 48 | + } else { |
| 49 | + dockerIp = 'localhost' |
| 50 | + } |
| 51 | + logger.info("metacat-functional-tests: docker ip '${dockerIp}'") |
| 52 | + |
| 53 | + if (project.hasProperty('dockerCertPath')) { |
| 54 | + dockerCertPath = new File(project['dockerCertPath'] as String) |
| 55 | + } else if (System.getenv('DOCKER_CERT_PATH')) { |
| 56 | + dockerCertPath = new File(System.getenv('DOCKER_CERT_PATH')) |
| 57 | + } else { |
| 58 | + dockerCertPath = null |
| 59 | + } |
| 60 | + logger.info("metacat-functional-tests: docker cert path '${dockerCertPath}'") |
| 61 | + |
| 62 | + clusterWorkingDir = file("${rootDir}/metacat-functional-tests/metacat-test-cluster") |
| 63 | +} |
| 64 | + |
| 65 | +configurations { |
| 66 | + warproject |
| 67 | + functionalTestCompile.extendsFrom testCompile |
| 68 | + functionalTestRuntime.extendsFrom testRuntime |
| 69 | + |
| 70 | + all*.exclude group: 'javax.ws.rs', module: 'javax.ws.rs-api' |
| 71 | +} |
| 72 | + |
| 73 | +sourceSets { |
| 74 | + functionalTest { |
| 75 | + compileClasspath += main.output + test.output |
| 76 | + runtimeClasspath += main.output + test.output |
| 77 | + |
| 78 | + java.srcDir file('src/functionalTest/java') |
| 79 | + groovy.srcDir file('src/functionalTest/groovy') |
| 80 | + resources.srcDir file('src/functionalTest/resources') |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +buildscript { |
| 85 | + repositories { |
| 86 | + jcenter() |
| 87 | + } |
| 88 | + |
| 89 | + dependencies { |
| 90 | + classpath 'com.bmuschko:gradle-docker-plugin:3.0.1' |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +apply plugin: 'com.bmuschko.docker-remote-api' |
| 95 | + |
| 96 | +dependencies { |
| 97 | + warproject project(path: ':metacat-server', configuration: 'archives') |
| 98 | + |
| 99 | + // Test that metacat-client can be used with jersey 1 |
| 100 | + testCompile(project(':metacat-client')) { |
| 101 | + exclude group: 'javax.ws.rs', module: 'javax.ws.rs-api' |
| 102 | + exclude group: 'org.glassfish.jersey.core' |
| 103 | + } |
| 104 | + testCompile 'com.sun.jersey:jersey-client:1.19.1' |
| 105 | + |
| 106 | + testCompile project(':metacat-common-server') |
| 107 | + testCompile 'javax.ws.rs:jsr311-api:1.1.1' |
| 108 | + testCompile "com.facebook.presto:presto-hive-hadoop2:${presto_version}" |
| 109 | +} |
| 110 | + |
| 111 | +docker { |
| 112 | + url = project.ext.dockerHost |
| 113 | + certPath = project.ext.dockerCertPath |
| 114 | +} |
| 115 | + |
| 116 | +task expandWar(type: Copy) { |
| 117 | + dependsOn ':metacat-server:war' |
| 118 | + |
| 119 | + from { configurations.warproject.collect { zipTree(it) } } |
| 120 | + into file("${buildDir}/metacat-war-expanded/ROOT") |
| 121 | +} |
| 122 | + |
| 123 | +task dockerInfo(type: DockerInfo) |
| 124 | + |
| 125 | +task createWarDockerfile(type: Dockerfile) { |
| 126 | + dependsOn 'expandWar' |
| 127 | + |
| 128 | + destFile = project.file('build/metacat-war-expanded/Dockerfile') |
| 129 | + from 'tomcat:8.0-jre8' |
| 130 | + maintainer 'Netflix OSS "[email protected]"' |
| 131 | + volume '/usr/local/tomcat/logs', '/etc/metacat' |
| 132 | + runCommand 'rm -rf /usr/local/tomcat/webapps' |
| 133 | + copyFile './ROOT', '/usr/local/tomcat/webapps/ROOT' |
| 134 | +} |
| 135 | + |
| 136 | +task buildWarImage(type: DockerBuildImage) { |
| 137 | + dependsOn 'createWarDockerfile' |
| 138 | + inputDir = createWarDockerfile.destFile.parentFile |
| 139 | + tag = 'netflix_metacat_test/metacat_server' |
| 140 | +} |
| 141 | + |
| 142 | +task startMetacatCluster(type: Exec) { |
| 143 | + workingDir = clusterWorkingDir |
| 144 | + |
| 145 | + environment 'PATH', '/usr/local/bin:/usr/bin:/bin' |
| 146 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 147 | + if (project.ext.dockerCertPath) { |
| 148 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 149 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 150 | + } |
| 151 | + |
| 152 | + commandLine './startCluster.sh' |
| 153 | +} |
| 154 | + |
| 155 | +task stopMetacatCluster(type: Exec) { |
| 156 | + workingDir = clusterWorkingDir |
| 157 | + |
| 158 | + environment 'PATH', '/usr/local/bin:/usr/bin:/bin' |
| 159 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 160 | + if (project.ext.dockerCertPath) { |
| 161 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 162 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 163 | + } |
| 164 | + |
| 165 | + commandLine './stopCluster.sh' |
| 166 | +} |
| 167 | + |
| 168 | +task metacatPorts { |
| 169 | + if (project.ext.startCluster) { |
| 170 | + dependsOn 'startMetacatCluster' |
| 171 | + } |
| 172 | + ext.http_port = null |
| 173 | + ext.metacat_hive_thrift_port = null |
| 174 | + ext.metacat_s3_thrift_port = null |
| 175 | + ext.hive_thrift_port = null |
| 176 | + |
| 177 | + doLast { |
| 178 | + new ByteArrayOutputStream().withStream { os -> |
| 179 | + exec { |
| 180 | + workingDir = clusterWorkingDir |
| 181 | + |
| 182 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 183 | + if (project.ext.dockerCertPath) { |
| 184 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 185 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 186 | + } |
| 187 | + |
| 188 | + commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 8080 |
| 189 | + standardOutput = os |
| 190 | + } |
| 191 | + ext.http_port = os.toString().trim() |
| 192 | + logger.info("metacat-functional-tests: metacat http_port '{}'", ext.http_port) |
| 193 | + } |
| 194 | + |
| 195 | + new ByteArrayOutputStream().withStream { os -> |
| 196 | + exec { |
| 197 | + workingDir = clusterWorkingDir |
| 198 | + |
| 199 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 200 | + if (project.ext.dockerCertPath) { |
| 201 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 202 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 203 | + } |
| 204 | + |
| 205 | + commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 12001 |
| 206 | + standardOutput = os |
| 207 | + } |
| 208 | + ext.metacat_hive_thrift_port = os.toString().trim() |
| 209 | + logger.info("metacat-functional-tests: metacat thrift_port '{}'", ext.metacat_hive_thrift_port) |
| 210 | + } |
| 211 | + |
| 212 | + new ByteArrayOutputStream().withStream { os -> |
| 213 | + exec { |
| 214 | + workingDir = clusterWorkingDir |
| 215 | + |
| 216 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 217 | + if (project.ext.dockerCertPath) { |
| 218 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 219 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 220 | + } |
| 221 | + |
| 222 | + commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.war', 12002 |
| 223 | + standardOutput = os |
| 224 | + } |
| 225 | + ext.metacat_s3_thrift_port = os.toString().trim() |
| 226 | + logger.info("metacat-functional-tests: metacat thrift_port '{}'", ext.metacat_s3_thrift_port) |
| 227 | + } |
| 228 | + |
| 229 | + new ByteArrayOutputStream().withStream { os -> |
| 230 | + exec { |
| 231 | + workingDir = clusterWorkingDir |
| 232 | + |
| 233 | + environment 'DOCKER_HOST', project.ext.dockerHost?.replace('http:', 'tcp:').replace('https', 'tcp:') |
| 234 | + if (project.ext.dockerCertPath) { |
| 235 | + environment 'DOCKER_CERT_PATH', project.ext.dockerCertPath |
| 236 | + environment 'DOCKER_TLS_VERIFY', '1' |
| 237 | + } |
| 238 | + |
| 239 | + commandLine './printDockerPort.sh', project.ext.dockerIp, 'label=com.netflix.metacat.oss.test.hive', 9083 |
| 240 | + standardOutput = os |
| 241 | + } |
| 242 | + ext.hive_thrift_port = os.toString().trim() |
| 243 | + logger.info("metacat-functional-tests: metacat hive_thrift_port '{}'", ext.hive_thrift_port) |
| 244 | + } |
| 245 | + } |
| 246 | +} |
| 247 | + |
| 248 | +task functionalTest(type: Test) { |
| 249 | + testClassesDir = sourceSets.functionalTest.output.classesDir |
| 250 | + classpath = sourceSets.functionalTest.runtimeClasspath |
| 251 | + outputs.upToDateWhen { false } |
| 252 | + |
| 253 | + doFirst { |
| 254 | + def properties = [ |
| 255 | + 'metacat_docker_ip' : project.ext.dockerIp as String, |
| 256 | + 'metacat_http_port' : metacatPorts.http_port as String, |
| 257 | + 'metacat_hive_thrift_port' : metacatPorts.metacat_hive_thrift_port as String, |
| 258 | + 'metacat_s3_thrift_port' : metacatPorts.metacat_s3_thrift_port as String, |
| 259 | + 'hive_thrift_port' : metacatPorts.hive_thrift_port as String, |
| 260 | + 'org.slf4j.simpleLogger.defaultLogLevel': 'debug' |
| 261 | + ] |
| 262 | + System.properties.stringPropertyNames().findAll { it?.toLowerCase()?.contains("metacat") }.each { |
| 263 | + properties[it] = System.getProperty(it) |
| 264 | + } |
| 265 | + systemProperties = properties |
| 266 | + } |
| 267 | + |
| 268 | + testLogging { |
| 269 | + showStandardStreams = true |
| 270 | + } |
| 271 | + |
| 272 | + if (project.ext.startCluster) { |
| 273 | + dependsOn 'startMetacatCluster', 'metacatPorts' |
| 274 | + } else { |
| 275 | + dependsOn 'metacatPorts' |
| 276 | + } |
| 277 | + |
| 278 | + if (project.ext.stopCluster) { |
| 279 | + finalizedBy 'stopMetacatCluster' |
| 280 | + } |
| 281 | +} |
0 commit comments