io.grpc.stub.ClientCalls Java Examples

The following examples show how to use io.grpc.stub.ClientCalls. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void afterResponseMaxAge_cacheEntryInvalidated() throws Exception {
  cacheControlDirectives.add("max-age=1");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  assertSame(reply1, reply2);

  // Wait for cache entry to expire
  sleepAtLeast(1001);

  assertNotEquals(
      reply1,
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
  Truth.assertThat(cache.removedKeys).hasSize(1);
  assertEquals(
      new SafeMethodCachingInterceptor.Key(
          GreeterGrpc.getSayHelloMethod().getFullMethodName(), message),
      cache.removedKeys.get(0));
}
 
Example #2
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithNoCacheOptionSkipsCache() {
  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse,
          safeGreeterSayHelloMethod,
          CallOptions.DEFAULT.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true),
          message);
  HelloReply reply3 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  assertSame(reply1, reply3);
}
 
Example #3
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithOnlyIfCachedOption_unavailableIfNotInCache() {
  try {
    ClientCalls.blockingUnaryCall(
        channelToUse,
        safeGreeterSayHelloMethod,
        CallOptions.DEFAULT.withOption(
            SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true),
        message);
    fail("Expected call to fail");
  } catch (StatusRuntimeException sre) {
    assertEquals(Status.UNAVAILABLE.getCode(), sre.getStatus().getCode());
    assertEquals(
        "Unsatisfiable Request (only-if-cached set, but value not in cache)",
        sre.getStatus().getDescription());
  }
}
 
Example #4
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithNoCacheAndOnlyIfCached_fails() {
  try {
    ClientCalls.blockingUnaryCall(
        channelToUse,
        safeGreeterSayHelloMethod,
        CallOptions.DEFAULT
            .withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true)
            .withOption(SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true),
        message);
    fail("Expected call to fail");
  } catch (StatusRuntimeException sre) {
    assertEquals(Status.UNAVAILABLE.getCode(), sre.getStatus().getCode());
    assertEquals(
        "Unsatisfiable Request (no-cache and only-if-cached conflict)",
        sre.getStatus().getDescription());
  }
}
 
Example #5
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void responseNoCacheDirective_notCached() throws Exception {
  cacheControlDirectives.add("no-cache");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #6
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void afterResponseMaxAge_cacheEntryInvalidated() throws Exception {
  cacheControlDirectives.add("max-age=1");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  assertSame(reply1, reply2);

  // Wait for cache entry to expire
  sleepAtLeast(1001);

  assertNotEquals(
      reply1,
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message));
  Truth.assertThat(cache.removedKeys).hasSize(1);
  assertEquals(
      new SafeMethodCachingInterceptor.Key(
          GreeterGrpc.getSayHelloMethod().getFullMethodName(), message),
      cache.removedKeys.get(0));
}
 
Example #7
Source File: AbstractGRPCClient.java    From client-java with Apache License 2.0 6 votes vote down vote up
public <ReqT, RespT> RespT callWithRetry(
    BackOffer backOffer,
    MethodDescriptor<ReqT, RespT> method,
    Supplier<ReqT> requestFactory,
    ErrorHandler<RespT> handler) {
  if (logger.isTraceEnabled()) {
    logger.trace(String.format("Calling %s...", method.getFullMethodName()));
  }
  RetryPolicy.Builder<RespT> builder = new Builder<>(backOffer);
  RespT resp =
      builder
          .create(handler)
          .callWithRetry(
              () -> {
                BlockingStubT stub = getBlockingStub();
                return ClientCalls.blockingUnaryCall(
                    stub.getChannel(), method, stub.getCallOptions(), requestFactory.get());
              },
              method.getFullMethodName());

  if (logger.isTraceEnabled()) {
    logger.trace(String.format("leaving %s...", method.getFullMethodName()));
  }
  return resp;
}
 
Example #8
Source File: HederaCall.java    From hedera-sdk-java with Apache License 2.0 6 votes vote down vote up
public Resp execute(Client client, Duration retryTimeout) throws HederaStatusException, HederaNetworkException, LocalValidationException {
    // Run local validator just before execute
    localValidate();

    // N.B. only QueryBuilder used onPreExecute() so instead it should just override this
    // method instead

    final Backoff.FallibleProducer<Resp, HederaStatusException> tryProduce = () -> {
        try {
            return mapResponse(ClientCalls.blockingUnaryCall(getChannel(client).newCall(getMethod(), CallOptions.DEFAULT), toProto()));
        } catch (StatusRuntimeException e) {
            throw new HederaNetworkException(e);
        }
    };

    return new Backoff(RETRY_DELAY, retryTimeout)
        .tryWhile(this::shouldRetry, tryProduce);
}
 
