mirror of https://github.com/grpc/grpc-java.git
core: Move io.grpc to grpc-api
io.grpc has fewer dependencies than io.grpc.internal. Moving it to a separate artifact lets users use the API without bringing in the deps. If the library has an optional dependency on grpc, that can be quite convenient. We now version-pin both grpc-api and grpc-core, since both contain internal APIs. I had to change a few tests in grpc-api to avoid FakeClock. Moving FakeClock to grpc-api was difficult because it uses io.grpc.internal.TimeProvider, which can't be moved since it is a production class. Having grpc-api's tests depend on grpc-core's test classes would be weird and cause a circular dependincy. Having grpc-api's tests depend on grpc-core is likely possible, but weird and fairly unnecessary at this point. So instead I rewrote the tests to avoid FakeClock. Fixes #1447
This commit is contained in:
parent
f3731eabb3
commit
80c3c992a6
|
|
@ -29,7 +29,7 @@ java_library(
|
|||
name = "java_grpc_library_deps__do_not_reference",
|
||||
visibility = ["//visibility:public"],
|
||||
exports = [
|
||||
"//core",
|
||||
"//api",
|
||||
"//protobuf",
|
||||
"//stub",
|
||||
"//stub:javax_annotation",
|
||||
|
|
@ -43,7 +43,7 @@ java_library(
|
|||
name = "java_lite_grpc_library_deps__do_not_reference",
|
||||
visibility = ["//visibility:public"],
|
||||
exports = [
|
||||
"//core",
|
||||
"//api",
|
||||
"//protobuf-lite",
|
||||
"//stub",
|
||||
"//stub:javax_annotation",
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ buildscript {
|
|||
}
|
||||
|
||||
def subprojects = [
|
||||
project(':grpc-api'),
|
||||
project(':grpc-auth'),
|
||||
project(':grpc-core'),
|
||||
project(':grpc-context'),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ java_library(
|
|||
deps = [
|
||||
":handshaker_java_grpc",
|
||||
":handshaker_java_proto",
|
||||
"//core",
|
||||
"//api",
|
||||
"//core:internal",
|
||||
"//netty",
|
||||
"//stub",
|
||||
|
|
@ -35,8 +35,8 @@ java_library(
|
|||
deps = [
|
||||
":alts_internal",
|
||||
":handshaker_java_grpc",
|
||||
"//api",
|
||||
"//auth",
|
||||
"//core",
|
||||
"//core:internal",
|
||||
"//netty",
|
||||
"@com_google_auth_google_auth_library_oauth2_http//jar",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
java_library(
|
||||
name = "api",
|
||||
srcs = glob([
|
||||
"src/main/java/**/*.java",
|
||||
]),
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//context",
|
||||
"@com_google_code_findbugs_jsr305//jar",
|
||||
"@com_google_guava_failureaccess//jar", # future transitive dep of Guava. See #5214
|
||||
"@com_google_guava_guava//jar",
|
||||
"@com_google_j2objc_j2objc_annotations//jar",
|
||||
],
|
||||
)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
description = 'gRPC: API'
|
||||
|
||||
dependencies {
|
||||
compile project(':grpc-context'),
|
||||
libraries.errorprone,
|
||||
libraries.jsr305,
|
||||
libraries.animalsniffer_annotations
|
||||
compile (libraries.guava) {
|
||||
// prefer 2.3.2 from libraries instead of 2.1.3
|
||||
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
|
||||
// prefer 3.0.2 from libraries instead of 3.0.1
|
||||
exclude group: 'com.google.code.findbugs', module: 'jsr305'
|
||||
// prefer 1.17 from libraries instead of 1.14
|
||||
exclude group: 'org.codehaus.mojo', module: 'animal-sniffer-annotations'
|
||||
}
|
||||
|
||||
testCompile project(':grpc-context').sourceSets.test.output,
|
||||
project(':grpc-testing'),
|
||||
project(':grpc-grpclb'),
|
||||
libraries.guava_testlib
|
||||
|
||||
jmh project(':grpc-core')
|
||||
|
||||
signature "org.codehaus.mojo.signature:java17:1.0@signature"
|
||||
signature "net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature"
|
||||
}
|
||||
|
||||
javadoc {
|
||||
// We want io.grpc.Internal, but not io.grpc.Internal*
|
||||
exclude 'io/grpc/Internal?*.java'
|
||||
exclude 'io/grpc/internal/**'
|
||||
}
|
||||
|
|
@ -28,11 +28,13 @@ import static org.junit.Assert.assertThat;
|
|||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import io.grpc.internal.FakeClock;
|
||||
import com.google.common.util.concurrent.testing.TestingExecutors;
|
||||
import io.grpc.internal.NoopServerCall;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import org.junit.Test;
|
||||
|
|
@ -213,11 +215,29 @@ public class ContextsTest {
|
|||
|
||||
@Test
|
||||
public void statusFromCancelled_TimeoutExceptionShouldMapToDeadlineExceeded() {
|
||||
FakeClock fakeClock = new FakeClock();
|
||||
final long expectedDelay = 100;
|
||||
final TimeUnit expectedUnit = TimeUnit.SECONDS;
|
||||
class MockScheduledExecutorService extends ForwardingScheduledExecutorService {
|
||||
private ScheduledExecutorService delegate = TestingExecutors.noOpScheduledExecutor();
|
||||
Runnable command;
|
||||
|
||||
@Override public ScheduledExecutorService delegate() {
|
||||
return delegate;
|
||||
}
|
||||
|
||||
@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
|
||||
if (delay > unit.convert(expectedDelay, expectedUnit)) {
|
||||
fail("Delay larger than expected: " + delay + " " + unit);
|
||||
}
|
||||
this.command = command;
|
||||
return super.schedule(command, delay, unit);
|
||||
}
|
||||
}
|
||||
|
||||
MockScheduledExecutorService executorService = new MockScheduledExecutorService();
|
||||
Context.CancellableContext cancellableContext = Context.current()
|
||||
.withDeadlineAfter(100, TimeUnit.NANOSECONDS, fakeClock.getScheduledExecutorService());
|
||||
fakeClock.forwardTime(System.nanoTime(), TimeUnit.NANOSECONDS);
|
||||
fakeClock.forwardNanos(100);
|
||||
.withDeadlineAfter(expectedDelay, expectedUnit, executorService);
|
||||
executorService.command.run();
|
||||
|
||||
assertTrue(cancellableContext.isCancelled());
|
||||
assertThat(cancellableContext.cancellationCause(), instanceOf(TimeoutException.class));
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue