blob: b3f5d8b1af6132f49859c96fd8423b8ddacfe8dc [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")
Alex Volanis7004a612018-01-24 10:30:13 -050070 // We do not need a version number for this internal jar
Jiayu Liueb62fa82022-05-08 13:01:41 +080071 archiveVersion.set(null)
Alex Volanis7004a612018-01-24 10:30:13 -050072 // Bundle the complete set of unit test classes including generated code
73 // and the runtime dependencies in one JAR to expedite execution.
Jiayu Liueb62fa82022-05-08 13:01:41 +080074 // see https://imperceptiblethoughts.com/shadow/custom-tasks/
Alex Volanis7004a612018-01-24 10:30:13 -050075 from sourceSets.test.output
76 from sourceSets.crossTest.output
Jiayu Liueb62fa82022-05-08 13:01:41 +080077 configurations = [project.configurations.crossTestRuntime]
Alex Volanis7004a612018-01-24 10:30:13 -050078}
79
80// Common script runner configuration elements
81def scriptExt = ''
82def execExt = ''
83def scriptHead = '#!/bin/bash'
84def args = '$*'
85
86// Although this is marked internal it is an available and stable interface
87if (org.gradle.internal.os.OperatingSystem.current().windows) {
88 scriptExt = '.bat'
89 execExt = '.exe'
90 scriptHead = '@echo off'
91 args = '%*'
92}
93
94// The Java executable to use with the runner scripts
95def javaExe = file("${System.getProperty('java.home')}/bin/java${execExt}").canonicalPath
96// The common Uber jar path
Jiayu Liueac51032022-03-11 04:55:13 +010097def jarPath = shadowJar.archiveFile.get().asFile.canonicalPath
98def trustStore = file("${projectDir}/src/crossTest/resources/.truststore").canonicalPath
Dmytro Shteflyuk312cef92025-11-23 12:35:09 -050099def serverKeyStore = file("${projectDir}/src/crossTest/resources/.serverkeystore").canonicalPath
100def clientKeyStore = file("${projectDir}/src/crossTest/resources/.clientkeystore").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
Dmytro Shteflyuk312cef92025-11-23 12:35:09 -0500110"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$clientKeyStore" -Djavax.net.ssl.keyStorePassword=thrift "-Djavax.net.ssl.trustStore=$trustStore" -Djavax.net.ssl.trustStorePassword=thrift org.apache.thrift.test.TestClient $args
Alex Volanis7004a612018-01-24 10:30:13 -0500111"""
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
Dmytro Shteflyuk312cef92025-11-23 12:35:09 -0500130"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$serverKeyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestServer $args
Alex Volanis7004a612018-01-24 10:30:13 -0500131"""
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
Dmytro Shteflyuk312cef92025-11-23 12:35:09 -0500151"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$serverKeyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestNonblockingServer $args
Alex Volanis7004a612018-01-24 10:30:13 -0500152"""
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
Dmytro Shteflyuk312cef92025-11-23 12:35:09 -0500172"${javaExe}" -cp "$jarPath" "-Djavax.net.ssl.keyStore=$serverKeyStore" -Djavax.net.ssl.keyStorePassword=thrift org.apache.thrift.test.TestTServletServer $args
pengzhouhu6e4c5812019-10-21 22:21:11 +0800173"""
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}