Skip to content

Commit 36475ca

Browse files
committed
Update tests
1 parent 94442e9 commit 36475ca

File tree

11 files changed

+182
-111
lines changed

11 files changed

+182
-111
lines changed

sdk/clientcore/http-netty4/pom.xml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
io.clientcore.core.implementation*,io.clientcore.core.models,io.clientcore.core.util,io.clientcore.core.util*
5757
</javadoc.excludePackageNames>
5858

59-
<netty.version>4.1.127.Final</netty.version> <!-- {x-version-update;io.netty:netty-common;external_dependency} -->
59+
<netty.version>4.2.9.Final</netty.version> <!-- {x-version-update;io.netty:netty-common;external_dependency} -->
6060
</properties>
6161

6262
<dependencies>
@@ -205,12 +205,6 @@
205205
<version>2.5.2</version> <!-- {x-version-update;org.conscrypt:conscrypt-openjdk-uber;external_dependency} -->
206206
<scope>test</scope>
207207
</dependency>
208-
<dependency>
209-
<groupId>org.mockito</groupId>
210-
<artifactId>mockito-core</artifactId>
211-
<version>4.11.0</version> <!-- {x-version-update;org.mockito:mockito-core;external_dependency} -->
212-
<scope>test</scope>
213-
</dependency>
214208
</dependencies>
215209

216210
<build>

