@Override public void onCompleted() { if (cancelled) { throw Status.CANCELLED.asRuntimeException(); } else { call.close(Status.OK, new Metadata()); } }
@Benchmark public void inject_both_no_tags() { Metadata carrier = new Metadata(); bothInjector.inject(context, carrier); }
@Benchmark public void inject_b3() { Metadata carrier = new Metadata(); b3Injector.inject(context, carrier); }
@Benchmark public void inject_both() { Metadata carrier = new Metadata(); bothInjector.inject(contextWithTags, carrier); }
@Override public void onNext(RespT response) { if (cancelled) { throw Status.CANCELLED.asRuntimeException(); } if (!sentHeaders) { call.sendHeaders(new Metadata()); sentHeaders = true; } //TODO send header from here.. call.sendMessage(response); }
Metadata newMetadata(String resourceTokenTemplate, String defaultResourceToken) { Metadata metadata = new Metadata(); for (Map.Entry<Metadata.Key<String>, String> header : headers.entrySet()) { metadata.put(header.getKey(), header.getValue()); } metadata.put( Key.of(resourceHeaderKey, Metadata.ASCII_STRING_MARSHALLER), getResourceHeaderValue(resourceTokenTemplate, defaultResourceToken)); return metadata; }
@Override public void onError(Throwable t) { Metadata metadata = Status.trailersFromThrowable(t); if (metadata == null) { metadata = new Metadata(); } if (t instanceof MotanBizException) { call.close(Status.INTERNAL.withDescription(t.getMessage()).withCause(t), metadata); } else { call.close(Status.UNAVAILABLE.withDescription(t.getMessage()).withCause(t), metadata); } }
@Test public void notReadyAfterClose() { assertThat(call.isReady()).isTrue(); call.close(Status.OK, new Metadata()); await().untilAsserted(() -> assertThat(call.isReady()).isFalse()); }
Metadata trailers = new Metadata();
@Test public void messageReadAfterClose_byteBuf() { call.close(Status.ABORTED, new Metadata()); // messageRead is always called from the event loop. eventLoop.get().submit(() -> { call.messageRead(new ByteBufOrStream(GrpcTestUtil.requestByteBuf())); verify(listener, never()).onMessage(any()); }).syncUninterruptibly(); }
serverCall.close(FLOW_CONTROL_BLOCK, new Metadata()); return new ServerCall.Listener<ReqT>() {}; } finally {
Metadata metadata = new Metadata(); metadata.put(STATUS_DETAILS_KEY, DebugInfo.newBuilder()
@Test public void messageReadAfterClose_stream() { call.close(Status.ABORTED, new Metadata()); // messageRead is always called from the event loop. eventLoop.get().submit(() -> { call.messageRead(new ByteBufOrStream(new ByteBufInputStream(GrpcTestUtil.requestByteBuf(), true))); verify(listener, never()).onMessage(any()); }).syncUninterruptibly(); }
public Driver(Builder builder) { this.segments = builder.segments; this.runtime = builder.runtimeSeconds; this.latencyAccumulator = builder.latencyAccumulator; Metadata metadata = new Metadata(); metadata.put(ID_HEADER, builder.id); this.channel = ClientInterceptors.intercept(NettyChannelBuilder.forTarget("localhost:" + builder.port) .usePlaintext(true) .build(), MetadataUtils.newAttachHeadersInterceptor(metadata)); }
@Test public void abortWithoutDuration() { Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); Status status = Status.fromCodeValue(Status.Code.ABORTED.value()); Metadata trailers = new Metadata(); trailers.put(key, RetryInfo.getDefaultInstance()); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers)); assertThat(e).isInstanceOf(AbortedException.class); assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L); } }
@After public void tearDown() { // HttpStreamReader must be invoked from an event loop. eventLoop.get().submit(() -> call.messageReader().cancel()).syncUninterruptibly(); if (!call.isCloseCalled()) { call.close(Status.OK, new Metadata()); } }
@Test public void abortWithRetryInfo() { Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); Status status = Status.fromCodeValue(Status.Code.ABORTED.value()); Metadata trailers = new Metadata(); RetryInfo retryInfo = RetryInfo.newBuilder() .setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L)) .build(); trailers.put(key, retryInfo); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers)); assertThat(e).isInstanceOf(AbortedException.class); assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(1001L); }
@Test public void resourceExhaustedWithBackoff() { Status status = Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()) .withDescription("Memory pushback"); Metadata trailers = new Metadata(); Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); RetryInfo retryInfo = RetryInfo.newBuilder() .setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L)) .build(); trailers.put(key, retryInfo); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers)); assertThat(e.isRetryable()).isTrue(); assertThat(e.getRetryDelayInMillis()).isEqualTo(1001); }
/** * Close the call with {@link Status#PERMISSION_DENIED}. * * @param call The call to close. * @param aex The exception that was the cause. */ protected void closeCallAccessDenied(final ServerCall<?, ?> call, final AccessDeniedException aex) { call.close(Status.PERMISSION_DENIED.withCause(aex).withDescription(ACCESS_DENIED_DESCRIPTION), new Metadata()); }
/** * Close the call with {@link Status#UNAUTHENTICATED}. * * @param call The call to close. * @param aex The exception that was the cause. */ protected void closeCallUnauthenticated(final ServerCall<?, ?> call, final AuthenticationException aex) { call.close(Status.UNAUTHENTICATED.withCause(aex).withDescription(UNAUTHENTICATED_DESCRIPTION), new Metadata()); }