Skip to content

Commit a054eac

Browse files
committed
Update tests
1 parent e303363 commit a054eac

File tree

1 file changed

+66
-50
lines changed

1 file changed

+66
-50
lines changed

core/src/test/java/tech/ydb/core/impl/pool/DefaultChannelFactoryTest.java

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
import org.junit.Assert;
2121
import org.junit.Before;
2222
import org.junit.Test;
23-
import static org.mockito.ArgumentMatchers.any;
24-
import static org.mockito.ArgumentMatchers.anyInt;
23+
import org.mockito.ArgumentMatchers;
2524
import org.mockito.MockedStatic;
2625
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;
3026
import org.mockito.MockitoAnnotations;
3127

3228
import tech.ydb.core.grpc.GrpcTransport;
@@ -54,13 +50,20 @@ public void setUp() {
5450
channelStaticMock = Mockito.mockStatic(NettyChannelBuilder.class);
5551
channelStaticMock.when(FOR_ADDRESS).thenReturn(channelBuilderMock);
5652

57-
when(channelBuilderMock.negotiationType(any())).thenReturn(channelBuilderMock);
58-
when(channelBuilderMock.maxInboundMessageSize(anyInt())).thenReturn(channelBuilderMock);
59-
when(channelBuilderMock.withOption(any(), any())).thenReturn(channelBuilderMock);
60-
when(channelBuilderMock.intercept((ClientInterceptor)any())).thenReturn(channelBuilderMock);
61-
when(channelBuilderMock.nameResolverFactory(any())).thenReturn(channelBuilderMock);
62-
63-
when(channelBuilderMock.build()).thenReturn(channelMock);
53+
Mockito.when(channelBuilderMock.negotiationType(ArgumentMatchers.any()))
54+
.thenReturn(channelBuilderMock);
55+
Mockito.when(channelBuilderMock.maxInboundMessageSize(ArgumentMatchers.anyInt()))
56+
.thenReturn(channelBuilderMock);
57+
Mockito.when(channelBuilderMock.withOption(ArgumentMatchers.any(), ArgumentMatchers.any()))
58+
.thenReturn(channelBuilderMock);
59+
Mockito.when(channelBuilderMock.intercept(ArgumentMatchers.any(ClientInterceptor.class)))
60+
.thenReturn(channelBuilderMock);
61+
Mockito.when(channelBuilderMock.nameResolverFactory(ArgumentMatchers.any()))
62+
.thenReturn(channelBuilderMock);
63+
Mockito.when(channelBuilderMock.keepAliveTime(ArgumentMatchers.anyLong(), ArgumentMatchers.any()))
64+
.thenReturn(channelBuilderMock);
65+
66+
Mockito.when(channelBuilderMock.build()).thenReturn(channelMock);
6467
}
6568

6669
@After
@@ -73,20 +76,23 @@ public void tearDown() throws Exception {
7376
public void defaultParams() {
7477
GrpcTransportBuilder builder = GrpcTransport.forHost(MOCKED_HOST, MOCKED_PORT, "/Root");
7578
ManagedChannelFactory factory = ChannelFactoryLoader.load().buildFactory(builder);
76-
channelStaticMock.verify(FOR_ADDRESS, times(0));
79+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(0));
7780

7881
Assert.assertEquals(30_000l, factory.getConnectTimeoutMs());
7982
Assert.assertSame(channelMock, factory.newManagedChannel(MOCKED_HOST, MOCKED_PORT, null));
8083

81-
channelStaticMock.verify(FOR_ADDRESS, times(1));
82-
83-
verify(channelBuilderMock, times(0)).negotiationType(NegotiationType.TLS);
84-
verify(channelBuilderMock, times(1)).negotiationType(NegotiationType.PLAINTEXT);
85-
verify(channelBuilderMock, times(1)).maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
86-
verify(channelBuilderMock, times(1)).defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
87-
verify(channelBuilderMock, times(1)).withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
88-
verify(channelBuilderMock, times(0)).enableRetry();
89-
verify(channelBuilderMock, times(1)).disableRetry();
84+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(1));
85+
86+
Mockito.verify(channelBuilderMock, Mockito.times(0)).negotiationType(NegotiationType.TLS);
87+
Mockito.verify(channelBuilderMock, Mockito.times(1)).negotiationType(NegotiationType.PLAINTEXT);
88+
Mockito.verify(channelBuilderMock, Mockito.times(1))
89+
.maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
90+
Mockito.verify(channelBuilderMock, Mockito.times(1))
91+
.defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
92+
Mockito.verify(channelBuilderMock, Mockito.times(1))
93+
.withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
94+
Mockito.verify(channelBuilderMock, Mockito.times(0)).enableRetry();
95+
Mockito.verify(channelBuilderMock, Mockito.times(1)).disableRetry();
9096
}
9197

9298
@Test
@@ -97,20 +103,23 @@ public void defaultSslFactory() {
97103
.withConnectTimeout(Duration.ofMinutes(1));
98104

99105
ManagedChannelFactory factory = ChannelFactoryLoader.load().buildFactory(builder);
100-
channelStaticMock.verify(FOR_ADDRESS, times(0));
106+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(0));
101107

102108
Assert.assertEquals(60000l, factory.getConnectTimeoutMs());
103109
Assert.assertSame(channelMock, factory.newManagedChannel(MOCKED_HOST, MOCKED_PORT, null));
104110

