xref: /aosp_15_r20/external/grpc-grpc-java/gae-interop-testing/gae-jdk8/build.gradle (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard Worker// Copyright 2017 The gRPC Authors
2*e07d83d3SAndroid Build Coastguard Worker//
3*e07d83d3SAndroid Build Coastguard Worker//  Licensed under the Apache License, Version 2.0 (the "License");
4*e07d83d3SAndroid Build Coastguard Worker//  you may not use this file except in compliance with the License.
5*e07d83d3SAndroid Build Coastguard Worker//  You may obtain a copy of the License at
6*e07d83d3SAndroid Build Coastguard Worker//
7*e07d83d3SAndroid Build Coastguard Worker//        http://www.apache.org/licenses/LICENSE-2.0
8*e07d83d3SAndroid Build Coastguard Worker//
9*e07d83d3SAndroid Build Coastguard Worker//  Unless required by applicable law or agreed to in writing, software
10*e07d83d3SAndroid Build Coastguard Worker//  distributed under the License is distributed on an "AS IS" BASIS,
11*e07d83d3SAndroid Build Coastguard Worker//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*e07d83d3SAndroid Build Coastguard Worker//  See the License for the specific language governing permissions and
13*e07d83d3SAndroid Build Coastguard Worker//  limitations under the License.
14*e07d83d3SAndroid Build Coastguard Worker
15*e07d83d3SAndroid Build Coastguard Workerbuildscript {
16*e07d83d3SAndroid Build Coastguard Worker    // Configuration for building
17*e07d83d3SAndroid Build Coastguard Worker    repositories {
18*e07d83d3SAndroid Build Coastguard Worker        maven { // The google mirror is less flaky than mavenCentral()
19*e07d83d3SAndroid Build Coastguard Worker            url "https://maven-central.storage-download.googleapis.com/maven2/" }
20*e07d83d3SAndroid Build Coastguard Worker    }
21*e07d83d3SAndroid Build Coastguard Worker    dependencies {
22*e07d83d3SAndroid Build Coastguard Worker        classpath 'com.squareup.okhttp:okhttp:2.7.4'
23*e07d83d3SAndroid Build Coastguard Worker    }
24*e07d83d3SAndroid Build Coastguard Worker}
25*e07d83d3SAndroid Build Coastguard Worker
26*e07d83d3SAndroid Build Coastguard Workerplugins {
27*e07d83d3SAndroid Build Coastguard Worker    id "java"
28*e07d83d3SAndroid Build Coastguard Worker    id "war"
29*e07d83d3SAndroid Build Coastguard Worker
30*e07d83d3SAndroid Build Coastguard Worker    id "ru.vyarus.animalsniffer"
31*e07d83d3SAndroid Build Coastguard Worker    id 'com.google.cloud.tools.appengine' version '2.3.0'
32*e07d83d3SAndroid Build Coastguard Worker}
33*e07d83d3SAndroid Build Coastguard Worker
34*e07d83d3SAndroid Build Coastguard Workerdescription = 'gRPC: gae interop testing (jdk8)'
35*e07d83d3SAndroid Build Coastguard Worker
36*e07d83d3SAndroid Build Coastguard Workerrepositories {
37*e07d83d3SAndroid Build Coastguard Worker    // repositories for Jar's you access in your code
38*e07d83d3SAndroid Build Coastguard Worker    mavenLocal()
39*e07d83d3SAndroid Build Coastguard Worker    maven { // The google mirror is less flaky than mavenCentral()
40*e07d83d3SAndroid Build Coastguard Worker        url "https://maven-central.storage-download.googleapis.com/maven2/" }
41*e07d83d3SAndroid Build Coastguard Worker}
42*e07d83d3SAndroid Build Coastguard Worker
43*e07d83d3SAndroid Build Coastguard Workerapply plugin: 'com.google.cloud.tools.appengine'  // App Engine tasks
44*e07d83d3SAndroid Build Coastguard Worker
45*e07d83d3SAndroid Build Coastguard Workerdependencies {
46*e07d83d3SAndroid Build Coastguard Worker    providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
47*e07d83d3SAndroid Build Coastguard Worker    runtimeOnly 'com.google.appengine:appengine-api-1.0-sdk:1.9.59'
48*e07d83d3SAndroid Build Coastguard Worker    implementation project(':grpc-netty')
49*e07d83d3SAndroid Build Coastguard Worker    implementation project(":grpc-stub")
50*e07d83d3SAndroid Build Coastguard Worker    implementation (project(':grpc-interop-testing')) {
51*e07d83d3SAndroid Build Coastguard Worker        // Avoid grpc-netty-shaded dependency
52*e07d83d3SAndroid Build Coastguard Worker        exclude group: 'io.grpc', module: 'grpc-alts'
53*e07d83d3SAndroid Build Coastguard Worker        exclude group: 'io.grpc', module: 'grpc-xds'
54*e07d83d3SAndroid Build Coastguard Worker    }
55*e07d83d3SAndroid Build Coastguard Worker    implementation libraries.junit
56*e07d83d3SAndroid Build Coastguard Worker    implementation libraries.protobuf.java
57*e07d83d3SAndroid Build Coastguard Worker    runtimeOnly libraries.netty.tcnative, libraries.netty.tcnative.classes
58*e07d83d3SAndroid Build Coastguard Worker    signature libraries.signature.java
59*e07d83d3SAndroid Build Coastguard Worker}
60*e07d83d3SAndroid Build Coastguard Worker
61*e07d83d3SAndroid Build Coastguard Workertasks.named("compileJava").configure {
62*e07d83d3SAndroid Build Coastguard Worker    // Disable "No processor claimed any of these annotations: org.junit.Ignore"
63*e07d83d3SAndroid Build Coastguard Worker    options.compilerArgs += ["-Xlint:-processing"]
64*e07d83d3SAndroid Build Coastguard Worker}
65*e07d83d3SAndroid Build Coastguard Worker
66*e07d83d3SAndroid Build Coastguard Workerdef createDefaultVersion() {
67*e07d83d3SAndroid Build Coastguard Worker    return new java.text.SimpleDateFormat("yyyyMMdd't'HHmmss").format(new Date())
68*e07d83d3SAndroid Build Coastguard Worker}
69*e07d83d3SAndroid Build Coastguard Worker
70*e07d83d3SAndroid Build Coastguard Worker// [START model]
71*e07d83d3SAndroid Build Coastguard Workerappengine {
72*e07d83d3SAndroid Build Coastguard Worker    // App Engine tasks configuration
73*e07d83d3SAndroid Build Coastguard Worker    run {      // local (dev_appserver) configuration (standard environments only)
74*e07d83d3SAndroid Build Coastguard Worker        port = 8080                 // default
75*e07d83d3SAndroid Build Coastguard Worker    }
76*e07d83d3SAndroid Build Coastguard Worker
77*e07d83d3SAndroid Build Coastguard Worker    deploy {
78*e07d83d3SAndroid Build Coastguard Worker        // deploy configuration
79*e07d83d3SAndroid Build Coastguard Worker        projectId = 'GCLOUD_CONFIG'
80*e07d83d3SAndroid Build Coastguard Worker        // default - stop the current version
81*e07d83d3SAndroid Build Coastguard Worker        stopPreviousVersion = System.getProperty('gaeStopPreviousVersion') ?: true
82*e07d83d3SAndroid Build Coastguard Worker        // default - do not make this the promoted version
83*e07d83d3SAndroid Build Coastguard Worker        promote = System.getProperty('gaePromote') ?: false
84*e07d83d3SAndroid Build Coastguard Worker        // Use -DgaeDeployVersion if set, otherwise the version is null and the plugin will generate it
85*e07d83d3SAndroid Build Coastguard Worker        version = System.getProperty('gaeDeployVersion', createDefaultVersion())
86*e07d83d3SAndroid Build Coastguard Worker    }
87*e07d83d3SAndroid Build Coastguard Worker}
88*e07d83d3SAndroid Build Coastguard Worker// [END model]
89*e07d83d3SAndroid Build Coastguard Worker
90*e07d83d3SAndroid Build Coastguard Workergroup = 'io.grpc'   // Generated output GroupId
91*e07d83d3SAndroid Build Coastguard Workerversion = '1.0-SNAPSHOT'          // Version in generated output
92*e07d83d3SAndroid Build Coastguard Worker
93*e07d83d3SAndroid Build Coastguard WorkersourceCompatibility = 1.8
94*e07d83d3SAndroid Build Coastguard WorkertargetCompatibility = 1.8
95*e07d83d3SAndroid Build Coastguard Worker
96*e07d83d3SAndroid Build Coastguard Worker/** Returns the service name. */
97*e07d83d3SAndroid Build Coastguard WorkerString getGaeProject() {
98*e07d83d3SAndroid Build Coastguard Worker    def stream = new ByteArrayOutputStream()
99*e07d83d3SAndroid Build Coastguard Worker    exec {
100*e07d83d3SAndroid Build Coastguard Worker        executable 'gcloud'
101*e07d83d3SAndroid Build Coastguard Worker        args = [
102*e07d83d3SAndroid Build Coastguard Worker            'config',
103*e07d83d3SAndroid Build Coastguard Worker            'get-value',
104*e07d83d3SAndroid Build Coastguard Worker            'project'
105*e07d83d3SAndroid Build Coastguard Worker        ]
106*e07d83d3SAndroid Build Coastguard Worker        standardOutput = stream
107*e07d83d3SAndroid Build Coastguard Worker    }
108*e07d83d3SAndroid Build Coastguard Worker    return stream.toString().trim()
109*e07d83d3SAndroid Build Coastguard Worker}
110*e07d83d3SAndroid Build Coastguard Worker
111*e07d83d3SAndroid Build Coastguard WorkerString getService(java.nio.file.Path projectPath) {
112*e07d83d3SAndroid Build Coastguard Worker    Node xml = new XmlParser().parse(projectPath.resolve("src/main/webapp/WEB-INF/appengine-web.xml").toFile())
113*e07d83d3SAndroid Build Coastguard Worker    if (xml.service.isEmpty()) {
114*e07d83d3SAndroid Build Coastguard Worker        return "default"
115*e07d83d3SAndroid Build Coastguard Worker    } else {
116*e07d83d3SAndroid Build Coastguard Worker        return xml.service.text()
117*e07d83d3SAndroid Build Coastguard Worker    }
118*e07d83d3SAndroid Build Coastguard Worker}
119*e07d83d3SAndroid Build Coastguard Worker
120*e07d83d3SAndroid Build Coastguard WorkerString getAppUrl(String project, String service, String version) {
121*e07d83d3SAndroid Build Coastguard Worker    return "http://${version}.${service}.${project}.appspot.com"
122*e07d83d3SAndroid Build Coastguard Worker}
123*e07d83d3SAndroid Build Coastguard Worker
124*e07d83d3SAndroid Build Coastguard Workertasks.register("runInteropTestRemote") {
125*e07d83d3SAndroid Build Coastguard Worker    dependsOn appengineDeploy
126*e07d83d3SAndroid Build Coastguard Worker    doLast {
127*e07d83d3SAndroid Build Coastguard Worker        // give remote app some time to settle down
128*e07d83d3SAndroid Build Coastguard Worker        sleep(20000)
129*e07d83d3SAndroid Build Coastguard Worker
130*e07d83d3SAndroid Build Coastguard Worker        def appUrl = getAppUrl(
131*e07d83d3SAndroid Build Coastguard Worker                getGaeProject(),
132*e07d83d3SAndroid Build Coastguard Worker                getService(project.getProjectDir().toPath()),
133*e07d83d3SAndroid Build Coastguard Worker                appengine.deploy.version)
134*e07d83d3SAndroid Build Coastguard Worker        logger.log(LogLevel.INFO, "the appURL=" + appUrl)
135*e07d83d3SAndroid Build Coastguard Worker        def client = new com.squareup.okhttp.OkHttpClient()
136*e07d83d3SAndroid Build Coastguard Worker        // The '?jdk8' argument is ignored by the server, it exists only to tag the request log entry
137*e07d83d3SAndroid Build Coastguard Worker        client.setReadTimeout(30, java.util.concurrent.TimeUnit.SECONDS)
138*e07d83d3SAndroid Build Coastguard Worker        def request = new com.squareup.okhttp.Request.Builder()
139*e07d83d3SAndroid Build Coastguard Worker                .url("${appUrl}/long_lived_channel?jdk8").build()
140*e07d83d3SAndroid Build Coastguard Worker        def result1 = client.newCall(request).execute()
141*e07d83d3SAndroid Build Coastguard Worker        def result2 = client.newCall(request).execute()
142*e07d83d3SAndroid Build Coastguard Worker        if (result1.code() != 200 || result2.code() != 200) {
143*e07d83d3SAndroid Build Coastguard Worker            throw new GradleException("Unable to reuse same channel across requests")
144*e07d83d3SAndroid Build Coastguard Worker        }
145*e07d83d3SAndroid Build Coastguard Worker
146*e07d83d3SAndroid Build Coastguard Worker        // The test suite can take a while to run
147*e07d83d3SAndroid Build Coastguard Worker        client.setReadTimeout(3, java.util.concurrent.TimeUnit.MINUTES)
148*e07d83d3SAndroid Build Coastguard Worker        // The '?jdk8' argument is ignored by the server, it exists only to tag the request log entry
149*e07d83d3SAndroid Build Coastguard Worker        def interopRequest = new com.squareup.okhttp.Request.Builder()
150*e07d83d3SAndroid Build Coastguard Worker                .url("${appUrl}/?jdk8").build()
151*e07d83d3SAndroid Build Coastguard Worker
152*e07d83d3SAndroid Build Coastguard Worker        // Retry in case GAE is slow and times out
153*e07d83d3SAndroid Build Coastguard Worker        int maxRetries = 5
154*e07d83d3SAndroid Build Coastguard Worker        String result = null
155*e07d83d3SAndroid Build Coastguard Worker        Throwable caught = null
156*e07d83d3SAndroid Build Coastguard Worker        for (int attempt = 0; attempt < maxRetries; attempt++) {
157*e07d83d3SAndroid Build Coastguard Worker            try {
158*e07d83d3SAndroid Build Coastguard Worker                def response = client.newCall(interopRequest).execute()
159*e07d83d3SAndroid Build Coastguard Worker                result = response.body().string()
160*e07d83d3SAndroid Build Coastguard Worker                project.println(result)
161*e07d83d3SAndroid Build Coastguard Worker                if (response.code() == 200) {
162*e07d83d3SAndroid Build Coastguard Worker                    return
163*e07d83d3SAndroid Build Coastguard Worker                }
164*e07d83d3SAndroid Build Coastguard Worker            } catch (Throwable t) {
165*e07d83d3SAndroid Build Coastguard Worker                caught = t
166*e07d83d3SAndroid Build Coastguard Worker                logger.log(LogLevel.ERROR, "caught exception. will retry if possible", t)
167*e07d83d3SAndroid Build Coastguard Worker            }
168*e07d83d3SAndroid Build Coastguard Worker        }
169*e07d83d3SAndroid Build Coastguard Worker        throw new GradleException("Interop test failed:\nthrowable:${caught}")
170*e07d83d3SAndroid Build Coastguard Worker    }
171*e07d83d3SAndroid Build Coastguard Worker}
172