Java Code Examples for io.grpc.LoadBalancer.PickResult#withDrop()

The following examples show how to use io.grpc.LoadBalancer.PickResult#withDrop() . 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: ManagedChannelImpl.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
void panic(final Throwable t) {
  if (panicMode) {
    // Preserve the first panic information
    return;
  }
  panicMode = true;
  cancelIdleTimer(/* permanent= */ true);
  shutdownNameResolverAndLoadBalancer(false);
  final class PanicSubchannelPicker extends SubchannelPicker {
    private final PickResult panicPickResult =
        PickResult.withDrop(
            Status.INTERNAL.withDescription("Panic! This is a bug!").withCause(t));

    @Override
    public PickResult pickSubchannel(PickSubchannelArgs args) {
      return panicPickResult;
    }
  }

  updateSubchannelPicker(new PanicSubchannelPicker());
  channelLogger.log(ChannelLogLevel.ERROR, "PANIC! Entering TRANSIENT_FAILURE");
  channelStateManager.gotoState(TRANSIENT_FAILURE);
}
 
Example 2
Source File: GrpcUtilTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTransportFromPickResult_dropPickResult_waitForReady() {
  Status status = Status.UNAVAILABLE;
  PickResult pickResult = PickResult.withDrop(status);
  ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult, true);

  assertNotNull(transport);

  ClientStream stream = transport
      .newStream(TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT);
  ClientStreamListener listener = mock(ClientStreamListener.class);
  stream.start(listener);

  verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class));
}
 
Example 3
Source File: GrpcUtilTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTransportFromPickResult_dropPickResult_failFast() {
  Status status = Status.UNAVAILABLE;
  PickResult pickResult = PickResult.withDrop(status);
  ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult, false);

  assertNotNull(transport);

  ClientStream stream = transport
      .newStream(TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT);
  ClientStreamListener listener = mock(ClientStreamListener.class);
  stream.start(listener);

  verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class));
}
 
Example 4
Source File: LoadBalancerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void pickResult_withDrop() {
  PickResult result = PickResult.withDrop(status);
  assertThat(result.getSubchannel()).isNull();
  assertThat(result.getStatus()).isSameAs(status);
  assertThat(result.getStreamTracerFactory()).isNull();
  assertThat(result.isDrop()).isTrue();
}
 
Example 5
Source File: LoadBalancerTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Test
public void pickResult_equals() {
  PickResult sc1 = PickResult.withSubchannel(subchannel);
  PickResult sc2 = PickResult.withSubchannel(subchannel);
  PickResult sc3 = PickResult.withSubchannel(subchannel, tracerFactory);
  PickResult sc4 = PickResult.withSubchannel(subchannel2);
  PickResult nr = PickResult.withNoResult();
  PickResult error1 = PickResult.withError(status);
  PickResult error2 = PickResult.withError(status2);
  PickResult error3 = PickResult.withError(status2);
  PickResult drop1 = PickResult.withDrop(status);
  PickResult drop2 = PickResult.withDrop(status);
  PickResult drop3 = PickResult.withDrop(status2);

  assertThat(sc1).isNotEqualTo(nr);
  assertThat(sc1).isNotEqualTo(error1);
  assertThat(sc1).isNotEqualTo(drop1);
  assertThat(sc1).isEqualTo(sc2);
  assertThat(sc1).isNotEqualTo(sc3);
  assertThat(sc1).isNotEqualTo(sc4);

  assertThat(error1).isNotEqualTo(error2);
  assertThat(error2).isEqualTo(error3);

  assertThat(drop1).isEqualTo(drop2);
  assertThat(drop1).isNotEqualTo(drop3);

  assertThat(error1.getStatus()).isEqualTo(drop1.getStatus());
  assertThat(error1).isNotEqualTo(drop1);
}
 
Example 6
Source File: LoadBalancerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void pickResult_withDrop() {
  PickResult result = PickResult.withDrop(status);
  assertThat(result.getSubchannel()).isNull();
  assertThat(result.getStatus()).isSameInstanceAs(status);
  assertThat(result.getStreamTracerFactory()).isNull();
  assertThat(result.isDrop()).isTrue();
}
 