105-
channelStaticMock.verify(FOR_ADDRESS, times(1));
106-
107-
verify(channelBuilderMock, times(1)).negotiationType(NegotiationType.TLS);
108-
verify(channelBuilderMock, times(0)).negotiationType(NegotiationType.PLAINTEXT);
109-
verify(channelBuilderMock, times(1)).maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
110-
verify(channelBuilderMock, times(1)).defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
111-
verify(channelBuilderMock, times(1)).withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
112-
verify(channelBuilderMock, times(1)).enableRetry();
113-
verify(channelBuilderMock, times(0)).disableRetry();
111+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(1));
112+
113+
Mockito.verify(channelBuilderMock, Mockito.times(1)).negotiationType(NegotiationType.TLS);
114+
Mockito.verify(channelBuilderMock, Mockito.times(0)).negotiationType(NegotiationType.PLAINTEXT);
115+
Mockito.verify(channelBuilderMock, Mockito.times(1))
116+
.maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
117+
Mockito.verify(channelBuilderMock, Mockito.times(1))
118+
.defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
119+
Mockito.verify(channelBuilderMock, Mockito.times(1))
120+
.withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
121+
Mockito.verify(channelBuilderMock, Mockito.times(1)).enableRetry();
122+
Mockito.verify(channelBuilderMock, Mockito.times(0)).disableRetry();
114123
}
115124

116125
@Test
@@ -119,20 +128,24 @@ public void customChannelInitializer() {
119128
.withUseDefaultGrpcResolver(true);
120129

121130
ManagedChannelFactory factory = ShadedNettyChannelFactory
122-
.withInterceptor(cb -> cb.withOption(ChannelOption.TCP_NODELAY, Boolean.TRUE))
131+
.withInterceptor(cb -> cb.enableFullStreamDecompression())
123132
.buildFactory(builder);
124133

125-
channelStaticMock.verify(FOR_ADDRESS, times(0));
134+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(0));
126135

127136
Assert.assertSame(channelMock, factory.newManagedChannel(MOCKED_HOST, MOCKED_PORT, null));
128137

129-
channelStaticMock.verify(FOR_ADDRESS, times(1));
130-
131-
verify(channelBuilderMock, times(1)).negotiationType(NegotiationType.PLAINTEXT);
132-
verify(channelBuilderMock, times(1)).maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
133-
verify(channelBuilderMock, times(0)).defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
134-
verify(channelBuilderMock, times(1)).withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
135-
verify(channelBuilderMock, times(1)).withOption(ChannelOption.TCP_NODELAY, Boolean.TRUE);
138+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(1));
139+
140+
Mockito.verify(channelBuilderMock, Mockito.times(1)).negotiationType(NegotiationType.PLAINTEXT);
141+
Mockito.verify(channelBuilderMock, Mockito.times(1))
142+
.maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
143+
Mockito.verify(channelBuilderMock, Mockito.times(0))
144+
.defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
145+
Mockito.verify(channelBuilderMock, Mockito.times(1))
146+
.withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
147+
Mockito.verify(channelBuilderMock, Mockito.times(1)).withOption(ChannelOption.TCP_NODELAY, Boolean.TRUE);
148+
Mockito.verify(channelBuilderMock, Mockito.times(1)).enableFullStreamDecompression();
136149
}
137150

138151
@Test
@@ -156,15 +169,18 @@ public void customSslFactory() throws CertificateException, IOException {
156169
selfSignedCert.delete();
157170
}
158171

159-
channelStaticMock.verify(FOR_ADDRESS, times(1));
160-
161-
verify(channelBuilderMock, times(1)).negotiationType(NegotiationType.TLS);
162-
verify(channelBuilderMock, times(0)).negotiationType(NegotiationType.PLAINTEXT);
163-
verify(channelBuilderMock, times(1)).maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
164-
verify(channelBuilderMock, times(1)).defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
165-
verify(channelBuilderMock, times(1)).withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
166-
verify(channelBuilderMock, times(0)).enableRetry();
167-
verify(channelBuilderMock, times(1)).disableRetry();
172+
channelStaticMock.verify(FOR_ADDRESS, Mockito.times(1));
173+
174+
Mockito.verify(channelBuilderMock, Mockito.times(1)).negotiationType(NegotiationType.TLS);
175+
Mockito.verify(channelBuilderMock, Mockito.times(0)).negotiationType(NegotiationType.PLAINTEXT);
176+
Mockito.verify(channelBuilderMock, Mockito.times(1))
177+
.maxInboundMessageSize(ShadedNettyChannelFactory.INBOUND_MESSAGE_SIZE);
178+
Mockito.verify(channelBuilderMock, Mockito.times(1))
179+
.defaultLoadBalancingPolicy(ShadedNettyChannelFactory.DEFAULT_BALANCER_POLICY);
180+
Mockito.verify(channelBuilderMock, Mockito.times(1))
181+
.withOption(ChannelOption.ALLOCATOR, ByteBufAllocator.DEFAULT);
182+
Mockito.verify(channelBuilderMock, Mockito.times(0)).enableRetry();
183+
Mockito.verify(channelBuilderMock, Mockito.times(1)).disableRetry();
168184
}
169185

170186
@Test

0 commit comments

Comments
 (0)