Java Code Examples for io.grpc.LoadBalancer.PickResult#withNoResult()
The following examples show how to use
io.grpc.LoadBalancer.PickResult#withNoResult() .
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: DelayedClientTransportTest.java From grpc-java with Apache License 2.0 | 6 votes |
@Test public void newStream_racesWithReprocessIdleMode() throws Exception { SubchannelPicker picker = new SubchannelPicker() { @Override public PickResult pickSubchannel(PickSubchannelArgs args) { // Assume entering idle mode raced with the pick delayedTransport.reprocess(null); // Act like IDLE LB return PickResult.withNoResult(); } }; // Because there is no pending stream yet, it will do nothing but save the picker. delayedTransport.reprocess(picker); ClientStream stream = delayedTransport.newStream(method, headers, callOptions); stream.start(streamListener); assertTrue(delayedTransport.hasPendingStreams()); verify(transportListener).transportInUse(true); }
Example 2
Source File: LoadBalancerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void pickResult_withNoResult() { PickResult result = PickResult.withNoResult(); assertThat(result.getSubchannel()).isNull(); assertThat(result.getStatus()).isSameAs(Status.OK); assertThat(result.getStreamTracerFactory()).isNull(); assertThat(result.isDrop()).isFalse(); }
Example 3
Source File: LoadBalancerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@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 4
Source File: GrpcRoutePicker.java From saluki with Apache License 2.0 | 5 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { Map<String, Object> affinity = args.getCallOptions().getOption(GrpcCallOptions.CALLOPTIONS_CUSTOME_KEY); GrpcURL refUrl = (GrpcURL) affinity.get(GrpcCallOptions.GRPC_REF_URL); if (size > 0) { Subchannel subchannel = nextSubchannel(refUrl); affinity.put(GrpcCallOptions.GRPC_NAMERESOVER_ATTRIBUTES, nameResovleCache); return PickResult.withSubchannel(subchannel); } if (status != null) { return PickResult.withError(status); } return PickResult.withNoResult(); }
Example 5
Source File: GrpclbState.java From grpc-java with Apache License 2.0 | 5 votes |
@Override public PickResult picked(Metadata headers) { if (connectionRequested.compareAndSet(false, true)) { syncContext.execute(new Runnable() { @Override public void run() { subchannel.requestConnection(); } }); } return PickResult.withNoResult(); }
Example 6
Source File: LoadBalancerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void pickResult_withNoResult() { PickResult result = PickResult.withNoResult(); assertThat(result.getSubchannel()).isNull(); assertThat(result.getStatus()).isSameInstanceAs(Status.OK); assertThat(result.getStreamTracerFactory()).isNull(); assertThat(result.isDrop()).isFalse(); }
Example 7
Source File: LoadBalancerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@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 |
@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: CachingRlsLbClient.java From grpc-java with Apache License 2.0 | 5 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { String[] methodName = args.getMethodDescriptor().getFullMethodName().split("/", 2); RouteLookupRequest request = requestFactory.create(methodName[0], methodName[1], args.getHeaders()); final CachedRouteLookupResponse response = CachingRlsLbClient.this.get(request); PickSubchannelArgs rlsAppliedArgs = getApplyRlsHeader(args, response); if (response.hasData()) { ChildPolicyWrapper childPolicyWrapper = response.getChildPolicyWrapper(); ConnectivityState connectivityState = childPolicyWrapper.getConnectivityStateInfo().getState(); switch (connectivityState) { case IDLE: case CONNECTING: return PickResult.withNoResult(); case READY: return childPolicyWrapper.getPicker().pickSubchannel(rlsAppliedArgs); case TRANSIENT_FAILURE: case SHUTDOWN: default: return useFallback(rlsAppliedArgs); } } else if (response.hasError()) { return useFallback(rlsAppliedArgs); } else { return PickResult.withNoResult(); } }
Example 10
Source File: CachingRlsLbClient.java From grpc-java with Apache License 2.0 | 5 votes |
/** Uses Subchannel connected to default target. */ private PickResult useFallback(PickSubchannelArgs args) { String defaultTarget = lbPolicyConfig.getRouteLookupConfig().getDefaultTarget(); if (fallbackChildPolicyWrapper == null || !fallbackChildPolicyWrapper.getTarget().equals(defaultTarget)) { // TODO(creamsoup) wait until lb is ready startFallbackChildPolicy(); } switch (fallbackChildPolicyWrapper.getConnectivityStateInfo().getState()) { case IDLE: // fall through case CONNECTING: return PickResult.withNoResult(); case TRANSIENT_FAILURE: // fall through case SHUTDOWN: return PickResult .withError(fallbackChildPolicyWrapper.getConnectivityStateInfo().getStatus()); case READY: SubchannelPicker picker = fallbackChildPolicyWrapper.getPicker(); if (picker == null) { return PickResult.withNoResult(); } return picker.pickSubchannel(args); default: throw new AssertionError(); } }
Example 11
Source File: GrpclbState.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public PickResult picked(Metadata headers) { return PickResult.withNoResult(); }
Example 12
Source File: AutoConfiguredLoadBalancerFactory.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { return PickResult.withNoResult(); }
Example 13
Source File: RoundRobinLoadBalancer.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { return status.isOk() ? PickResult.withNoResult() : PickResult.withError(status); }
Example 14
Source File: XdsSubchannelPickers.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { return PickResult.withNoResult(); }
Example 15
Source File: AutoConfiguredLoadBalancerFactory.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public PickResult pickSubchannel(PickSubchannelArgs args) { return PickResult.withNoResult(); }