2020import org .junit .Assert ;
2121import org .junit .Before ;
2222import org .junit .Test ;
23+ import static org .mockito .ArgumentMatchers .any ;
24+ import static org .mockito .ArgumentMatchers .anyInt ;
2325import org .mockito .MockedStatic ;
2426import org .mockito .Mockito ;
27+ import static org .mockito .Mockito .times ;
28+ import static org .mockito .Mockito .verify ;
29+ import static org .mockito .Mockito .when ;
2530import org .mockito .MockitoAnnotations ;
2631
2732import tech .ydb .core .grpc .GrpcTransport ;
2833import tech .ydb .core .grpc .GrpcTransportBuilder ;
2934
30- import static org .mockito .ArgumentMatchers .any ;
31- import static org .mockito .ArgumentMatchers .anyInt ;
32- import static org .mockito .Mockito .times ;
33- import static org .mockito .Mockito .verify ;
34- import static org .mockito .Mockito .when ;
35-
3635/**
3736 *
3837 * @author Aleksandr Gorshenin
@@ -73,7 +72,7 @@ public void tearDown() throws Exception {
7372 @ Test
7473 public void defaultParams () {
7574 GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" );
76- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
75+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
7776 channelStaticMock .verify (FOR_ADDRESS , times (0 ));
7877
7978 Assert .assertEquals (30_000l , factory .getConnectTimeoutMs ());
@@ -83,8 +82,8 @@ public void defaultParams() {
8382
8483 verify (channelBuilderMock , times (0 )).negotiationType (NegotiationType .TLS );
8584 verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .PLAINTEXT );
86- verify (channelBuilderMock , times (1 )).maxInboundMessageSize (DefaultChannelFactory .INBOUND_MESSAGE_SIZE );
87- verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (DefaultChannelFactory .DEFAULT_BALANCER_POLICY );
85+ verify (channelBuilderMock , times (1 )).maxInboundMessageSize (ShadedNettyChannelFactory .INBOUND_MESSAGE_SIZE );
86+ verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (ShadedNettyChannelFactory .DEFAULT_BALANCER_POLICY );
8887 verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
8988 verify (channelBuilderMock , times (0 )).enableRetry ();
9089 verify (channelBuilderMock , times (1 )).disableRetry ();
@@ -97,7 +96,7 @@ public void defaultSslFactory() {
9796 .withGrpcRetry (true )
9897 .withConnectTimeout (Duration .ofMinutes (1 ));
9998
100- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
99+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
101100 channelStaticMock .verify (FOR_ADDRESS , times (0 ));
102101
103102 Assert .assertEquals (60000l , factory .getConnectTimeoutMs ());
@@ -107,8 +106,8 @@ public void defaultSslFactory() {
107106
108107 verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .TLS );
109108 verify (channelBuilderMock , times (0 )).negotiationType (NegotiationType .PLAINTEXT );
110- verify (channelBuilderMock , times (1 )).maxInboundMessageSize (DefaultChannelFactory .INBOUND_MESSAGE_SIZE );
111- verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (DefaultChannelFactory .DEFAULT_BALANCER_POLICY );
109+ verify (channelBuilderMock , times (1 )).maxInboundMessageSize (ShadedNettyChannelFactory .INBOUND_MESSAGE_SIZE );
110+ verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (ShadedNettyChannelFactory .DEFAULT_BALANCER_POLICY );
112111 verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
113112 verify (channelBuilderMock , times (1 )).enableRetry ();
114113 verify (channelBuilderMock , times (0 )).disableRetry ();
@@ -119,18 +118,19 @@ public void customChannelInitializer() {
119118 GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" )
120119 .withUseDefaultGrpcResolver (true );
121120
122- ManagedChannelFactory factory = DefaultChannelFactory .build (
123- builder , cb -> cb .withOption (ChannelOption .TCP_NODELAY , Boolean .TRUE )
124- );
121+ ManagedChannelFactory factory = ShadedNettyChannelFactory
122+ .withInterceptor (cb -> cb .withOption (ChannelOption .TCP_NODELAY , Boolean .TRUE ))
123+ .buildFactory (builder );
124+
125125 channelStaticMock .verify (FOR_ADDRESS , times (0 ));
126126
127127 Assert .assertSame (channelMock , factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
128128
129129 channelStaticMock .verify (FOR_ADDRESS , times (1 ));
130130
131131 verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .PLAINTEXT );
132- verify (channelBuilderMock , times (1 )).maxInboundMessageSize (DefaultChannelFactory .INBOUND_MESSAGE_SIZE );
133- verify (channelBuilderMock , times (0 )).defaultLoadBalancingPolicy (DefaultChannelFactory .DEFAULT_BALANCER_POLICY );
132+ verify (channelBuilderMock , times (1 )).maxInboundMessageSize (ShadedNettyChannelFactory .INBOUND_MESSAGE_SIZE );
133+ verify (channelBuilderMock , times (0 )).defaultLoadBalancingPolicy (ShadedNettyChannelFactory .DEFAULT_BALANCER_POLICY );
134134 verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
135135 verify (channelBuilderMock , times (1 )).withOption (ChannelOption .TCP_NODELAY , Boolean .TRUE );
136136 }
@@ -147,7 +147,7 @@ public void customSslFactory() throws CertificateException, IOException {
147147 .withGrpcRetry (false )
148148 .withConnectTimeout (4 , TimeUnit .SECONDS );
149149
150- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
150+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
151151
152152 Assert .assertEquals (4000l , factory .getConnectTimeoutMs ());
153153 Assert .assertSame (channelMock , factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
@@ -160,8 +160,8 @@ public void customSslFactory() throws CertificateException, IOException {
160160
161161 verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .TLS );
162162 verify (channelBuilderMock , times (0 )).negotiationType (NegotiationType .PLAINTEXT );
163- verify (channelBuilderMock , times (1 )).maxInboundMessageSize (DefaultChannelFactory .INBOUND_MESSAGE_SIZE );
164- verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (DefaultChannelFactory .DEFAULT_BALANCER_POLICY );
163+ verify (channelBuilderMock , times (1 )).maxInboundMessageSize (ShadedNettyChannelFactory .INBOUND_MESSAGE_SIZE );
164+ verify (channelBuilderMock , times (1 )).defaultLoadBalancingPolicy (ShadedNettyChannelFactory .DEFAULT_BALANCER_POLICY );
165165 verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
166166 verify (channelBuilderMock , times (0 )).enableRetry ();
167167 verify (channelBuilderMock , times (1 )).disableRetry ();
@@ -173,7 +173,7 @@ public void invalidSslCert() {
173173 GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" )
174174 .withSecureConnection (cert );
175175
176- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
176+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
177177
178178 RuntimeException ex = Assert .assertThrows (RuntimeException .class ,
179179 () -> factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
0 commit comments