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