Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/grpc/grpc-java into fix-o…
Browse files Browse the repository at this point in the history
…khttp-pad-len
  • Loading branch information
YifeiZhuang committed Aug 16, 2023
2 parents 7702e16 + f906562 commit 247c2db
Show file tree
Hide file tree
Showing 70 changed files with 3,732 additions and 495 deletions.
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Tagging the Release
tools/interop_matrix/testcases/java__master

# Commit the changes
git commit --all -m "Add grpc-java $MAJOR.$MINOR.$PATCH to client_matrix.py"
git commit --all -m "[interop] Add grpc-java $MAJOR.$MINOR.$PATCH to client_matrix.py"

# Create a PR with the `release notes: no` label and run ad-hoc test against your PR
```
Expand Down
1 change: 1 addition & 0 deletions all/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def subprojects = [
project(':grpc-servlet-jakarta'),
project(':grpc-stub'),
project(':grpc-testing'),
project(':grpc-util'),
project(':grpc-xds'),
]

Expand Down
3 changes: 1 addition & 2 deletions android-interop-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ dependencies {

compileOnly libraries.javax.annotation

androidTestImplementation project(':grpc-netty'),
'androidx.test.ext:junit:1.1.3',
androidTestImplementation 'androidx.test.ext:junit:1.1.3',
'androidx.test:runner:1.4.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import androidx.test.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.ActivityTestRule;
import io.grpc.Grpc;
import io.grpc.InsecureServerCredentials;
import io.grpc.Server;
import io.grpc.android.UdsChannelBuilder;
import io.grpc.netty.NettyServerBuilder;
import io.grpc.testing.integration.TestServiceImpl;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -68,7 +69,7 @@ public void setUp() throws IOException {

// Start local server.
server =
NettyServerBuilder.forPort(0)
Grpc.newServerBuilderForPort(0, InsecureServerCredentials.create())
.maxInboundMessageSize(16 * 1024 * 1024)
.addService(new TestServiceImpl(serverExecutor))
.build();
Expand Down
35 changes: 35 additions & 0 deletions api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public abstract class LoadBalancer {
@NameResolver.ResolutionResultAttr
public static final Attributes.Key<Map<String, ?>> ATTR_HEALTH_CHECKING_CONFIG =
Attributes.Key.create("internal:health-checking-config");

public static final SubchannelPicker EMPTY_PICKER = new SubchannelPicker() {
@Override
public PickResult pickSubchannel(PickSubchannelArgs args) {
return PickResult.withNoResult();
}

@Override
public String toString() {
return "EMPTY_PICKER";
}
};

private int recursionCount;

/**
Expand Down Expand Up @@ -1398,4 +1411,26 @@ public abstract static class Factory {
*/
public abstract LoadBalancer newLoadBalancer(Helper helper);
}

public static final class ErrorPicker extends SubchannelPicker {

private final Status error;

public ErrorPicker(Status error) {
this.error = checkNotNull(error, "error");
}

@Override
public PickResult pickSubchannel(PickSubchannelArgs args) {
return PickResult.withError(error);
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("error", error)
.toString();
}
}

}
17 changes: 16 additions & 1 deletion api/src/main/java/io/grpc/ServerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Comparator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.concurrent.GuardedBy;
import javax.annotation.concurrent.ThreadSafe;
Expand Down Expand Up @@ -92,7 +93,7 @@ public static synchronized ServerRegistry getDefaultRegistry() {
if (instance == null) {
List<ServerProvider> providerList = ServiceProviders.loadAll(
ServerProvider.class,
Collections.<Class<?>>emptyList(),
getHardCodedClasses(),
ServerProvider.class.getClassLoader(),
new ServerPriorityAccessor());
instance = new ServerRegistry();
Expand All @@ -119,6 +120,20 @@ ServerProvider provider() {
return providers.isEmpty() ? null : providers.get(0);
}

@VisibleForTesting
static List<Class<?>> getHardCodedClasses() {
// Class.forName(String) is used to remove the need for ProGuard configuration. Note that
// ProGuard does not detect usages of Class.forName(String, boolean, ClassLoader):
// https://sourceforge.net/p/proguard/bugs/418/
List<Class<?>> list = new ArrayList<>();
try {
list.add(Class.forName("io.grpc.okhttp.OkHttpServerProvider"));
} catch (ClassNotFoundException e) {
logger.log(Level.FINE, "Unable to find OkHttpServerProvider", e);
}
return Collections.unmodifiableList(list);
}

ServerBuilder<?> newServerBuilderForPort(int port, ServerCredentials creds) {
List<ServerProvider> providers = providers();
if (providers.isEmpty()) {
Expand Down
26 changes: 26 additions & 0 deletions api/src/testFixtures/java/io/grpc/ServerRegistryAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc;

/** Accesses test-only methods of {@link ServerRegistry}. */
public final class ServerRegistryAccessor {
private ServerRegistryAccessor() {}

public static Iterable<Class<?>> getHardCodedClasses() {
return ServerRegistry.getHardCodedClasses();
}
}
28 changes: 10 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -417,31 +417,25 @@ subprojects {
def baselineGrpcVersion = '1.6.1'

// Get the baseline version's jar for this subproject
File baselineArtifact = null
// Use a detached configuration, otherwise the current version's jar will take precedence
// over the baseline jar.
configurations {
baselineArtifact
}
// A necessary hack, the intuitive thing does NOT work:
// https://discuss.gradle.org/t/is-the-default-configuration-leaking-into-independent-configurations/2088/6
def oldGroup = project.group
try {
project.group = 'virtual_group_for_japicmp'
String depModule = "io.grpc:${project.name}:${baselineGrpcVersion}@jar"
String depJar = "${project.name}-${baselineGrpcVersion}.jar"
Configuration configuration = configurations.detachedConfiguration(
dependencies.create(depModule)
)
baselineArtifact = files(configuration.files).filter {
it.name.equals(depJar)
}.singleFile
dependencies {
baselineArtifact "io.grpc:${project.name}:${baselineGrpcVersion}@jar"
}
} finally {
project.group = oldGroup
}

// Add a japicmp task that compares the current .jar with baseline .jar
tasks.register("japicmp", me.champeau.gradle.japicmp.JapicmpTask) {
dependsOn jar
oldClasspath.from baselineArtifact
newClasspath.from jar.archiveFile
oldClasspath.from configurations.baselineArtifact
newClasspath.from tasks.named("jar")
onlyBinaryIncompatibleModified = false
// Be quiet about things that did not change
onlyModified = true
Expand All @@ -454,12 +448,10 @@ subprojects {

// Also break on source incompatible changes, not just binary.
// Eg adding abstract method to public class.
// TODO(zpencer): enable after japicmp-gradle-plugin/pull/14
// breakOnSourceIncompatibility = true
failOnSourceIncompatibility = true

// Ignore any classes or methods marked @ExperimentalApi
// TODO(zpencer): enable after japicmp-gradle-plugin/pull/15
// annotationExcludes = ['@io.grpc.ExperimentalApi']
annotationExcludes = ['@io.grpc.ExperimentalApi']
}
}
}
Expand Down
Loading

0 comments on commit 247c2db

Please sign in to comment.