mirror of https://github.com/grpc/grpc-java.git
binder: Use Channel-based blockingUnaryCall()
The Channel-based overload can change the CallOptions to use ThreadlessExecutor, so avoids using extra threads.
This commit is contained in:
parent
0005029328
commit
22366891de
|
|
@ -31,6 +31,7 @@ import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
|
import io.grpc.Channel;
|
||||||
import io.grpc.ClientCall;
|
import io.grpc.ClientCall;
|
||||||
import io.grpc.ClientInterceptors;
|
import io.grpc.ClientInterceptors;
|
||||||
import io.grpc.ConnectivityState;
|
import io.grpc.ConnectivityState;
|
||||||
|
|
@ -234,18 +235,17 @@ public final class BinderChannelSmokeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("GrpcUseClientCallBasedBlockingMethods") //TODO(zivy): fix error prone
|
|
||||||
public void testUncaughtServerException() throws Exception {
|
public void testUncaughtServerException() throws Exception {
|
||||||
// Use a poison parcelable to cause an unexpected Exception in the server's onTransact().
|
// Use a poison parcelable to cause an unexpected Exception in the server's onTransact().
|
||||||
PoisonParcelable bad = new PoisonParcelable();
|
PoisonParcelable bad = new PoisonParcelable();
|
||||||
Metadata extraHeadersToSend = new Metadata();
|
Metadata extraHeadersToSend = new Metadata();
|
||||||
extraHeadersToSend.put(POISON_KEY, bad);
|
extraHeadersToSend.put(POISON_KEY, bad);
|
||||||
ClientCall<String, String> call =
|
Channel interceptedChannel =
|
||||||
ClientInterceptors.intercept(channel,
|
ClientInterceptors.intercept(channel,
|
||||||
MetadataUtils.newAttachHeadersInterceptor(extraHeadersToSend))
|
MetadataUtils.newAttachHeadersInterceptor(extraHeadersToSend));
|
||||||
.newCall(method, CallOptions.DEFAULT.withDeadlineAfter(5, SECONDS));
|
CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(5, SECONDS);
|
||||||
try {
|
try {
|
||||||
ClientCalls.blockingUnaryCall(call, "hello");
|
ClientCalls.blockingUnaryCall(interceptedChannel, method, callOptions, "hello");
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (StatusRuntimeException e) {
|
} catch (StatusRuntimeException e) {
|
||||||
// We don't care how *our* RPC failed, but make sure we didn't have to rely on the deadline.
|
// We don't care how *our* RPC failed, but make sure we didn't have to rely on the deadline.
|
||||||
|
|
@ -255,14 +255,12 @@ public final class BinderChannelSmokeTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("GrpcUseClientCallBasedBlockingMethods") //TODO(zivy): fix error prone
|
|
||||||
public void testUncaughtClientException() throws Exception {
|
public void testUncaughtClientException() throws Exception {
|
||||||
// Use a poison parcelable to cause an unexpected Exception in the client's onTransact().
|
// Use a poison parcelable to cause an unexpected Exception in the client's onTransact().
|
||||||
parcelableForResponseHeaders = new PoisonParcelable();
|
parcelableForResponseHeaders = new PoisonParcelable();
|
||||||
ClientCall<String, String> call = channel
|
CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(5, SECONDS);
|
||||||
.newCall(method, CallOptions.DEFAULT.withDeadlineAfter(5, SECONDS));
|
|
||||||
try {
|
try {
|
||||||
ClientCalls.blockingUnaryCall(call, "hello");
|
ClientCalls.blockingUnaryCall(channel, method, callOptions, "hello");
|
||||||
Assert.fail();
|
Assert.fail();
|
||||||
} catch (StatusRuntimeException e) {
|
} catch (StatusRuntimeException e) {
|
||||||
// We don't care *how* our RPC failed, but make sure we didn't have to rely on the deadline.
|
// We don't care *how* our RPC failed, but make sure we didn't have to rely on the deadline.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue