use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class AltsProtocolNegotiatorTest method setup.
@Before
public void setup() throws Exception {
ChannelHandler uncaughtExceptionHandler = new ChannelDuplexHandler() {
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
caughtException = cause;
super.exceptionCaught(ctx, cause);
ctx.close();
}
};
TsiHandshakerFactory handshakerFactory = new DelegatingTsiHandshakerFactory(FakeTsiHandshaker.clientHandshakerFactory()) {
@Override
public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) {
return new DelegatingTsiHandshaker(super.newHandshaker(authority, logger)) {
@Override
public TsiPeer extractPeer() throws GeneralSecurityException {
return mockedTsiPeer;
}
@Override
public Object extractPeerObject() throws GeneralSecurityException {
return mockedAltsContext;
}
};
}
};
ManagedChannel fakeChannel = NettyChannelBuilder.forTarget("localhost:8080").build();
ObjectPool<Channel> fakeChannelPool = new FixedObjectPool<Channel>(fakeChannel);
LazyChannel lazyFakeChannel = new LazyChannel(fakeChannelPool);
ChannelHandler altsServerHandler = new ServerAltsProtocolNegotiator(handshakerFactory, lazyFakeChannel).newHandler(grpcHandler);
// On real server, WBAEH fires default ProtocolNegotiationEvent. KickNH provides this behavior.
ChannelHandler handler = new KickNegotiationHandler(altsServerHandler);
channel = new EmbeddedChannel(uncaughtExceptionHandler, handler);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class LoggingServerProviderTest method serverBuilder_interceptorCalled.
@SuppressWarnings("unchecked")
private void serverBuilder_interceptorCalled(Supplier<ServerBuilder<?>> serverBuilderSupplier) throws IOException {
ServerInterceptor interceptor = mock(ServerInterceptor.class, delegatesTo(new NoopInterceptor()));
InternalLoggingServerInterceptor.Factory factory = mock(InternalLoggingServerInterceptor.Factory.class);
when(factory.create()).thenReturn(interceptor);
LoggingServerProvider.init(factory);
Server server = serverBuilderSupplier.get().addService(new SimpleServiceImpl()).build().start();
int port = cleanupRule.register(server).getPort();
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", port).usePlaintext().build();
SimpleServiceGrpc.SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(cleanupRule.register(channel));
assertThat(unaryRpc("buddy", stub)).isEqualTo("Hello buddy");
verify(interceptor).interceptCall(any(ServerCall.class), any(Metadata.class), anyCallHandler());
LoggingServerProvider.finish();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class LoggingChannelProviderTest method forAddress_interceptorCalled.
@Test
public void forAddress_interceptorCalled() {
ClientInterceptor interceptor = mock(ClientInterceptor.class, delegatesTo(new NoopInterceptor()));
InternalLoggingChannelInterceptor.Factory factory = mock(InternalLoggingChannelInterceptor.Factory.class);
when(factory.create()).thenReturn(interceptor);
LoggingChannelProvider.init(factory);
ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forAddress("localhost", 80);
ManagedChannel channel = builder.build();
CallOptions callOptions = CallOptions.DEFAULT;
ClientCall<Void, Void> unused = channel.newCall(method, callOptions);
verify(interceptor).interceptCall(same(method), same(callOptions), ArgumentMatchers.<Channel>any());
channel.shutdownNow();
LoggingChannelProvider.finish();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class LoggingChannelProviderTest method forTarget_interceptorCalled.
@Test
public void forTarget_interceptorCalled() {
ClientInterceptor interceptor = mock(ClientInterceptor.class, delegatesTo(new NoopInterceptor()));
InternalLoggingChannelInterceptor.Factory factory = mock(InternalLoggingChannelInterceptor.Factory.class);
when(factory.create()).thenReturn(interceptor);
LoggingChannelProvider.init(factory);
ManagedChannelBuilder<?> builder = ManagedChannelBuilder.forTarget("localhost");
ManagedChannel channel = builder.build();
CallOptions callOptions = CallOptions.DEFAULT;
ClientCall<Void, Void> unused = channel.newCall(method, callOptions);
verify(interceptor).interceptCall(same(method), same(callOptions), ArgumentMatchers.<Channel>any());
channel.shutdownNow();
LoggingChannelProvider.finish();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project grpc-java by grpc.
the class OkHttpChannelBuilderTest method authorityIsReadable.
@Test
public void authorityIsReadable() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("original", 1234);
ManagedChannel channel = grpcCleanupRule.register(builder.build());
assertEquals("original:1234", channel.authority());
}
Aggregations