sdk/clientcore/http-netty4/src/main/java/io/clientcore/http/netty4/NettyHttpClientBuilder.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import io.netty.channel.Channel;
1616
import io.netty.channel.ChannelOption;
1717
import io.netty.channel.EventLoopGroup;
18-
import io.netty.channel.nio.NioEventLoopGroup;
1918
import io.netty.channel.socket.SocketChannel;
2019
import io.netty.channel.socket.nio.NioSocketChannel;
2120
import io.netty.handler.ssl.SslContext;
@@ -153,11 +152,11 @@ public NettyHttpClientBuilder() {
153152
/**
154153
* Sets the event loop group for the Netty client.
155154
* <p>
156-
* By default, if no {@code eventLoopGroup} is configured and no native transports are available (Epoll KQueue)
157-
* {@link NioEventLoopGroup} will be used.
155+
* By default, if no {@code eventLoopGroup} is configured and no native transports are available (Epoll, KQueue)
156+
* {@link io.netty.channel.nio.NioEventLoopGroup} will be used.
158157
* <p>
159158
* If native transports are available, the {@link EventLoopGroup} implementation for the native transport will be
160-
* chosen over {@link NioEventLoopGroup}.
159+
* chosen over {@link io.netty.channel.nio.NioEventLoopGroup}.
161160
*
162161
* @param eventLoopGroup The event loop group.
163162
* @return The updated builder.
@@ -453,6 +452,7 @@ ProxyOptions getProxyOptions() {
453452
return (proxyOptions == null) ? ProxyOptions.fromConfiguration(buildConfiguration, true) : proxyOptions;
454453
}
455454

455+
@SuppressWarnings("deprecation")
456456
static EventLoopGroup getEventLoopGroupToUse(EventLoopGroup configuredGroup,
457457
Class<? extends SocketChannel> configuredChannelClass, boolean isEpollAvailable,
458458
MethodHandle epollEventLoopGroupCreator, boolean isKqueueAvailable, MethodHandle kqueueEventLoopGroupCreator) {
@@ -483,7 +483,7 @@ static EventLoopGroup getEventLoopGroupToUse(EventLoopGroup configuredGroup,
483483
}
484484

485485
// Fallback to NioEventLoopGroup.
486-
return new NioEventLoopGroup(threadFactory);
486+
return new io.netty.channel.nio.NioEventLoopGroup(threadFactory);
487487
}
488488

489489
static Class<? extends SocketChannel> getChannelClass(Class<? extends SocketChannel> configuredChannelClass,

sdk/clientcore/http-netty4/src/test/java/io/clientcore/http/netty4/NettyHttpClientBuilderTests.java

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
import io.netty.bootstrap.BootstrapConfig;
1616
import io.netty.channel.Channel;
1717
import io.netty.channel.EventLoopGroup;
18-
import io.netty.channel.epoll.EpollEventLoopGroup;
1918
import io.netty.channel.epoll.EpollSocketChannel;
20-
import io.netty.channel.kqueue.KQueueEventLoopGroup;
2119
import io.netty.channel.kqueue.KQueueSocketChannel;
22-
import io.netty.channel.nio.NioEventLoopGroup;
2320
import io.netty.channel.socket.SocketChannel;
2421
import io.netty.channel.socket.nio.NioSocketChannel;
2522
import org.junit.jupiter.api.Test;
@@ -283,10 +280,12 @@ private static Stream<Configuration> buildWithExplicitConfigurationProxySupplier
283280
* Tests that a custom {@link io.netty.channel.EventLoopGroup} is properly applied to the Netty client to handle
284281
* sending and receiving requests and responses.
285282
*/
283+
@SuppressWarnings("deprecation")
286284
@Test
287285
public void buildEventLoopClient() {
288286
String expectedThreadName = "testEventLoop";
289-
NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(1, (Runnable r) -> new Thread(r, expectedThreadName));
287+
io.netty.channel.nio.NioEventLoopGroup eventLoopGroup
288+
= new io.netty.channel.nio.NioEventLoopGroup(1, (Runnable r) -> new Thread(r, expectedThreadName));
290289

291290
NettyHttpClient nettyClient
292291
= (NettyHttpClient) new NettyHttpClientBuilder().eventLoopGroup(eventLoopGroup).build();
@@ -307,59 +306,64 @@ private static Stream<Arguments> getTimeoutMillisSupplier() {
307306
Arguments.of(Duration.ofNanos(1), TimeUnit.MILLISECONDS.toMillis(1)));
308307
}
309308

309+
@SuppressWarnings("deprecation")
310310
@Test
311311
@EnabledOnOs(OS.WINDOWS)
312312
public void windowsUseNioByDefault() {
313313
NettyHttpClient nettyHttpClient = (NettyHttpClient) new NettyHttpClientBuilder().build();
314314

315315
BootstrapConfig config = nettyHttpClient.getBootstrap().config();
316-
assertInstanceOf(NioEventLoopGroup.class, config.group());
316+
assertInstanceOf(io.netty.channel.nio.NioEventLoopGroup.class, config.group());
317317
assertInstanceOf(NioSocketChannel.class, config.channelFactory().newChannel());
318318
}
319319

320+
@SuppressWarnings("deprecation")
320321
@Test
321322
@EnabledOnOs(OS.MAC)
322323
public void macUsesKQueueByDefault() {
323324
NettyHttpClient nettyHttpClient = (NettyHttpClient) new NettyHttpClientBuilder().build();
324325

325326
BootstrapConfig config = nettyHttpClient.getBootstrap().config();
326-
assertInstanceOf(KQueueEventLoopGroup.class, config.group());
327+
assertInstanceOf(io.netty.channel.kqueue.KQueueEventLoopGroup.class, config.group());
327328
assertInstanceOf(KQueueSocketChannel.class, config.channelFactory().newChannel());
328329
}
329330

331+
@SuppressWarnings("deprecation")
330332
@Test
331333
@EnabledOnOs(OS.MAC)
332334
public void macUsesNioIfConfigured() {
333335
NettyHttpClient nettyHttpClient
334336
= (NettyHttpClient) new NettyHttpClientBuilder().channelClass(NioSocketChannel.class)
335-
.eventLoopGroup(new NioEventLoopGroup())
337+
.eventLoopGroup(new io.netty.channel.nio.NioEventLoopGroup())
336338
.build();
337339

338340
BootstrapConfig config = nettyHttpClient.getBootstrap().config();
339-
assertInstanceOf(NioEventLoopGroup.class, config.group());
341+
assertInstanceOf(io.netty.channel.nio.NioEventLoopGroup.class, config.group());
340342
assertInstanceOf(NioSocketChannel.class, config.channelFactory().newChannel());
341343
}
342344

345+
@SuppressWarnings("deprecation")
343346
@Test
344347
@EnabledOnOs(OS.LINUX)
345348
public void linuxUsesEpollByDefault() {
346349
NettyHttpClient nettyHttpClient = (NettyHttpClient) new NettyHttpClientBuilder().build();
347350

348351
BootstrapConfig config = nettyHttpClient.getBootstrap().config();
349-
assertInstanceOf(EpollEventLoopGroup.class, config.group());
352+
assertInstanceOf(io.netty.channel.epoll.EpollEventLoopGroup.class, config.group());
350353
assertInstanceOf(EpollSocketChannel.class, config.channelFactory().newChannel());
351354
}
352355

356+
@SuppressWarnings("deprecation")
353357
@Test
354358
@EnabledOnOs(OS.LINUX)
355359
public void linuxUsesNioIfConfigured() {
356360
NettyHttpClient nettyHttpClient
357361
= (NettyHttpClient) new NettyHttpClientBuilder().channelClass(NioSocketChannel.class)
358-
.eventLoopGroup(new NioEventLoopGroup())
362+
.eventLoopGroup(new io.netty.channel.nio.NioEventLoopGroup())
359363
.build();
360364

361365
BootstrapConfig config = nettyHttpClient.getBootstrap().config();
362-
assertInstanceOf(NioEventLoopGroup.class, config.group());
366+
assertInstanceOf(io.netty.channel.nio.NioEventLoopGroup.class, config.group());
363367
assertInstanceOf(NioSocketChannel.class, config.channelFactory().newChannel());
364368
}
365369

@@ -404,11 +408,12 @@ public void testMaximumHttpVersion() throws NoSuchFieldException, IllegalAccessE
404408
assertEquals(HttpProtocolVersion.HTTP_2, httpVersionField.get(clientv2));
405409
}
406410

