use of io.grpc.ChannelLogger 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 io.grpc.ChannelLogger in project grpc-java by grpc.
the class NettyTransportTest method channelHasUnresolvedHostname.
@Test
public void channelHasUnresolvedHostname() throws Exception {
server = null;
final SettableFuture<Status> future = SettableFuture.create();
ChannelLogger logger = transportLogger();
ManagedClientTransport transport = clientFactory.newClientTransport(InetSocketAddress.createUnresolved("invalid", 1234), new ClientTransportFactory.ClientTransportOptions().setChannelLogger(logger), logger);
Runnable runnable = transport.start(new ManagedClientTransport.Listener() {
@Override
public void transportShutdown(Status s) {
future.set(s);
}
@Override
public void transportTerminated() {
}
@Override
public void transportReady() {
Throwable t = new Throwable("transport should have failed and shutdown but didnt");
future.setException(t);
}
@Override
public void transportInUse(boolean inUse) {
Throwable t = new Throwable("transport should have failed and shutdown but didnt");
future.setException(t);
}
});
if (runnable != null) {
runnable.run();
}
try {
Status status = future.get();
assertEquals(Status.Code.UNAVAILABLE, status.getCode());
assertThat(status.getCause()).isInstanceOf(UnresolvedAddressException.class);
assertEquals("unresolved address", status.getDescription());
} finally {
transport.shutdown(Status.UNAVAILABLE.withDescription("test shutdown"));
}
}
use of io.grpc.ChannelLogger in project grpc-java by grpc.
the class SdsProtocolNegotiatorsTest method clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute.
@Test
public void clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute() {
UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext(CommonTlsContext.newBuilder().build());
ClientSdsProtocolNegotiator pn = new ClientSdsProtocolNegotiator(InternalProtocolNegotiators.plaintext());
GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
ChannelLogger logger = mock(ChannelLogger.class);
doNothing().when(logger).log(any(ChannelLogLevel.class), anyString());
when(mockHandler.getNegotiationLogger()).thenReturn(logger);
TlsContextManager mockTlsContextManager = mock(TlsContextManager.class);
when(mockHandler.getEagAttributes()).thenReturn(Attributes.newBuilder().set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER, new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager)).build());
ChannelHandler newHandler = pn.newHandler(mockHandler);
assertThat(newHandler).isNotNull();
assertThat(newHandler).isInstanceOf(ClientSdsHandler.class);
}
use of io.grpc.ChannelLogger in project grpc-java by grpc.
the class ProtocolNegotiators method httpProxy.
/**
* Returns a {@link ProtocolNegotiator} that does HTTP CONNECT proxy negotiation.
*/
public static ProtocolNegotiator httpProxy(final SocketAddress proxyAddress, @Nullable final String proxyUsername, @Nullable final String proxyPassword, final ProtocolNegotiator negotiator) {
checkNotNull(negotiator, "negotiator");
checkNotNull(proxyAddress, "proxyAddress");
final AsciiString scheme = negotiator.scheme();
class ProxyNegotiator implements ProtocolNegotiator {
@Override
public ChannelHandler newHandler(GrpcHttp2ConnectionHandler http2Handler) {
ChannelHandler protocolNegotiationHandler = negotiator.newHandler(http2Handler);
ChannelLogger negotiationLogger = http2Handler.getNegotiationLogger();
return new ProxyProtocolNegotiationHandler(proxyAddress, proxyUsername, proxyPassword, protocolNegotiationHandler, negotiationLogger);
}
@Override
public AsciiString scheme() {
return scheme;
}
// This method is not normally called, because we use httpProxy on a per-connection basis in
// NettyChannelBuilder. Instead, we expect `negotiator' to be closed by NettyTransportFactory.
@Override
public void close() {
negotiator.close();
}
}
return new ProxyNegotiator();
}
use of io.grpc.ChannelLogger in project grpc-java by grpc.
the class AbstractClientTransportFactoryTest method newClientTransportAfterCloseShouldThrow.
@Test(expected = IllegalStateException.class)
public void newClientTransportAfterCloseShouldThrow() {
ClientTransportFactory transportFactory = newClientTransportFactory();
transportFactory.close();
transportFactory.newClientTransport(new InetSocketAddress("localhost", 12345), new ClientTransportFactory.ClientTransportOptions(), new ChannelLogger() {
@Override
public void log(ChannelLogLevel level, String message) {
}
@Override
public void log(ChannelLogLevel level, String messageFormat, Object... args) {
}
});
}
Aggregations