You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2024/02/24 18:38:46 UTC

(pinot) branch master updated: enable Netty leak detection (#12483)

This is an automated email from the ASF dual-hosted git repository.

jackie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 6903eca09e enable Netty leak detection (#12483)
6903eca09e is described below

commit 6903eca09e92f419e82ab10f3b0ab47926a3ddcf
Author: sullis <gi...@seansullivan.com>
AuthorDate: Sat Feb 24 10:38:41 2024 -0800

    enable Netty leak detection (#12483)
---
 .../pinot/integration/tests/ClusterTest.java       |  2 +
 .../pinot/integration/tests/NettyLeakListener.java | 58 ++++++++++++++++++++++
 .../integration/tests/NettyTestNGListener.java     | 49 ++++++++++++++++++
 3 files changed, 109 insertions(+)

diff --git a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
index 6c7b487876..dd16ce1f7f 100644
--- a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
+++ b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/ClusterTest.java
@@ -82,6 +82,7 @@ import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.SkipException;
 import org.testng.annotations.DataProvider;
+import org.testng.annotations.Listeners;
 
 import static org.apache.pinot.integration.tests.ClusterIntegrationTestUtils.getBrokerQueryApiUrl;
 import static org.testng.Assert.assertEquals;
@@ -92,6 +93,7 @@ import static org.testng.Assert.assertTrue;
 /**
  * Base class for integration tests that involve a complete Pinot cluster.
  */
+@Listeners(NettyTestNGListener.class)
 public abstract class ClusterTest extends ControllerTest {
   protected static final int DEFAULT_BROKER_PORT = 18099;
   protected static final Random RANDOM = new Random(System.currentTimeMillis());
diff --git a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyLeakListener.java b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyLeakListener.java
new file mode 100644
index 0000000000..7cd74f67b4
--- /dev/null
+++ b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyLeakListener.java
@@ -0,0 +1,58 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.integration.tests;
+
+import io.netty.util.ResourceLeakDetector.LeakListener;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+
+public class NettyLeakListener implements LeakListener {
+  private final List<String> _leaks = new CopyOnWriteArrayList<>();
+
+  @Override
+  public void onLeak(String resourceType, String records) {
+    _leaks.add(resourceType);
+  }
+
+  public int getLeakCount() {
+    return _leaks.size();
+  }
+
+  public void assertZeroLeaks() {
+    assertZeroLeaks(null);
+  }
+
+  public void assertZeroLeaks(String detail) {
+    if (!_leaks.isEmpty()) {
+      StringBuilder message = new StringBuilder("Netty leaks: ");
+      if (detail != null) {
+        message.append(detail);
+        message.append(" ");
+      }
+      message.append(_leaks);
+      throw new IllegalStateException(message.toString());
+    }
+  }
+
+  @Override
+  public String toString() {
+    return "leakCount=" + this.getLeakCount();
+  }
+}
diff --git a/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyTestNGListener.java b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyTestNGListener.java
new file mode 100644
index 0000000000..fd1c69a450
--- /dev/null
+++ b/pinot-integration-test-base/src/test/java/org/apache/pinot/integration/tests/NettyTestNGListener.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.integration.tests;
+
+import io.netty.buffer.ByteBufUtil;
+import org.testng.IInvokedMethod;
+import org.testng.IInvokedMethodListener;
+import org.testng.ITestContext;
+import org.testng.ITestResult;
+
+
+public class NettyTestNGListener implements IInvokedMethodListener {
+  private static final NettyLeakListener NETTY_LEAK_LISTENER;
+  private static final String LEAK_DETECTION_LEVEL_PROP_KEY = "io.netty.leakDetection.level";
+
+  static {
+    if (System.getProperty(LEAK_DETECTION_LEVEL_PROP_KEY) == null) {
+      System.setProperty(LEAK_DETECTION_LEVEL_PROP_KEY, "paranoid");
+    }
+    NETTY_LEAK_LISTENER = new NettyLeakListener();
+    ByteBufUtil.setLeakListener(NETTY_LEAK_LISTENER);
+  }
+
+  @Override
+  public void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) {
+    NETTY_LEAK_LISTENER.assertZeroLeaks();
+  }
+
+  @Override
+  public void afterInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) {
+    NETTY_LEAK_LISTENER.assertZeroLeaks();
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org