Example #9
Source File: ConsensusClient.java    From hedera-sdk-java with Apache License 2.0 6 votes vote down vote up
/**
 * Get a blocking iterator which returns messages for the given topic with consensus timestamps
 * between two {@link Instant}s.
 *
 * @param topicId
 * @param startTime the lower bound for timestamps (inclusive), may be in the past or future.
 * @param endTime the upper bound for timestamps (exclusive), may also be in the past or future.
 * @return
 */
public Iterator<ConsensusMessage> getMessages(ConsensusTopicId topicId, Instant startTime, Instant endTime) {
    final ConsensusTopicQuery topicQuery = ConsensusTopicQuery.newBuilder()
        .setTopicID(topicId.toProto())
        .setConsensusStartTime(TimestampHelper.timestampFrom(startTime))
        .setConsensusEndTime(TimestampHelper.timestampFrom(endTime))
        .build();

    final Iterator<ConsensusTopicResponse> iter = ClientCalls.blockingServerStreamingCall(
        channel,
        ConsensusServiceGrpc.getSubscribeTopicMethod(),
        CallOptions.DEFAULT,
        topicQuery);

    return Iterators.transform(iter, message -> new ConsensusMessage(topicId, Objects.requireNonNull(message)));
}
 
Example #10
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void cacheHit_doesNotResetExpiration() throws Exception {
  cacheControlDirectives.add("max-age=1");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  sleepAtLeast(1001);

  HelloReply reply3 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertSame(reply1, reply2);
  assertNotEquals(reply1, reply3);
  Truth.assertThat(cache.internalCache).hasSize(1);
  Truth.assertThat(cache.removedKeys).hasSize(1);
}
 
Example #11
Source File: ClientDynamic.java    From pampas with Apache License 2.0 6 votes vote down vote up
public static <ReqT, RespT> void autoCall() throws Exception {
        DynamicMultiClassLoader loader = DynamicMultiClassLoader.getLoader(toUrl("/home/darrenfu/IdeaProjects/pampas/pampas-grpc/df/open/grpc/hello/grpc-test-229014610914606914.jar"));
        Class grpc = loader.load("df.open.grpc.hello.HelloServiceGrpc");
        Class proto = loader.load("df.open.grpc.hello.HelloServiceProto");
        Method getSayHelloMethod = grpc.getDeclaredMethod("getSayHelloMethod");
        MethodDescriptor<ReqT, RespT> methodDescriptor = (MethodDescriptor) getSayHelloMethod.invoke(grpc);

        ClientCall<ReqT, RespT> call =
                new ForwardingClientCall.SimpleForwardingClientCall(channel.newCall(methodDescriptor, callOption.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS))) {

                    public void start(Listener responseListener, Metadata headers) {
                        System.out.println("start call......");
                        super.start(responseListener, headers);
                    }
                };
//        ClientCalls.asyncUnaryCall(call, (ReqT) req.newInstance(), responseFuture);
        Class<?> reqClz = Class.forName("df.open.grpc.hello.HelloServiceProto$HelloReq", false, loader);
        Constructor<?> constructor = reqClz.getDeclaredConstructor();
        constructor.setAccessible(true);
        System.out.println(constructor.isAccessible());

        RespT respT = ClientCalls.blockingUnaryCall(call, (ReqT) constructor.newInstance());
        System.out.println(respT);
        System.out.println("XXXXXXXxx");

    }
 
Example #12
Source File: ConcurrencyLimitServerInterceptorTest.java    From concurrency-limits with Apache License 2.0 6 votes vote down vote up
@Test
public void releaseOnError() {
    // Setup server
    startServer((req, observer) -> {
        observer.onError(Status.INVALID_ARGUMENT.asRuntimeException());
    });

    try {
        ClientCalls.blockingUnaryCall(channel, METHOD_DESCRIPTOR, CallOptions.DEFAULT, "foo");
        Assert.fail("Should have failed with UNKNOWN error");
    } catch (StatusRuntimeException e) {
        Assert.assertEquals(Status.Code.INVALID_ARGUMENT, e.getStatus().getCode());
    }
    // Verify
    Mockito.verify(limiter, Mockito.times(1)).acquire(Mockito.isA(GrpcServerRequestContext.class));

    verifyCounts(0, 0, 1, 0);
}
 
Example #13
Source File: ConcurrencyLimitServerInterceptorTest.java    From concurrency-limits with Apache License 2.0 6 votes vote down vote up
@Test
public void releaseOnCancellation() {
    // Setup server
    startServer((req, observer) -> {
        Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
        observer.onNext("delayed_response");
        observer.onCompleted();
    });

    ListenableFuture<String> future = ClientCalls.futureUnaryCall(channel.newCall(METHOD_DESCRIPTOR, CallOptions.DEFAULT), "foo");
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    future.cancel(true);

    // Verify
    Mockito.verify(limiter, Mockito.times(1)).acquire(Mockito.isA(GrpcServerRequestContext.class));
    Mockito.verify(listener.getResult().get(), Mockito.times(0)).onIgnore();

    Mockito.verify(listener.getResult().get(), Mockito.timeout(2000).times(1)).onSuccess();

    verifyCounts(0, 0, 1, 0);
}
 
