blob: f00f74bf2bcebb3e1c69251469b470a7b3833f6b [file] [log] [blame]
Alex Volanis7004a612018-01-24 10:30:13 -05001/*
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//
30sourceSets {
31 crossTest {
32 java {
33 srcDir 'test'
34 include '**/test/TestClient.java'
35 include '**/test/TestServer.java'
36 include '**/test/TestNonblockingServer.java'
pengzhouhu6e4c5812019-10-21 22:21:11 +080037 include '**/test/TestTServletServer.java'
Alex Volanis7004a612018-01-24 10:30:13 -050038 }
39 }
40}
41
42configurations {
43 crossTestCompile { extendsFrom testCompile }
44 crossTestRuntime { extendsFrom crossTestCompile, testRuntime }
45}
46
47dependencies {
iadcodea8c041d2021-03-02 14:15:13 +110048 crossTestCompile "org.apache.tomcat.embed:tomcat-embed-core:${tomcatEmbedVersion}"
Alex Volanis7004a612018-01-24 10:30:13 -050049 crossTestCompile sourceSets.main.output
50 crossTestCompile sourceSets.test.output
51}
52
53// I am using shadow plugin to make a self contained functional test Uber JAR that
54// eliminates startup problems with wrapping the cross-check harness in Gradle.
55// This is used by the runner scripts as the single classpath entry which
56// allows the process to be as lightweight as it can.
57shadowJar {
58 description = 'Assemble a test JAR file for cross-check execution'
59 // make sure the runners are created when this runs
pengzhouhu6e4c5812019-10-21 22:21:11 +080060 dependsOn 'generateRunnerScriptForClient', 'generateRunnerScriptForServer', 'generateRunnerScriptForNonblockingServer', 'generateRunnerScriptForTServletServer'
Alex Volanis7004a612018-01-24 10:30:13 -050061
62 baseName = 'functionalTest'
63 destinationDir = file("$buildDir/functionalTestJar")
64 classifier = null
65
66 // We do not need a version number for this internal jar
67 version = null
68
69 // Bundle the complete set of unit test classes including generated code
70 // and the runtime dependencies in one JAR to expedite execution.
71 from sourceSets.test.output
72 from sourceSets.crossTest.output
73 configurations = [project.configurations.testRuntime]
74}
75
76// Common script runner configuration elements
77def scriptExt = ''
78def execExt = ''
79def scriptHead = '#!/bin/bash'
80def args = '$*'
81
82// Although this is marked internal it is an available and stable interface
83if (org.gradle.internal.os.OperatingSystem.current().windows) {
84 scriptExt = '.bat'
85 execExt = '.exe'
86 scriptHead = '@echo off'
87 args = '%*'
88}
89
90// The Java executable to use with the runner scripts
91def javaExe = file("${System.getProperty('java.home')}/bin/java${execExt}").canonicalPath
92// The common Uber jar path
93def jarPath = shadowJar.archivePath.canonicalPath
94def trustStore = file('test/.truststore').canonicalPath
95def keyStore = file('test/.keystore').canonicalPath
96
97task generateRunnerScriptForClient(group: 'Build') {
98 description = 'Generate a runner script for cross-check tests with TestClient'
99
100 def clientFile = file("$buildDir/runclient${scriptExt}")
101
102 def runClientText = """\
103${scriptHead}
104
105"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.trustStore=$trustStore" -Djavax.net.ssl.trustStorePassword=thrift org.apache.thrift.test.TestClient $args
106"""
107 inputs.property 'runClientText', runClientText
108 outputs.file clientFile
109
110 doLast {
111 clientFile.parentFile.mkdirs()
112 clientFile.text = runClientText
113 clientFile.setExecutable(true, false)
114 }
115}
116
117task generateRunnerScriptForServer(group: 'Build') {
118 description = 'Generate a runner script for cross-check tests with TestServer'
119
120 def serverFile = file("$buildDir/runserver${scriptExt}")
121
122 def runServerText = """\
123${scriptHead}
124
125"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestServer $args
126"""
127
128 inputs.property 'runServerText', runServerText
129 outputs.file serverFile
130
131 doLast {
132 serverFile.parentFile.mkdirs()
133 serverFile.text = runServerText
134 serverFile.setExecutable(true, false)
135 }
136}
137
138task generateRunnerScriptForNonblockingServer(group: 'Build') {
139 description = 'Generate a runner script for cross-check tests with TestNonblockingServer'
140
141 def serverFile = file("$buildDir/runnonblockingserver${scriptExt}")
142
143 def runServerText = """\
144${scriptHead}
145
146"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestNonblockingServer $args
147"""
148
149 inputs.property 'runServerText', runServerText
150 outputs.file serverFile
151
152 doLast {
153 serverFile.parentFile.mkdirs()
154 serverFile.text = runServerText
155 serverFile.setExecutable(true, false)
156 }
157}
pengzhouhu6e4c5812019-10-21 22:21:11 +0800158
159task generateRunnerScriptForTServletServer(group: 'Build') {
160 description = 'Generate a runner script for cross-check tests with TestTServletServer'
161
162 def serverFile = file("$buildDir/runservletserver${scriptExt}")
163
164 def runServerText = """\
165${scriptHead}
166
167"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestTServletServer $args
168"""
169
170 inputs.property 'runServerText', runServerText
171 outputs.file serverFile
172
173 doLast {
174 serverFile.parentFile.mkdirs()
175 serverFile.text = runServerText
176 serverFile.setExecutable(true, false)
177 }
178}