|
53 | 53 | import com.rabbitmq.stream.impl.TestUtils.DisabledIfTlsNotEnabled;
|
54 | 54 | import io.netty.channel.Channel;
|
55 | 55 | import io.netty.channel.EventLoopGroup;
|
| 56 | +import io.netty.channel.epoll.EpollEventLoopGroup; |
| 57 | +import io.netty.channel.epoll.EpollSocketChannel; |
56 | 58 | import io.netty.channel.nio.NioEventLoopGroup;
|
57 | 59 | import io.netty.handler.ssl.SslHandler;
|
58 | 60 | import java.net.ConnectException;
|
|
64 | 66 | import java.util.List;
|
65 | 67 | import java.util.Map;
|
66 | 68 | import java.util.Random;
|
| 69 | +import java.util.Set; |
67 | 70 | import java.util.UUID;
|
| 71 | +import java.util.concurrent.ConcurrentHashMap; |
68 | 72 | import java.util.concurrent.CopyOnWriteArrayList;
|
69 | 73 | import java.util.concurrent.CountDownLatch;
|
70 | 74 | import java.util.concurrent.atomic.AtomicBoolean;
|
71 | 75 | import java.util.concurrent.atomic.AtomicLong;
|
72 | 76 | import java.util.function.Supplier;
|
73 | 77 | import java.util.stream.Collectors;
|
| 78 | +import java.util.stream.IntStream; |
74 | 79 | import javax.net.ssl.SNIHostName;
|
75 | 80 | import javax.net.ssl.SSLParameters;
|
76 | 81 | import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
|
|
79 | 84 | import org.junit.jupiter.api.BeforeEach;
|
80 | 85 | import org.junit.jupiter.api.Test;
|
81 | 86 | import org.junit.jupiter.api.TestInfo;
|
| 87 | +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; |
| 88 | +import org.junit.jupiter.api.condition.EnabledOnOs; |
| 89 | +import org.junit.jupiter.api.condition.OS; |
82 | 90 | import org.junit.jupiter.api.extension.ExtendWith;
|
83 | 91 | import org.junit.jupiter.params.ParameterizedTest;
|
84 | 92 | import org.junit.jupiter.params.provider.ValueSource;
|
@@ -615,4 +623,44 @@ void nettyInitializersAreCalled() {
|
615 | 623 | assertThat(bootstrapCalled).isTrue();
|
616 | 624 | assertThat(channelCalled).isTrue();
|
617 | 625 | }
|
| 626 | + |
| 627 | + @Test |
| 628 | + @EnabledOnOs(OS.LINUX) |
| 629 | + @EnabledIfSystemProperty(named = "os.arch", matches = "amd64") |
| 630 | + void nativeEpollWorksOnLinux() { |
| 631 | + int messageCount = 10_000; |
| 632 | + EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(); |
| 633 | + try { |
| 634 | + Set<Channel> channels = ConcurrentHashMap.newKeySet(); |
| 635 | + try (Environment env = |
| 636 | + environmentBuilder |
| 637 | + .netty() |
| 638 | + .eventLoopGroup(epollEventLoopGroup) |
| 639 | + .bootstrapCustomizer(b -> b.channel(EpollSocketChannel.class)) |
| 640 | + .channelCustomizer(ch -> channels.add(ch)) |
| 641 | + .environmentBuilder() |
| 642 | + .build()) { |
| 643 | + Producer producer = env.producerBuilder().stream(this.stream).build(); |
| 644 | + ConfirmationHandler handler = confirmationStatus -> {}; |
| 645 | + IntStream.range(0, messageCount) |
| 646 | + .forEach( |
| 647 | + i -> |
| 648 | + producer.send( |
| 649 | + producer |
| 650 | + .messageBuilder() |
| 651 | + .addData("hello".getBytes(StandardCharsets.UTF_8)) |
| 652 | + .build(), |
| 653 | + handler)); |
| 654 | + CountDownLatch latch = new CountDownLatch(messageCount); |
| 655 | + env.consumerBuilder().stream(this.stream) |
| 656 | + .offset(OffsetSpecification.first()) |
| 657 | + .messageHandler((context, message) -> latch.countDown()) |
| 658 | + .build(); |
| 659 | + assertThat(latchAssert(latch)).completes(); |
| 660 | + } |
| 661 | + assertThat(channels).isNotEmpty().allMatch(ch -> ch instanceof EpollSocketChannel); |
| 662 | + } finally { |
| 663 | + epollEventLoopGroup.shutdownGracefully(0, 0, SECONDS); |
| 664 | + } |
| 665 | + } |
618 | 666 | }
|
0 commit comments