411+
@SuppressWarnings("deprecation")
407412
private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws ReflectiveOperationException {
408413
// Doesn't matter what this is calling, just needs to throw an exception.
409414
// This will as it doesn't accept the arguments that it will be called with.
410-
MethodHandle exceptionCreator
411-
= MethodHandles.publicLookup().unreflectConstructor(NioEventLoopGroup.class.getDeclaredConstructor());
415+
MethodHandle exceptionCreator = MethodHandles.publicLookup()
416+
.unreflectConstructor(io.netty.channel.nio.NioEventLoopGroup.class.getDeclaredConstructor());
412417

413418
// NOTE: This test doesn't use EpollEventLoopGroup or KQueueEventLoopGroup directly, but rather uses different
414419
// EventLoopGroup classes as the creation of those requires native libraries to be loaded.
@@ -420,8 +425,8 @@ private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws Reflect
420425
.unreflectConstructor(MockKQueueEventLoopGroup.class.getDeclaredConstructor(ThreadFactory.class));
421426

422427
// EventLoopGroup is configured, use it.
423-
Arguments configuredGroup
424-
= Arguments.of(NioEventLoopGroup.class, new NioEventLoopGroup(), null, false, null, false, null);
428+
Arguments configuredGroup = Arguments.of(io.netty.channel.nio.NioEventLoopGroup.class,
429+
new io.netty.channel.nio.NioEventLoopGroup(), null, false, null, false, null);
425430

426431
// Epoll is available and nothing is configured, use EpollEventLoopGroup.
427432
Arguments epollGroup = Arguments.of(MockEpollEventLoopGroup.class, null, null, true, epollCreator, false, null);
@@ -431,8 +436,8 @@ private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws Reflect
431436
epollCreator, false, null);
432437

433438
// Epoll is available but throws an exception, use NioEventLoopGroup.
434-
Arguments epollExceptionGroup
435-
= Arguments.of(NioEventLoopGroup.class, null, null, true, exceptionCreator, false, null);
439+
Arguments epollExceptionGroup = Arguments.of(io.netty.channel.nio.NioEventLoopGroup.class, null, null, true,
440+
exceptionCreator, false, null);
436441

437442
// KQueue is available and nothing is configured, use KQueueEventLoopGroup.
438443
Arguments kqueueGroup
@@ -443,8 +448,8 @@ private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws Reflect
443448
false, null, true, kqueueCreator);
444449