Example #14
Source File: AbstractGRPCClient.java    From client-java with Apache License 2.0 6 votes vote down vote up
protected <ReqT, RespT> void callAsyncWithRetry(
    BackOffer backOffer,
    MethodDescriptor<ReqT, RespT> method,
    Supplier<ReqT> requestFactory,
    StreamObserver<RespT> responseObserver,
    ErrorHandler<RespT> handler) {
  logger.debug(String.format("Calling %s...", method.getFullMethodName()));

  RetryPolicy.Builder<RespT> builder = new Builder<>(backOffer);
  builder
      .create(handler)
      .callWithRetry(
          () -> {
            StubT stub = getAsyncStub();
            ClientCalls.asyncUnaryCall(
                stub.getChannel().newCall(method, stub.getCallOptions()),
                requestFactory.get(),
                responseObserver);
            return null;
          },
          method.getFullMethodName());
  logger.debug(String.format("leaving %s...", method.getFullMethodName()));
}
 
Example #15
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void separateResponseCacheControlDirectives_parsesWithoutError() throws Exception {
  cacheControlDirectives.add("max-age=1");
  cacheControlDirectives.add("no-store , no-cache");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #16
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void responseNoCacheDirective_notCached() throws Exception {
  cacheControlDirectives.add("no-cache");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #17
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithNoCacheAndOnlyIfCached_fails() {
  try {
    ClientCalls.blockingUnaryCall(
        channelToUse,
        safeGreeterSayHelloMethod,
        CallOptions.DEFAULT
            .withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true)
            .withOption(SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true),
        message);
    fail("Expected call to fail");
  } catch (StatusRuntimeException sre) {
    assertEquals(Status.UNAVAILABLE.getCode(), sre.getStatus().getCode());
    assertEquals(
        "Unsatisfiable Request (no-cache and only-if-cached conflict)",
        sre.getStatus().getDescription());
  }
}
 
Example #18
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithOnlyIfCachedOption_unavailableIfNotInCache() {
  try {
    ClientCalls.blockingUnaryCall(
        channelToUse,
        safeGreeterSayHelloMethod,
        CallOptions.DEFAULT.withOption(
            SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true),
        message);
    fail("Expected call to fail");
  } catch (StatusRuntimeException sre) {
    assertEquals(Status.UNAVAILABLE.getCode(), sre.getStatus().getCode());
    assertEquals(
        "Unsatisfiable Request (only-if-cached set, but value not in cache)",
        sre.getStatus().getDescription());
  }
}
 
Example #19
Source File: SafeMethodCachingInterceptorTest.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Test
public void requestWithNoCacheOptionSkipsCache() {
  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse,
          safeGreeterSayHelloMethod,
          CallOptions.DEFAULT.withOption(SafeMethodCachingInterceptor.NO_CACHE_CALL_OPTION, true),
          message);
  HelloReply reply3 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  assertSame(reply1, reply3);
}
 
Example #20
Source File: AbstractGRPCClient.java    From tikv-client-lib-java with Apache License 2.0 6 votes vote down vote up
protected <ReqT, RespT> void callAsyncWithRetry(
    MethodDescriptor<ReqT, RespT> method,
    Supplier<ReqT> requestFactory,
    StreamObserver<RespT> responseObserver,
    ErrorHandler<RespT> handler) {
  logger.debug(String.format("Calling %s...", method.getFullMethodName()));

  RetryPolicy.Builder<RespT> builder = new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  builder.create(handler)
      .callWithRetry(
          () -> {
            StubT stub = getAsyncStub();
            ClientCalls.asyncUnaryCall(
                stub.getChannel().newCall(method, stub.getCallOptions()),
                requestFactory.get(),
                responseObserver);
            return null;
          },
          method.getFullMethodName());
  logger.debug(String.format("leaving %s...", method.getFullMethodName()));
}
 
Example #21
Source File: AbstractGRPCClient.java    From tikv-client-lib-java with Apache License 2.0 6 votes vote down vote up
protected <ReqT, RespT> RespT callWithRetry(MethodDescriptor<ReqT, RespT> method,
                                            Supplier<ReqT> requestFactory,
                                            ErrorHandler<RespT> handler) {
  if (logger.isTraceEnabled()) {
    logger.trace(String.format("Calling %s...", method.getFullMethodName()));
  }
  RetryPolicy.Builder<RespT> builder = new Builder<>(conf.getRetryTimes(), conf.getBackOffClass());
  RespT resp =
      builder.create(handler)
          .callWithRetry(
              () -> {
                BlockingStubT stub = getBlockingStub();
                return ClientCalls.blockingUnaryCall(
                    stub.getChannel(), method, stub.getCallOptions(), requestFactory.get());
              },
              method.getFullMethodName());
  if (logger.isTraceEnabled()) {
    logger.trace(String.format("leaving %s...", method.getFullMethodName()));
  }
  return resp;
}
 