Example 7
Source File: LoadBalancerTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void pickResult_equals() {
  PickResult sc1 = PickResult.withSubchannel(subchannel);
  PickResult sc2 = PickResult.withSubchannel(subchannel);
  PickResult sc3 = PickResult.withSubchannel(subchannel, tracerFactory);
  PickResult sc4 = PickResult.withSubchannel(subchannel2);
  PickResult nr = PickResult.withNoResult();
  PickResult error1 = PickResult.withError(status);
  PickResult error2 = PickResult.withError(status2);
  PickResult error3 = PickResult.withError(status2);
  PickResult drop1 = PickResult.withDrop(status);
  PickResult drop2 = PickResult.withDrop(status);
  PickResult drop3 = PickResult.withDrop(status2);

  assertThat(sc1).isNotEqualTo(nr);
  assertThat(sc1).isNotEqualTo(error1);
  assertThat(sc1).isNotEqualTo(drop1);
  assertThat(sc1).isEqualTo(sc2);
  assertThat(sc1).isNotEqualTo(sc3);
  assertThat(sc1).isNotEqualTo(sc4);

  assertThat(error1).isNotEqualTo(error2);
  assertThat(error2).isEqualTo(error3);

  assertThat(drop1).isEqualTo(drop2);
  assertThat(drop1).isNotEqualTo(drop3);

  assertThat(error1.getStatus()).isEqualTo(drop1.getStatus());
  assertThat(error1).isNotEqualTo(drop1);
}
 
Example 8
Source File: ClientLoadCounterTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void tracerWrappingSubchannelPicker_interceptPickResult_invalidPickResultNotIntercepted() {
  final SubchannelPicker picker = mock(SubchannelPicker.class);
  SubchannelPicker streamInstrSubchannelPicker = new TracerWrappingSubchannelPicker() {
    @Override
    protected SubchannelPicker delegate() {
      return picker;
    }

    @Override
    protected Factory wrapTracerFactory(Factory originFactory) {
      // NO-OP
      return originFactory;
    }
  };
  PickResult errorResult = PickResult.withError(Status.UNAVAILABLE.withDescription("Error"));
  PickResult droppedResult = PickResult.withDrop(Status.UNAVAILABLE.withDescription("Dropped"));
  PickResult emptyResult = PickResult.withNoResult();
  when(picker.pickSubchannel(any(PickSubchannelArgs.class)))
      .thenReturn(errorResult, droppedResult, emptyResult);
  PickSubchannelArgs args = mock(PickSubchannelArgs.class);

  PickResult interceptedErrorResult = streamInstrSubchannelPicker.pickSubchannel(args);
  PickResult interceptedDroppedResult = streamInstrSubchannelPicker.pickSubchannel(args);
  PickResult interceptedEmptyResult = streamInstrSubchannelPicker.pickSubchannel(args);
  assertThat(interceptedErrorResult).isSameInstanceAs(errorResult);
  assertThat(interceptedDroppedResult).isSameInstanceAs(droppedResult);
  assertThat(interceptedEmptyResult).isSameInstanceAs(emptyResult);
}
 
Example 9
Source File: ManagedChannelImpl.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
void panic(final Throwable t) {
  if (panicMode) {
    // Preserve the first panic information
    return;
  }
  panicMode = true;
  cancelIdleTimer(/* permanent= */ true);
  shutdownNameResolverAndLoadBalancer(false);
  final class PanicSubchannelPicker extends SubchannelPicker {
    private final PickResult panicPickResult =
        PickResult.withDrop(
            Status.INTERNAL.withDescription("Panic! This is a bug!").withCause(t));

    @Override
    public PickResult pickSubchannel(PickSubchannelArgs args) {
      return panicPickResult;
    }

    @Override
    public String toString() {
      return MoreObjects.toStringHelper(PanicSubchannelPicker.class)
          .add("panicPickResult", panicPickResult)
          .toString();
    }
  }

  updateSubchannelPicker(new PanicSubchannelPicker());
  channelLogger.log(ChannelLogLevel.ERROR, "PANIC! Entering TRANSIENT_FAILURE");
  channelStateManager.gotoState(TRANSIENT_FAILURE);
}
 
Example 10
Source File: GrpcUtilTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTransportFromPickResult_dropPickResult_waitForReady() {
  Status status = Status.UNAVAILABLE;
  PickResult pickResult = PickResult.withDrop(status);
  ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult, true);

  assertNotNull(transport);

  ClientStream stream = transport
      .newStream(TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT);
  ClientStreamListener listener = mock(ClientStreamListener.class);
  stream.start(listener);

  verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class));
}
 
Example 11
Source File: GrpcUtilTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Test
public void getTransportFromPickResult_dropPickResult_failFast() {
  Status status = Status.UNAVAILABLE;
  PickResult pickResult = PickResult.withDrop(status);
  ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult, false);

  assertNotNull(transport);

  ClientStream stream = transport
      .newStream(TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT);
  ClientStreamListener listener = mock(ClientStreamListener.class);
  stream.start(listener);

  verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class));
}