本文整理汇总了Java中io.grpc.CallOptions.DEFAULT属性的典型用法代码示例。如果您正苦于以下问题:Java CallOptions.DEFAULT属性的具体用法?Java CallOptions.DEFAULT怎么用?Java CallOptions.DEFAULT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类io.grpc.CallOptions
的用法示例。
在下文中一共展示了CallOptions.DEFAULT属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: simpleValueTransfers
@Test
public void simpleValueTransfers() {
CallOptions baseOptions = CallOptions.DEFAULT;
CallOptions defaultOptions = CallOptions.DEFAULT.withAuthority("FOO");
DefaultCallOptionsClientInterceptor interceptor = new DefaultCallOptionsClientInterceptor(defaultOptions);
CallOptions patchedOptions = interceptor.patchOptions(baseOptions);
assertThat(patchedOptions.getAuthority()).isEqualTo("FOO");
}
示例2: callOptions
private static CallOptions callOptions(CallConfiguration callConfig) {
CallOptions result = CallOptions.DEFAULT;
if (callConfig.getDeadlineMs() > 0) {
result = result.withDeadlineAfter(callConfig.getDeadlineMs(), TimeUnit.MILLISECONDS);
}
return result;
}
示例3: setUp
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(factory);
clientStream =
new CronetClientStream(
"https://www.google.com:443",
"cronet",
executor,
metadata,
transport,
callback,
lock,
100,
false /* alwaysUsePut */,
method,
StatsTraceContext.NOOP,
CallOptions.DEFAULT,
transportTracer);
callback.setStream(clientStream);
when(factory.newBidirectionalStreamBuilder(
any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class)))
.thenReturn(builder);
when(builder.build()).thenReturn(cronetStream);
clientStream.start(clientListener);
}
示例4: idempotentMethod_usesHttpPut
@Test
public void idempotentMethod_usesHttpPut() {
SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(factory);
MethodDescriptor<?, ?> idempotentMethod = method.toBuilder().setIdempotent(true).build();
CronetClientStream stream =
new CronetClientStream(
"https://www.google.com:443",
"cronet",
executor,
metadata,
transport,
callback,
lock,
100,
false /* alwaysUsePut */,
idempotentMethod,
StatsTraceContext.NOOP,
CallOptions.DEFAULT,
transportTracer);
callback.setStream(stream);
ExperimentalBidirectionalStream.Builder builder =
mock(ExperimentalBidirectionalStream.Builder.class);
when(factory.newBidirectionalStreamBuilder(
any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class)))
.thenReturn(builder);
when(builder.build()).thenReturn(cronetStream);
stream.start(clientListener);
verify(builder).setHttpMethod("PUT");
}
示例5: alwaysUsePutOption_usesHttpPut
@Test
public void alwaysUsePutOption_usesHttpPut() {
SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(factory);
CronetClientStream stream =
new CronetClientStream(
"https://www.google.com:443",
"cronet",
executor,
metadata,
transport,
callback,
lock,
100,
true /* alwaysUsePut */,
method,
StatsTraceContext.NOOP,
CallOptions.DEFAULT,
transportTracer);
callback.setStream(stream);
ExperimentalBidirectionalStream.Builder builder =
mock(ExperimentalBidirectionalStream.Builder.class);
when(factory.newBidirectionalStreamBuilder(
any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class)))
.thenReturn(builder);
when(builder.build()).thenReturn(cronetStream);
stream.start(clientListener);
verify(builder).setHttpMethod("PUT");
}
示例6: subtestFailRpcFromBalancer
private void subtestFailRpcFromBalancer(boolean waitForReady, boolean drop, boolean shouldFail) {
createChannel(new FakeNameResolverFactory(true), NO_INTERCEPTOR);
// This call will be buffered by the channel, thus involve delayed transport
CallOptions callOptions = CallOptions.DEFAULT;
if (waitForReady) {
callOptions = callOptions.withWaitForReady();
} else {
callOptions = callOptions.withoutWaitForReady();
}
ClientCall<String, Integer> call1 = channel.newCall(method, callOptions);
call1.start(mockCallListener, new Metadata());
SubchannelPicker picker = mock(SubchannelPicker.class);
Status status = Status.UNAVAILABLE.withDescription("for test");
when(picker.pickSubchannel(any(PickSubchannelArgs.class)))
.thenReturn(drop ? PickResult.withDrop(status) : PickResult.withError(status));
helper.updateBalancingState(READY, picker);
executor.runDueTasks();
if (shouldFail) {
verify(mockCallListener).onClose(same(status), any(Metadata.class));
} else {
verifyZeroInteractions(mockCallListener);
}
// This call doesn't involve delayed transport
ClientCall<String, Integer> call2 = channel.newCall(method, callOptions);
call2.start(mockCallListener2, new Metadata());
executor.runDueTasks();
if (shouldFail) {
verify(mockCallListener2).onClose(same(status), any(Metadata.class));
} else {
verifyZeroInteractions(mockCallListener2);
}
}
示例7: getUnaryRequest
@Test
public void getUnaryRequest() {
StreamBuilderFactory getFactory = mock(StreamBuilderFactory.class);
MethodDescriptor<?, ?> getMethod =
MethodDescriptor.<Void, Void>newBuilder()
.setType(MethodDescriptor.MethodType.UNARY)
.setFullMethodName("/service/method")
.setIdempotent(true)
.setSafe(true)
.setRequestMarshaller(marshaller)
.setResponseMarshaller(marshaller)
.build();
SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(getFactory);
CronetClientStream stream =
new CronetClientStream(
"https://www.google.com/service/method",
"cronet",
executor,
metadata,
transport,
callback,
lock,
100,
false /* alwaysUsePut */,
getMethod,
StatsTraceContext.NOOP,
CallOptions.DEFAULT,
transportTracer);
callback.setStream(stream);
ExperimentalBidirectionalStream.Builder getBuilder =
mock(ExperimentalBidirectionalStream.Builder.class);
when(getFactory.newBidirectionalStreamBuilder(
any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class)))
.thenReturn(getBuilder);
when(getBuilder.build()).thenReturn(cronetStream);
stream.start(clientListener);
// We will not create BidirectionalStream until we have the full request.
verify(getFactory, times(0))
.newBidirectionalStreamBuilder(
isA(String.class), isA(BidirectionalStream.Callback.class), isA(Executor.class));
byte[] msg = "request".getBytes(Charset.forName("UTF-8"));
stream.writeMessage(new ByteArrayInputStream(msg));
// We still haven't built the stream or sent anything.
verify(cronetStream, times(0)).write(isA(ByteBuffer.class), isA(Boolean.class));
verify(getFactory, times(0))
.newBidirectionalStreamBuilder(
isA(String.class), isA(BidirectionalStream.Callback.class), isA(Executor.class));
// halfClose will trigger sending.
stream.halfClose();
// Stream should be built with request payload in the header.
ArgumentCaptor<String> urlCaptor = ArgumentCaptor.forClass(String.class);
verify(getFactory)
.newBidirectionalStreamBuilder(
urlCaptor.capture(), isA(BidirectionalStream.Callback.class), isA(Executor.class));
verify(getBuilder).setHttpMethod("GET");
assertEquals(
"https://www.google.com/service/method?" + BaseEncoding.base64().encode(msg),
urlCaptor.getValue());
}
示例8: reservedHeadersStripped
@Test
public void reservedHeadersStripped() {
String userAgent = "cronet";
Metadata headers = new Metadata();
Metadata.Key<String> userKey = Metadata.Key.of("user-key", Metadata.ASCII_STRING_MARSHALLER);
headers.put(GrpcUtil.CONTENT_TYPE_KEY, "to-be-removed");
headers.put(GrpcUtil.USER_AGENT_KEY, "to-be-removed");
headers.put(GrpcUtil.TE_HEADER, "to-be-removed");
headers.put(userKey, "user-value");
SetStreamFactoryRunnable callback = new SetStreamFactoryRunnable(factory);
CronetClientStream stream =
new CronetClientStream(
"https://www.google.com:443",
userAgent,
executor,
headers,
transport,
callback,
lock,
100,
false /* alwaysUsePut */,
method,
StatsTraceContext.NOOP,
CallOptions.DEFAULT,
transportTracer);
callback.setStream(stream);
ExperimentalBidirectionalStream.Builder builder =
mock(ExperimentalBidirectionalStream.Builder.class);
when(factory.newBidirectionalStreamBuilder(
any(String.class), any(BidirectionalStream.Callback.class), any(Executor.class)))
.thenReturn(builder);
when(builder.build()).thenReturn(cronetStream);
stream.start(clientListener);
verify(builder, times(4)).addHeader(any(String.class), any(String.class));
verify(builder).addHeader(GrpcUtil.USER_AGENT_KEY.name(), userAgent);
verify(builder).addHeader(GrpcUtil.CONTENT_TYPE_KEY.name(), GrpcUtil.CONTENT_TYPE_GRPC);
verify(builder).addHeader("te", GrpcUtil.TE_TRAILERS);
verify(builder).addHeader(userKey.name(), "user-value");
}
示例9: doInBackground
@Override
protected String doInBackground(Object... params) {
String host = (String) params[0];
String message = (String) params[1];
String portStr = (String) params[2];
boolean useGet = (boolean) params[3];
boolean noCache = (boolean) params[4];
boolean onlyIfCached = (boolean) params[5];
int port = TextUtils.isEmpty(portStr) ? 0 : Integer.valueOf(portStr);
try {
channel = ManagedChannelBuilder.forAddress(host, port).usePlaintext(true).build();
Channel channelToUse =
ClientInterceptors.intercept(
channel, SafeMethodCachingInterceptor.newSafeMethodCachingInterceptor(cache));
HelloRequest request = HelloRequest.newBuilder().setName(message).build();
HelloReply reply;
if (useGet) {
MethodDescriptor<HelloRequest, HelloReply> safeCacheableUnaryCallMethod =
GreeterGrpc.getSayHelloMethod().toBuilder().setSafe(true).build();
CallOptions callOptions = CallOptions.DEFAULT;
if (noCache) {
callOptions =
callOptions.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true);
}
if (onlyIfCached) {
callOptions =
callOptions.withOption(
SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true);
}
reply =
ClientCalls.blockingUnaryCall(
channelToUse, safeCacheableUnaryCallMethod, callOptions, request);
} else {
GreeterGrpc.GreeterBlockingStub stub = GreeterGrpc.newBlockingStub(channelToUse);
reply = stub.sayHello(request);
}
return reply.getMessage();
} catch (Exception e) {
Log.e(TAG, "RPC failed", e);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.flush();
return String.format("Failed... : %n%s", sw);
}
}
示例10: channelMustNotBeNull2
@Test(expected = NullPointerException.class)
public void channelMustNotBeNull2() {
new NoopStub(null, CallOptions.DEFAULT);
}
示例11: AbstractStub
/**
* Constructor for use by subclasses, with the default {@code CallOptions}.
*
* @since 1.0.0
* @param channel the channel that this stub will use to do communications
*/
protected AbstractStub(Channel channel) {
this(channel, CallOptions.DEFAULT);
}