445450
// KQueue is available but throws an exception, use NioEventLoopGroup.
446-
Arguments kqueueExceptionGroup
447-
= Arguments.of(NioEventLoopGroup.class, null, null, false, null, true, exceptionCreator);
451+
Arguments kqueueExceptionGroup = Arguments.of(io.netty.channel.nio.NioEventLoopGroup.class, null, null, false,
452+
null, true, exceptionCreator);
448453

449454
// Both Epoll and KQueue are available, use EpollEventLoopGroup.
450455
Arguments epollAndKqueueGroup
@@ -456,8 +461,8 @@ private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws Reflect
456461
KQueueSocketChannel.class, true, epollCreator, true, kqueueCreator);
457462

458463
// Both Epoll and KQueue are available but throws an exception, use NioEventLoopGroup.
459-
Arguments epollAndKqueueExceptionGroup
460-
= Arguments.of(NioEventLoopGroup.class, null, null, true, exceptionCreator, true, exceptionCreator);
464+
Arguments epollAndKqueueExceptionGroup = Arguments.of(io.netty.channel.nio.NioEventLoopGroup.class, null, null,
465+
true, exceptionCreator, true, exceptionCreator);
461466

462467
// Both Epoll and KQueue are available but channel class is set to EpollSocketChannel, use
463468
// EpollEventLoopGroup.
@@ -466,21 +471,23 @@ private static Stream<Arguments> getEventLoopGroupToUseSupplier() throws Reflect
466471

467472
// Both Epoll and KQueue are available but channel class is set to NioSocketChannel, use
468473
// NioEventLoopGroup.
469-
Arguments epollAndKqueueChannelNioGroup = Arguments.of(NioEventLoopGroup.class, null, NioSocketChannel.class,
470-
true, epollCreator, true, kqueueCreator);
474+
Arguments epollAndKqueueChannelNioGroup = Arguments.of(io.netty.channel.nio.NioEventLoopGroup.class, null,
475+
NioSocketChannel.class, true, epollCreator, true, kqueueCreator);
471476

472477
return Stream.of(configuredGroup, epollGroup, epollChannelGroup, epollExceptionGroup, kqueueGroup,
473478
kqueueChannelGroup, kqueueExceptionGroup, epollAndKqueueGroup, epollAndKqueueChannelGroup,
474479
epollAndKqueueExceptionGroup, epollAndKqueueChannelExceptionGroup, epollAndKqueueChannelNioGroup);
475480
}
476481

477-
public static final class MockEpollEventLoopGroup extends NioEventLoopGroup {
482+
@SuppressWarnings("deprecation")
483+
public static final class MockEpollEventLoopGroup extends io.netty.channel.nio.NioEventLoopGroup {
478484
public MockEpollEventLoopGroup(ThreadFactory threadFactory) {
479485
super(threadFactory);
480486
}
481487
}
482488

483-
public static final class MockKQueueEventLoopGroup extends NioEventLoopGroup {
489+
@SuppressWarnings("deprecation")
490+
public static final class MockKQueueEventLoopGroup extends io.netty.channel.nio.NioEventLoopGroup {
484491
public MockKQueueEventLoopGroup(ThreadFactory threadFactory) {
485492
super(threadFactory);
486493
}
@@ -496,34 +503,38 @@ public void getChannelClass(Class<?> expected, Class<? extends SocketChannel> co
496503
assertEquals(expected, channelClass);
497504
}
498505

506+
@SuppressWarnings("deprecation")
499507
private static Stream<Arguments> getChannelClassSupplier() {
500508
// Channel class is configured, use it.
501509
Arguments configuredChannel = Arguments.of(NioSocketChannel.class, NioSocketChannel.class, null, false, false);
502510

503511
// Epoll is available and EventLoopGroup is EpollEventLoopGroup, use EpollSocketChannel.
504-
Arguments epollChannel = Arguments.of(EpollSocketChannel.class, null, EpollEventLoopGroup.class, true, false);
512+
Arguments epollChannel = Arguments.of(EpollSocketChannel.class, null,
513+
io.netty.channel.epoll.EpollEventLoopGroup.class, true, false);
505514

506515
// KQueue is available and EventLoopGroup is KQueueEventLoopGroup, use KQueueSocketChannel.
507-
Arguments kqueueChannel
508-
= Arguments.of(KQueueSocketChannel.class, null, KQueueEventLoopGroup.class, false, true);
516+
Arguments kqueueChannel = Arguments.of(KQueueSocketChannel.class, null,
517+
io.netty.channel.kqueue.KQueueEventLoopGroup.class, false, true);
509518

510519
// Epoll is available and EventLoopGroup is NioEventLoopGroup, use NioSocketChannel.
511-
Arguments epollNioChannel = Arguments.of(NioSocketChannel.class, null, NioEventLoopGroup.class, true, false);
520+
Arguments epollNioChannel
521+
= Arguments.of(NioSocketChannel.class, null, io.netty.channel.nio.NioEventLoopGroup.class, true, false);
512522

513523
// KQueue is available and EventLoopGroup is NioEventLoopGroup, use NioSocketChannel.
514-
Arguments kqueueNioChannel = Arguments.of(NioSocketChannel.class, null, NioEventLoopGroup.class, false, true);
524+
Arguments kqueueNioChannel
525+
= Arguments.of(NioSocketChannel.class, null, io.netty.channel.nio.NioEventLoopGroup.class, false, true);
515526

516527
// Both Epoll and KQueue are available and EventLoopGroup is NioEventLoopGroup, use NioSocketChannel.
517528
Arguments epollAndKqueueNioChannel
518-
= Arguments.of(NioSocketChannel.class, null, NioEventLoopGroup.class, true, true);
529+
= Arguments.of(NioSocketChannel.class, null, io.netty.channel.nio.NioEventLoopGroup.class, true, true);
519530

520531
// Both Epoll and KQueue are available and EventLoopGroup is EpollEventLoopGroup, use EpollSocketChannel.
521-
Arguments epollAndKqueueEpollChannel
522-
= Arguments.of(EpollSocketChannel.class, null, EpollEventLoopGroup.class, true, true);
532+
Arguments epollAndKqueueEpollChannel = Arguments.of(EpollSocketChannel.class, null,
533+
io.netty.channel.epoll.EpollEventLoopGroup.class, true, true);
523534

524535
// Both Epoll and KQueue are available and EventLoopGroup is KQueueEventLoopGroup, use KQueueSocketChannel.
525-
Arguments epollAndKqueueKqueueChannel
526-
= Arguments.of(KQueueSocketChannel.class, null, KQueueEventLoopGroup.class, true, true);
536+
Arguments epollAndKqueueKqueueChannel = Arguments.of(KQueueSocketChannel.class, null,
537+
io.netty.channel.kqueue.KQueueEventLoopGroup.class, true, true);
527538

528539
return Stream.of(configuredChannel, epollChannel, kqueueChannel, epollNioChannel, kqueueNioChannel,
529540
epollAndKqueueNioChannel, epollAndKqueueEpollChannel, epollAndKqueueKqueueChannel);

sdk/clientcore/http-netty4/src/test/java/io/clientcore/http/netty4/implementation/Netty4ConnectionPoolTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.netty.channel.Channel;
1111
import io.netty.channel.ChannelOption;
1212
import io.netty.channel.EventLoopGroup;
13-
import io.netty.channel.nio.NioEventLoopGroup;
1413
import io.netty.channel.socket.nio.NioSocketChannel;
1514
import io.netty.util.concurrent.Future;
1615
import org.junit.jupiter.api.AfterAll;
@@ -59,11 +58,12 @@ public class Netty4ConnectionPoolTests {
5958
private static Bootstrap bootstrap;
6059
private static Netty4ConnectionPoolKey connectionPoolKey;
6160

61+
@SuppressWarnings("deprecation")
6262
@BeforeAll
6363
public static void startTestServerAndEventLoopGroup() {
6464
server = NettyHttpClientLocalTestServer.getServer();
6565
server.start();
66-
eventLoopGroup = new NioEventLoopGroup(2);
66+
eventLoopGroup = new io.netty.channel.nio.NioEventLoopGroup(2);
6767
bootstrap = new Bootstrap().group(eventLoopGroup).channel(NioSocketChannel.class);
6868
bootstrap.option(ChannelOption.AUTO_READ, false);
6969
SocketAddress socketAddress = new InetSocketAddress("localhost", server.getPort());

0 commit comments

Comments
 (0)