From 3624d59b187dc9e609adf4769c8eb378507e0209 Mon Sep 17 00:00:00 2001 From: yifeizhuang Date: Fri, 3 Jun 2022 09:31:00 -0700 Subject: [PATCH] interop-test: orca test change gradle dependency to xds non-shaded to allow bazel run (#9230) Co-authored-by: Eric Anderson --- interop-testing/build.gradle | 59 ++++++++++++++----- ...tomBackendMetricsLoadBalancerProvider.java | 2 +- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/interop-testing/build.gradle b/interop-testing/build.gradle index d0699b0eed7..385374db2fb 100644 --- a/interop-testing/build.gradle +++ b/interop-testing/build.gradle @@ -3,11 +3,14 @@ plugins { id "java" id "maven-publish" + id "com.github.johnrengelman.shadow" id "com.google.protobuf" } description = "gRPC: Integration Testing" -startScripts.enabled = false +startShadowScripts.enabled = false +installDist.dependsOn(installShadowDist) +installDist.enabled = false configurations { alpnagent @@ -26,13 +29,16 @@ dependencies { project(':grpc-services'), project(':grpc-stub'), project(':grpc-testing'), - project(path: ':grpc-xds', configuration: 'shadow'), libraries.hdrhistogram, libraries.junit, libraries.truth, libraries.opencensus_contrib_grpc_metrics, libraries.google_auth_oauth2_http + def xdsDependency = implementation project(':grpc-xds') + compileOnly libraries.javax_annotation + shadow configurations.implementation.getDependencies().minus(xdsDependency) + shadow project(path: ':grpc-xds', configuration: 'shadow') // TODO(sergiitk): replace with com.google.cloud:google-cloud-logging // Used instead of google-cloud-logging because it's failing // due to a circular dependency on grpc. @@ -60,6 +66,19 @@ compileJava { // This isn't a library; it can use beta APIs options.errorprone.check("BetaApi", CheckSeverity.OFF) } +jar { + // Must use a different archiveClassifier to avoid conflicting with shadowJar + archiveClassifier = 'original' +} + +def xdsPrefixName = 'io.grpc.xds' +shadowJar { + archiveClassifier = null + dependencies { + exclude(dependency {true}) + } + relocate 'com.github.xds', "${xdsPrefixName}.shaded.com.github.xds" +} test { // For the automated tests, use Jetty ALPN. @@ -69,6 +88,8 @@ test { // For the generated scripts, use Netty tcnative (i.e. OpenSSL). // Note that OkHttp currently only supports ALPN, so OpenSSL version >= 1.0.2 is required. +var startScriptsClasspath = shadowJar.outputs.files + configurations.shadow + task test_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.TestServiceClient" applicationName = "test-client" @@ -76,7 +97,7 @@ task test_client(type: CreateStartScripts) { "-javaagent:JAVAAGENT_APP_HOME" + configurations.alpnagent.singleFile.name ] outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath doLast { unixScript.text = unixScript.text.replace('JAVAAGENT_APP_HOME', '\'"\$APP_HOME"\'/lib/') windowsScript.text = windowsScript.text.replace('JAVAAGENT_APP_HOME', '%APP_HOME%\\lib\\') @@ -87,21 +108,21 @@ task test_server(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.TestServiceServer" applicationName = "test-server" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath } task reconnect_test_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.ReconnectTestClient" applicationName = "reconnect-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath } task stresstest_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.StressTestClient" applicationName = "stresstest-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath defaultJvmOpts = [ "-verbose:gc", "-XX:+PrintFlagsFinal" @@ -112,14 +133,14 @@ task http2_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.Http2Client" applicationName = "http2-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath } task grpclb_long_lived_affinity_test_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.GrpclbLongLivedAffinityTestClient" applicationName = "grpclb-long-lived-affinity-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath defaultJvmOpts = [ "-Dio.grpc.internal.DnsNameResolverProvider.enable_service_config=true" ] @@ -129,7 +150,7 @@ task grpclb_fallback_test_client (type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.GrpclbFallbackTestClient" applicationName = "grpclb-fallback-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath defaultJvmOpts = [ "-Dio.grpc.internal.DnsNameResolverProvider.enable_service_config=true" ] @@ -139,17 +160,17 @@ task xds_test_client(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.XdsTestClient" applicationName = "xds-test-client" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath } task xds_test_server(type: CreateStartScripts) { mainClass = "io.grpc.testing.integration.XdsTestServer" applicationName = "xds-test-server" outputDir = new File(project.buildDir, 'tmp/scripts/' + name) - classpath = startScripts.classpath + classpath = startScriptsClasspath } -applicationDistribution.into("bin") { +distributions.shadow.contents.into("bin") { from(test_client) from(test_server) from(reconnect_test_client) @@ -162,15 +183,23 @@ applicationDistribution.into("bin") { fileMode = 0755 } -applicationDistribution.into("lib") { +distributions.shadow.contents.into("lib") { from(configurations.alpnagent) } +distributions.shadow.distributionBaseName = project.name +// to please shadowJar +mainClassName = 'io.grpc.testing.integration.TestServiceClient' + publishing { publications { maven(MavenPublication) { - artifact distZip - artifact distTar + // We want this to throw an exception if it isn't working + def originalJar = artifacts.find { dep -> dep.classifier == 'original'} + artifacts.remove(originalJar) + + artifact shadowDistZip + artifact shadowDistTar } } } diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/CustomBackendMetricsLoadBalancerProvider.java b/interop-testing/src/main/java/io/grpc/testing/integration/CustomBackendMetricsLoadBalancerProvider.java index fc5b5f8e956..372403ed47f 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/CustomBackendMetricsLoadBalancerProvider.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/CustomBackendMetricsLoadBalancerProvider.java @@ -19,6 +19,7 @@ import static io.grpc.testing.integration.AbstractInteropTest.ORCA_OOB_REPORT_KEY; import static io.grpc.testing.integration.AbstractInteropTest.ORCA_RPC_REPORT_KEY; +import com.github.xds.data.orca.v3.OrcaLoadReport; import io.grpc.ConnectivityState; import io.grpc.LoadBalancer; import io.grpc.LoadBalancerProvider; @@ -28,7 +29,6 @@ import io.grpc.util.ForwardingLoadBalancerHelper; import io.grpc.xds.orca.OrcaOobUtil; import io.grpc.xds.orca.OrcaPerRequestUtil; -import io.grpc.xds.shaded.com.github.xds.data.orca.v3.OrcaLoadReport; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference;