blob: e8a3e8955ed209b39bc833de3e263896887935b8 [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 {
Alex Volanis7004a612018-01-24 10:30:13 -050033 }
34 }
35}
36
Jiayu Liueb62fa82022-05-08 13:01:41 +080037// see https://docs.gradle.org/current/userguide/java_library_plugin.html
38// 1. defines cross test implementation that includes all test implementation, which in turn
39// contains all implementation dependencies
40// 2. defines cross test runtime that further includes test runtime only dependencies
41// 3. the cross test implementation will need to depends on main and test output
42// 4. shadow jar will package both main and test source set, along with cross test runtime dependencies
Alex Volanis7004a612018-01-24 10:30:13 -050043configurations {
Jiayu Liueb62fa82022-05-08 13:01:41 +080044 crossTestImplementation {
45 description "implementation for cross test"
46 extendsFrom testImplementation
47 }
48 crossTestRuntime {
49 description "runtime dependencies for cross test"
50 extendsFrom crossTestImplementation, testRuntimeOnly
51 }
Alex Volanis7004a612018-01-24 10:30:13 -050052}
53
54dependencies {
Jiayu Liueb62fa82022-05-08 13:01:41 +080055 crossTestImplementation "org.apache.tomcat.embed:tomcat-embed-core:${tomcatEmbedVersion}"
56 crossTestImplementation sourceSets.main.output
57 crossTestImplementation sourceSets.test.output
Alex Volanis7004a612018-01-24 10:30:13 -050058}
59
60// I am using shadow plugin to make a self contained functional test Uber JAR that
61// eliminates startup problems with wrapping the cross-check harness in Gradle.
62// This is used by the runner scripts as the single classpath entry which
63// allows the process to be as lightweight as it can.
64shadowJar {
65 description = 'Assemble a test JAR file for cross-check execution'
66 // make sure the runners are created when this runs
pengzhouhu6e4c5812019-10-21 22:21:11 +080067 dependsOn 'generateRunnerScriptForClient', 'generateRunnerScriptForServer', 'generateRunnerScriptForNonblockingServer', 'generateRunnerScriptForTServletServer'
Jiayu Liueb62fa82022-05-08 13:01:41 +080068 archiveBaseName.set('functionalTest')
69 destinationDirectory = file("$buildDir/functionalTestJar")
70 archiveClassifier.set(null)
Alex Volanis7004a612018-01-24 10:30:13 -050071 // We do not need a version number for this internal jar
Jiayu Liueb62fa82022-05-08 13:01:41 +080072 archiveVersion.set(null)
Alex Volanis7004a612018-01-24 10:30:13 -050073 // Bundle the complete set of unit test classes including generated code
74 // and the runtime dependencies in one JAR to expedite execution.
Jiayu Liueb62fa82022-05-08 13:01:41 +080075 // see https://imperceptiblethoughts.com/shadow/custom-tasks/
Alex Volanis7004a612018-01-24 10:30:13 -050076 from sourceSets.test.output
77 from sourceSets.crossTest.output
Jiayu Liueb62fa82022-05-08 13:01:41 +080078 configurations = [project.configurations.crossTestRuntime]
Alex Volanis7004a612018-01-24 10:30:13 -050079}
80
81// Common script runner configuration elements
82def scriptExt = ''
83def execExt = ''
84def scriptHead = '#!/bin/bash'
85def args = '$*'
86
87// Although this is marked internal it is an available and stable interface
88if (org.gradle.internal.os.OperatingSystem.current().windows) {
89 scriptExt = '.bat'
90 execExt = '.exe'
91 scriptHead = '@echo off'
92 args = '%*'
93}
94
95// The Java executable to use with the runner scripts
96def javaExe = file("${System.getProperty('java.home')}/bin/java${execExt}").canonicalPath
97// The common Uber jar path
Jiayu Liueac51032022-03-11 04:55:13 +010098def jarPath = shadowJar.archiveFile.get().asFile.canonicalPath
99def trustStore = file("${projectDir}/src/crossTest/resources/.truststore").canonicalPath
100def keyStore = file("${projectDir}/src/crossTest/resources/.keystore").canonicalPath
Alex Volanis7004a612018-01-24 10:30:13 -0500101
102task generateRunnerScriptForClient(group: 'Build') {
103 description = 'Generate a runner script for cross-check tests with TestClient'
104
105 def clientFile = file("$buildDir/runclient${scriptExt}")
106
107 def runClientText = """\
108${scriptHead}
109
110"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.trustStore=$trustStore" -Djavax.net.ssl.trustStorePassword=thrift org.apache.thrift.test.TestClient $args
111"""
112 inputs.property 'runClientText', runClientText
113 outputs.file clientFile
114
115 doLast {
116 clientFile.parentFile.mkdirs()
117 clientFile.text = runClientText
118 clientFile.setExecutable(true, false)
119 }
120}
121
122task generateRunnerScriptForServer(group: 'Build') {
123 description = 'Generate a runner script for cross-check tests with TestServer'
124
125 def serverFile = file("$buildDir/runserver${scriptExt}")
126
127 def runServerText = """\
128${scriptHead}
129
130"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestServer $args
131"""
132
133 inputs.property 'runServerText', runServerText
134 outputs.file serverFile
135
136 doLast {
137 serverFile.parentFile.mkdirs()
138 serverFile.text = runServerText
139 serverFile.setExecutable(true, false)
140 }
141}
142
143task generateRunnerScriptForNonblockingServer(group: 'Build') {
144 description = 'Generate a runner script for cross-check tests with TestNonblockingServer'
145
146 def serverFile = file("$buildDir/runnonblockingserver${scriptExt}")
147
148 def runServerText = """\
149${scriptHead}
150
151"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestNonblockingServer $args
152"""
153
154 inputs.property 'runServerText', runServerText
155 outputs.file serverFile
156
157 doLast {
158 serverFile.parentFile.mkdirs()
159 serverFile.text = runServerText
160 serverFile.setExecutable(true, false)
161 }
162}
pengzhouhu6e4c5812019-10-21 22:21:11 +0800163
164task generateRunnerScriptForTServletServer(group: 'Build') {
165 description = 'Generate a runner script for cross-check tests with TestTServletServer'
166
167 def serverFile = file("$buildDir/runservletserver${scriptExt}")
168
169 def runServerText = """\
170${scriptHead}
171
172"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$keyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestTServletServer $args
173"""
174
175 inputs.property 'runServerText', runServerText
176 outputs.file serverFile
177
178 doLast {
179 serverFile.parentFile.mkdirs()
180 serverFile.text = runServerText
181 serverFile.setExecutable(true, false)
182 }
183}