Java Code Examples for io.grpc.LoadBalancer.Subchannel#asChannel()
The following examples show how to use
io.grpc.LoadBalancer.Subchannel#asChannel() .
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: ManagedChannelImplTest.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Test public void subchannelChannel_failWhenNotReady() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY); Channel sChannel = subchannel.asChannel(); Metadata headers = new Metadata(); subchannel.requestConnection(); verify(mockTransportFactory) .newClientTransport(any(SocketAddress.class), any(ClientTransportOptions.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; assertEquals(0, balancerRpcExecutor.numPendingTasks()); // Subchannel is still CONNECTING, but not READY yet ClientCall<String, Integer> call = sChannel.newCall(method, CallOptions.DEFAULT); call.start(mockCallListener, headers); verify(mockTransport, never()).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); verifyZeroInteractions(mockCallListener); assertEquals(1, balancerRpcExecutor.runDueTasks()); verify(mockCallListener).onClose( same(SubchannelChannel.NOT_READY_ERROR), any(Metadata.class)); }
Example 2
Source File: ManagedChannelImplTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void subchannelChannel_normalUsage() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY); verify(balancerRpcExecutorPool, never()).getObject(); Channel sChannel = subchannel.asChannel(); verify(balancerRpcExecutorPool).getObject(); Metadata headers = new Metadata(); CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(5, TimeUnit.SECONDS); // Subchannel must be READY when creating the RPC. subchannel.requestConnection(); verify(mockTransportFactory) .newClientTransport(any(SocketAddress.class), any(ClientTransportOptions.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; ManagedClientTransport.Listener transportListener = transportInfo.listener; transportListener.transportReady(); ClientCall<String, Integer> call = sChannel.newCall(method, callOptions); call.start(mockCallListener, headers); verify(mockTransport).newStream(same(method), same(headers), callOptionsCaptor.capture()); CallOptions capturedCallOption = callOptionsCaptor.getValue(); assertThat(capturedCallOption.getDeadline()).isSameAs(callOptions.getDeadline()); assertThat(capturedCallOption.getOption(GrpcUtil.CALL_OPTIONS_RPC_OWNED_BY_BALANCER)).isTrue(); }
Example 3
Source File: ManagedChannelImplTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Test public void subchannelChannel_failWaitForReady() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY); Channel sChannel = subchannel.asChannel(); Metadata headers = new Metadata(); // Subchannel must be READY when creating the RPC. subchannel.requestConnection(); verify(mockTransportFactory) .newClientTransport(any(SocketAddress.class), any(ClientTransportOptions.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; ManagedClientTransport.Listener transportListener = transportInfo.listener; transportListener.transportReady(); assertEquals(0, balancerRpcExecutor.numPendingTasks()); // Wait-for-ready RPC is not allowed ClientCall<String, Integer> call = sChannel.newCall(method, CallOptions.DEFAULT.withWaitForReady()); call.start(mockCallListener, headers); verify(mockTransport, never()).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); verifyZeroInteractions(mockCallListener); assertEquals(1, balancerRpcExecutor.runDueTasks()); verify(mockCallListener).onClose( same(SubchannelChannel.WAIT_FOR_READY_ERROR), any(Metadata.class)); }
Example 4
Source File: ManagedChannelImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void subchannelChannel_normalUsage() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY, subchannelStateListener); verify(balancerRpcExecutorPool, never()).getObject(); Channel sChannel = subchannel.asChannel(); verify(balancerRpcExecutorPool).getObject(); Metadata headers = new Metadata(); CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(5, TimeUnit.SECONDS); // Subchannel must be READY when creating the RPC. requestConnectionSafely(helper, subchannel); verify(mockTransportFactory) .newClientTransport( any(SocketAddress.class), any(ClientTransportOptions.class), any(ChannelLogger.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; ManagedClientTransport.Listener transportListener = transportInfo.listener; transportListener.transportReady(); ClientCall<String, Integer> call = sChannel.newCall(method, callOptions); call.start(mockCallListener, headers); verify(mockTransport).newStream(same(method), same(headers), callOptionsCaptor.capture()); CallOptions capturedCallOption = callOptionsCaptor.getValue(); assertThat(capturedCallOption.getDeadline()).isSameInstanceAs(callOptions.getDeadline()); assertThat(capturedCallOption.getOption(GrpcUtil.CALL_OPTIONS_RPC_OWNED_BY_BALANCER)).isTrue(); }
Example 5
Source File: ManagedChannelImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void subchannelChannel_failWhenNotReady() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY, subchannelStateListener); Channel sChannel = subchannel.asChannel(); Metadata headers = new Metadata(); requestConnectionSafely(helper, subchannel); verify(mockTransportFactory) .newClientTransport( any(SocketAddress.class), any(ClientTransportOptions.class), any(ChannelLogger.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; assertEquals(0, balancerRpcExecutor.numPendingTasks()); // Subchannel is still CONNECTING, but not READY yet ClientCall<String, Integer> call = sChannel.newCall(method, CallOptions.DEFAULT); call.start(mockCallListener, headers); verify(mockTransport, never()).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); verifyZeroInteractions(mockCallListener); assertEquals(1, balancerRpcExecutor.runDueTasks()); verify(mockCallListener).onClose( same(SubchannelChannel.NOT_READY_ERROR), any(Metadata.class)); }
Example 6
Source File: ManagedChannelImplTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Test public void subchannelChannel_failWaitForReady() { createChannel(); Subchannel subchannel = createSubchannelSafely(helper, addressGroup, Attributes.EMPTY, subchannelStateListener); Channel sChannel = subchannel.asChannel(); Metadata headers = new Metadata(); // Subchannel must be READY when creating the RPC. requestConnectionSafely(helper, subchannel); verify(mockTransportFactory) .newClientTransport( any(SocketAddress.class), any(ClientTransportOptions.class), any(ChannelLogger.class)); MockClientTransportInfo transportInfo = transports.poll(); ConnectionClientTransport mockTransport = transportInfo.transport; ManagedClientTransport.Listener transportListener = transportInfo.listener; transportListener.transportReady(); assertEquals(0, balancerRpcExecutor.numPendingTasks()); // Wait-for-ready RPC is not allowed ClientCall<String, Integer> call = sChannel.newCall(method, CallOptions.DEFAULT.withWaitForReady()); call.start(mockCallListener, headers); verify(mockTransport, never()).newStream( any(MethodDescriptor.class), any(Metadata.class), any(CallOptions.class)); verifyZeroInteractions(mockCallListener); assertEquals(1, balancerRpcExecutor.runDueTasks()); verify(mockCallListener).onClose( same(SubchannelChannel.WAIT_FOR_READY_ERROR), any(Metadata.class)); }