Example #22
Source File: ConcurrencyLimitServerInterceptorTest.java    From concurrency-limits with Apache License 2.0 6 votes vote down vote up
@Test
public void releaseOnDeadlineExceeded() {
    // Setup server
    startServer((req, observer) -> {
        Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
        observer.onNext("delayed_response");
        observer.onCompleted();
    });

    try {
        ClientCalls.blockingUnaryCall(channel.newCall(METHOD_DESCRIPTOR, CallOptions.DEFAULT.withDeadlineAfter(1, TimeUnit.SECONDS)), "foo");
    } catch (StatusRuntimeException e) {
        Assert.assertEquals(Status.Code.DEADLINE_EXCEEDED, e.getStatus().getCode());
    }
    // Verify
    Mockito.verify(limiter, Mockito.times(1)).acquire(Mockito.isA(GrpcServerRequestContext.class));
    Mockito.verify(listener.getResult().get(), Mockito.times(0)).onIgnore();

    Mockito.verify(listener.getResult().get(), Mockito.timeout(2000).times(1)).onSuccess();

    verifyCounts(0, 0, 1, 0);
}
 
Example #23
Source File: ConcurrencyLimitServerInterceptorTest.java    From concurrency-limits with Apache License 2.0 6 votes vote down vote up
@Test
public void releaseOnUncaughtException() throws IOException {
    // Setup server
    startServer((req, observer) -> {
        throw new RuntimeException("failure");
    });

    try {
        ClientCalls.blockingUnaryCall(channel, METHOD_DESCRIPTOR, CallOptions.DEFAULT, "foo");
        Assert.fail("Should have failed with UNKNOWN error");
    } catch (StatusRuntimeException e) {
        Assert.assertEquals(Status.Code.UNKNOWN, e.getStatus().getCode());
    }
    // Verify
    Mockito.verify(limiter, Mockito.times(1)).acquire(Mockito.isA(GrpcServerRequestContext.class));
    Mockito.verify(listener.getResult().get(), Mockito.timeout(1000).times(1)).onIgnore();

    verifyCounts(0, 1, 0, 0);
}
 
Example #24
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void responseNoTransformDirective_notCached() throws Exception {
  cacheControlDirectives.add("no-transform");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #25
Source File: GrpcClient.java    From etcd-java with Apache License 2.0 5 votes vote down vote up
private void refreshBackingStream() {
    if (finished) {
        return;
    }
    CallOptions callOpts = getCallOptions();
    sentCallOptions = callOpts;
    callOpts = callOpts.withExecutor(responseExecutor);
    initialReqStream = ClientCalls.asyncBidiStreamingCall(
            channel.newCall(method, callOpts), respWrapper);
}
 
Example #26
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void responseNoCache_caseInsensitive() throws Exception {
  cacheControlDirectives.add("No-CaCHe");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #27
Source File: LoadClient.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  long now;
  while (!shutdown) {
    now = System.nanoTime();
    ClientCalls.blockingUnaryCall(channel, LoadServer.GENERIC_UNARY_METHOD,
        CallOptions.DEFAULT,
        genericRequest.slice());
    delay(System.nanoTime() - now);
  }
}
 
Example #28
Source File: DynamicClient.java    From karate-grpc with MIT License 5 votes vote down vote up
private ListenableFuture<Void> callServerStreaming(
        DynamicMessage request,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    ClientCalls.asyncServerStreamingCall(
            createCall(callOptions),
            request,
            ComponentObserver.of(responseObserver, doneObserver));
    return doneObserver.getCompletionFuture();
}
 
Example #29
Source File: DynamicClient.java    From karate-grpc with MIT License 5 votes vote down vote up
private ListenableFuture<Void> callUnary(
        DynamicMessage request,
        StreamObserver<DynamicMessage> responseObserver,
        CallOptions callOptions) {
    DoneObserver<DynamicMessage> doneObserver = new DoneObserver<>();
    ClientCalls.asyncUnaryCall(
            createCall(callOptions),
            request,
            ComponentObserver.of(responseObserver, doneObserver));
    return doneObserver.getCompletionFuture();
}
 
Example #30
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void requestWithOnlyIfCachedOption_usesCache() {
  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse,
          safeGreeterSayHelloMethod,
          CallOptions.DEFAULT.withOption(
              SafeMethodCachingInterceptor.ONLY_IF_CACHED_CALL_OPTION, true),
          message);

  assertSame(reply1, reply2);
}