当前位置: 首页>>代码示例>>Java>>正文


Java CallOptions.DEFAULT属性代码示例

本文整理汇总了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");
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:11,代码来源:DefaultCallOptionsClientInterceptorTest.java

示例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;
}
 
开发者ID:grpc-ecosystem,项目名称:polyglot,代码行数:7,代码来源:ServiceCall.java

示例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);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:27,代码来源:CronetClientStreamTest.java

示例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");
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:30,代码来源:CronetClientStreamTest.java

示例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");
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:29,代码来源:CronetClientStreamTest.java

示例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);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:38,代码来源:ManagedChannelImplTest.java

示例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());
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:63,代码来源:CronetClientStreamTest.java

示例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");
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:41,代码来源:CronetClientStreamTest.java

示例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);
  }
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:46,代码来源:ClientCacheExampleActivity.java

示例10: channelMustNotBeNull2

@Test(expected = NullPointerException.class)
public void channelMustNotBeNull2() {
  new NoopStub(null, CallOptions.DEFAULT);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:4,代码来源:AbstractStubTest.java

示例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);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:9,代码来源:AbstractStub.java


注:本文中的io.grpc.CallOptions.DEFAULT属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。