Netty41NativeClientTest.groovy 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright The OpenTelemetry Authors
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. import io.netty.channel.Channel
  6. import io.netty.channel.EventLoopGroup
  7. import io.netty.channel.epoll.Epoll
  8. import io.netty.channel.epoll.EpollEventLoopGroup
  9. import io.netty.channel.epoll.EpollSocketChannel
  10. import io.netty.channel.kqueue.KQueue
  11. import io.netty.channel.kqueue.KQueueEventLoopGroup
  12. import io.netty.channel.kqueue.KQueueSocketChannel
  13. import org.junit.jupiter.api.Assumptions
  14. // netty client test with epoll/kqueue native library
  15. class Netty41NativeClientTest extends Netty41ClientTest {
  16. EventLoopGroup buildEventLoopGroup() {
  17. // linux
  18. if (Epoll.isAvailable()) {
  19. return new EpollEventLoopGroup()
  20. }
  21. // mac
  22. if (KQueueHelper.isAvailable()) {
  23. return new KQueueEventLoopGroup()
  24. }
  25. // skip test when native library was not found
  26. Assumptions.assumeTrue(false, "Native library was not found")
  27. return super.buildEventLoopGroup()
  28. }
  29. @Override
  30. Class<Channel> getChannelClass() {
  31. if (Epoll.isAvailable()) {
  32. return EpollSocketChannel
  33. }
  34. if (KQueueHelper.isAvailable()) {
  35. return KQueueSocketChannel
  36. }
  37. return null
  38. }
  39. static class KQueueHelper {
  40. static boolean isAvailable() {
  41. try {
  42. return KQueue.isAvailable()
  43. } catch (NoClassDefFoundError error) {
  44. // kqueue is available only in latest dep tests
  45. // in regular tests we only have a compile time dependency because kqueue support was added
  46. // after 4.1.0
  47. return false
  48. }
  49. }
  50. }
  51. }