20
20
import org .junit .Assert ;
21
21
import org .junit .Before ;
22
22
import org .junit .Test ;
23
+ import static org .mockito .ArgumentMatchers .any ;
24
+ import static org .mockito .ArgumentMatchers .anyInt ;
23
25
import org .mockito .MockedStatic ;
24
26
import org .mockito .Mockito ;
27
+ import static org .mockito .Mockito .times ;
28
+ import static org .mockito .Mockito .verify ;
29
+ import static org .mockito .Mockito .when ;
25
30
import org .mockito .MockitoAnnotations ;
26
31
27
32
import tech .ydb .core .grpc .GrpcTransport ;
28
33
import tech .ydb .core .grpc .GrpcTransportBuilder ;
29
34
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
-
36
35
/**
37
36
*
38
37
* @author Aleksandr Gorshenin
@@ -73,7 +72,7 @@ public void tearDown() throws Exception {
73
72
@ Test
74
73
public void defaultParams () {
75
74
GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" );
76
- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
75
+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
77
76
channelStaticMock .verify (FOR_ADDRESS , times (0 ));
78
77
79
78
Assert .assertEquals (30_000l , factory .getConnectTimeoutMs ());
@@ -83,8 +82,8 @@ public void defaultParams() {
83
82
84
83
verify (channelBuilderMock , times (0 )).negotiationType (NegotiationType .TLS );
85
84
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 );
88
87
verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
89
88
verify (channelBuilderMock , times (0 )).enableRetry ();
90
89
verify (channelBuilderMock , times (1 )).disableRetry ();
@@ -97,7 +96,7 @@ public void defaultSslFactory() {
97
96
.withGrpcRetry (true )
98
97
.withConnectTimeout (Duration .ofMinutes (1 ));
99
98
100
- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
99
+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
101
100
channelStaticMock .verify (FOR_ADDRESS , times (0 ));
102
101
103
102
Assert .assertEquals (60000l , factory .getConnectTimeoutMs ());
@@ -107,8 +106,8 @@ public void defaultSslFactory() {
107
106
108
107
verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .TLS );
109
108
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 );
112
111
verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
113
112
verify (channelBuilderMock , times (1 )).enableRetry ();
114
113
verify (channelBuilderMock , times (0 )).disableRetry ();
@@ -119,18 +118,19 @@ public void customChannelInitializer() {
119
118
GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" )
120
119
.withUseDefaultGrpcResolver (true );
121
120
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
+
125
125
channelStaticMock .verify (FOR_ADDRESS , times (0 ));
126
126
127
127
Assert .assertSame (channelMock , factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
128
128
129
129
channelStaticMock .verify (FOR_ADDRESS , times (1 ));
130
130
131
131
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 );
134
134
verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
135
135
verify (channelBuilderMock , times (1 )).withOption (ChannelOption .TCP_NODELAY , Boolean .TRUE );
136
136
}
@@ -147,7 +147,7 @@ public void customSslFactory() throws CertificateException, IOException {
147
147
.withGrpcRetry (false )
148
148
.withConnectTimeout (4 , TimeUnit .SECONDS );
149
149
150
- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
150
+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
151
151
152
152
Assert .assertEquals (4000l , factory .getConnectTimeoutMs ());
153
153
Assert .assertSame (channelMock , factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
@@ -160,8 +160,8 @@ public void customSslFactory() throws CertificateException, IOException {
160
160
161
161
verify (channelBuilderMock , times (1 )).negotiationType (NegotiationType .TLS );
162
162
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 );
165
165
verify (channelBuilderMock , times (1 )).withOption (ChannelOption .ALLOCATOR , ByteBufAllocator .DEFAULT );
166
166
verify (channelBuilderMock , times (0 )).enableRetry ();
167
167
verify (channelBuilderMock , times (1 )).disableRetry ();
@@ -173,7 +173,7 @@ public void invalidSslCert() {
173
173
GrpcTransportBuilder builder = GrpcTransport .forHost (MOCKED_HOST , MOCKED_PORT , "/Root" )
174
174
.withSecureConnection (cert );
175
175
176
- ManagedChannelFactory factory = DefaultChannelFactory . build (builder );
176
+ ManagedChannelFactory factory = ChannelFactoryLoader . load (). buildFactory (builder );
177
177
178
178
RuntimeException ex = Assert .assertThrows (RuntimeException .class ,
179
179
() -> factory .newManagedChannel (MOCKED_HOST , MOCKED_PORT ));
0 commit comments