Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | // Following Gradle best practices to keep build logic organized |
| 21 | |
| 22 | // ---------------------------------------------------------------------------- |
| 23 | // Functional testing harness creation. This helps run the cross-check tests. |
| 24 | // The Makefile precross target invokes the shadowJar task and the tests.json |
| 25 | // code is changed to call runclient or runserver as needed. |
| 26 | |
| 27 | // ---------------------------------------------------------------------------- |
| 28 | // Cross Test sources are separated in their own sourceSet |
| 29 | // |
| 30 | sourceSets { |
| 31 | crossTest { |
| 32 | java { |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | configurations { |
| 38 | crossTestCompile { extendsFrom testCompile } |
| 39 | crossTestRuntime { extendsFrom crossTestCompile, testRuntime } |
| 40 | } |
| 41 | |
| 42 | dependencies { |
iadcode | a8c041d | 2021-03-02 14:15:13 +1100 | [diff] [blame] | 43 | crossTestCompile "org.apache.tomcat.embed:tomcat-embed-core:${tomcatEmbedVersion}" |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 44 | crossTestCompile sourceSets.main.output |
| 45 | crossTestCompile sourceSets.test.output |
| 46 | } |
| 47 | |
| 48 | // I am using shadow plugin to make a self contained functional test Uber JAR that |
| 49 | // eliminates startup problems with wrapping the cross-check harness in Gradle. |
| 50 | // This is used by the runner scripts as the single classpath entry which |
| 51 | // allows the process to be as lightweight as it can. |
| 52 | shadowJar { |
| 53 | description = 'Assemble a test JAR file for cross-check execution' |
| 54 | // make sure the runners are created when this runs |
pengzhouhu | 6e4c581 | 2019-10-21 22:21:11 +0800 | [diff] [blame] | 55 | dependsOn 'generateRunnerScriptForClient', 'generateRunnerScriptForServer', 'generateRunnerScriptForNonblockingServer', 'generateRunnerScriptForTServletServer' |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 56 | |
| 57 | baseName = 'functionalTest' |
| 58 | destinationDir = file("$buildDir/functionalTestJar") |
| 59 | classifier = null |
| 60 | |
| 61 | // We do not need a version number for this internal jar |
| 62 | version = null |
| 63 | |
| 64 | // Bundle the complete set of unit test classes including generated code |
| 65 | // and the runtime dependencies in one JAR to expedite execution. |
| 66 | from sourceSets.test.output |
| 67 | from sourceSets.crossTest.output |
| 68 | configurations = [project.configurations.testRuntime] |
| 69 | } |
| 70 | |
| 71 | // Common script runner configuration elements |
| 72 | def scriptExt = '' |
| 73 | def execExt = '' |
| 74 | def scriptHead = '#!/bin/bash' |
| 75 | def args = '$*' |
| 76 | |
| 77 | // Although this is marked internal it is an available and stable interface |
| 78 | if (org.gradle.internal.os.OperatingSystem.current().windows) { |
| 79 | scriptExt = '.bat' |
| 80 | execExt = '.exe' |
| 81 | scriptHead = '@echo off' |
| 82 | args = '%*' |
| 83 | } |
| 84 | |
| 85 | // The Java executable to use with the runner scripts |
| 86 | def javaExe = file("${System.getProperty('java.home')}/bin/java${execExt}").canonicalPath |
| 87 | // The common Uber jar path |
Jiayu Liu | eac5103 | 2022-03-11 04:55:13 +0100 | [diff] [blame] | 88 | def jarPath = shadowJar.archiveFile.get().asFile.canonicalPath |
| 89 | def trustStore = file("${projectDir}/src/crossTest/resources/.truststore").canonicalPath |
| 90 | def keyStore = file("${projectDir}/src/crossTest/resources/.keystore").canonicalPath |
Alex Volanis | 7004a61 | 2018-01-24 10:30:13 -0500 | [diff] [blame] | 91 | |
| 92 | task generateRunnerScriptForClient(group: 'Build') { |
| 93 | description = 'Generate a runner script for cross-check tests with TestClient' |
| 94 | |
| 95 | def clientFile = file("$buildDir/runclient${scriptExt}") |
| 96 | |
| 97 | def runClientText = """\ |
| 98 | ${scriptHead} |
| 99 | |
| 100 | "${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.trustStore=$trustStore" -Djavax.net.ssl.trustStorePassword=thrift org.apache.thrift.test.TestClient $args |
| 101 | """ |
| 102 | inputs.property 'runClientText', runClientText |
| 103 | outputs.file clientFile |
| 104 | |
| 105 | doLast { |
| 106 | clientFile.parentFile.mkdirs() |
| 107 | clientFile.text = runClientText |
| 108 | clientFile.setExecutable(true, false) |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | task generateRunnerScriptForServer(group: 'Build') { |
| 113 | description = 'Generate a runner script for cross-check tests with TestServer' |
| 114 | |
| 115 | def serverFile = file("$buildDir/runserver${scriptExt}") |
| 116 | |
| 117 | def runServerText = """\ |
| 118 | ${scriptHead} |
| 119 | |
| 120 | "${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestServer $args |
| 121 | """ |
| 122 | |
| 123 | inputs.property 'runServerText', runServerText |
| 124 | outputs.file serverFile |
| 125 | |
| 126 | doLast { |
| 127 | serverFile.parentFile.mkdirs() |
| 128 | serverFile.text = runServerText |
| 129 | serverFile.setExecutable(true, false) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | task generateRunnerScriptForNonblockingServer(group: 'Build') { |
| 134 | description = 'Generate a runner script for cross-check tests with TestNonblockingServer' |
| 135 | |
| 136 | def serverFile = file("$buildDir/runnonblockingserver${scriptExt}") |
| 137 | |
| 138 | def runServerText = """\ |
| 139 | ${scriptHead} |
| 140 | |
| 141 | "${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestNonblockingServer $args |
| 142 | """ |
| 143 | |
| 144 | inputs.property 'runServerText', runServerText |
| 145 | outputs.file serverFile |
| 146 | |
| 147 | doLast { |
| 148 | serverFile.parentFile.mkdirs() |
| 149 | serverFile.text = runServerText |
| 150 | serverFile.setExecutable(true, false) |
| 151 | } |
| 152 | } |
pengzhouhu | 6e4c581 | 2019-10-21 22:21:11 +0800 | [diff] [blame] | 153 | |
| 154 | task generateRunnerScriptForTServletServer(group: 'Build') { |
| 155 | description = 'Generate a runner script for cross-check tests with TestTServletServer' |
| 156 | |
| 157 | def serverFile = file("$buildDir/runservletserver${scriptExt}") |
| 158 | |
| 159 | def runServerText = """\ |
| 160 | ${scriptHead} |
| 161 | |
| 162 | "${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestTServletServer $args |
| 163 | """ |
| 164 | |
| 165 | inputs.property 'runServerText', runServerText |
| 166 | outputs.file serverFile |
| 167 | |
| 168 | doLast { |
| 169 | serverFile.parentFile.mkdirs() |
| 170 | serverFile.text = runServerText |
| 171 | serverFile.setExecutable(true, false) |
| 172 | } |
| 173 | } |