From commits-return-56583-archive-asf-public=cust-asf.ponee.io@activemq.apache.org Fri Jul 19 19:01:52 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 369C8180684 for ; Fri, 19 Jul 2019 21:01:52 +0200 (CEST) Received: (qmail 91664 invoked by uid 500); 19 Jul 2019 19:01:51 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 91645 invoked by uid 99); 19 Jul 2019 19:01:51 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Jul 2019 19:01:51 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 6ACA085E31; Fri, 19 Jul 2019 19:01:51 +0000 (UTC) Date: Fri, 19 Jul 2019 19:01:51 +0000 To: "commits@activemq.apache.org" Subject: [activemq-artemis] 01/03: ARTEMIS-2408 Changing FileDescriptors rule as classRule MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: clebertsuconic@apache.org In-Reply-To: <156356291079.4910.12365655130287483043@gitbox.apache.org> References: <156356291079.4910.12365655130287483043@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: activemq-artemis X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Rev: 89cc07c7d8bf12d83d7a81eb8f71ee9746c5fb8e X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20190719190151.6ACA085E31@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. clebertsuconic pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git commit 89cc07c7d8bf12d83d7a81eb8f71ee9746c5fb8e Author: Clebert Suconic AuthorDate: Thu Jul 18 23:34:33 2019 -0400 ARTEMIS-2408 Changing FileDescriptors rule as classRule --- .../artemis/tests/util/ActiveMQTestBase.java | 5 +- .../artemis/tests/util/NoProcessFilesBehind.java | 98 ++++------------------ 2 files changed, 17 insertions(+), 86 deletions(-) diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java index 19a3919..22b3173 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java @@ -171,8 +171,8 @@ public abstract class ActiveMQTestBase extends Assert { @ClassRule public static ThreadLeakCheckRule leakCheckRule = new ThreadLeakCheckRule(); - @Rule - public NoProcessFilesBehind noProcessFilesBehind = new NoProcessFilesBehind(-1, 1000); + @ClassRule + public static NoProcessFilesBehind noProcessFilesBehind = new NoProcessFilesBehind(1000); /** We should not under any circunstance create data outside of ./target * if you have a test failing because because of this rule for any reason, @@ -279,7 +279,6 @@ public abstract class ActiveMQTestBase extends Assert { @After public void tearDown() throws Exception { - noProcessFilesBehind.tearDown(); closeAllSessionFactories(); closeAllServerLocatorsFactories(); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/NoProcessFilesBehind.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/NoProcessFilesBehind.java index fe28ad7..e04b6ce 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/NoProcessFilesBehind.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/NoProcessFilesBehind.java @@ -19,16 +19,18 @@ package org.apache.activemq.artemis.tests.util; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import com.sun.management.UnixOperatingSystemMXBean; import org.apache.activemq.artemis.nativo.jlibaio.LibaioContext; import org.apache.activemq.artemis.utils.Wait; import org.jboss.logging.Logger; +import org.junit.Assert; import org.junit.rules.TestWatcher; import org.junit.runner.Description; @@ -42,17 +44,13 @@ public class NoProcessFilesBehind extends TestWatcher { /** * -1 on maxVariance means no check */ - public NoProcessFilesBehind(int maxVariance, long maxFiles) { + public NoProcessFilesBehind(long maxFiles) { - this.maxVariance = maxVariance; this.maxFiles = maxFiles; } long fdBefore; - int maxVariance; long maxFiles; - List openFilesBefore; - List openFilesAfter; static OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean(); @@ -68,7 +66,6 @@ public class NoProcessFilesBehind extends TestWatcher { protected void starting(Description description) { LibaioContext.isLoaded(); fdBefore = getOpenFD(); - openFilesBefore = getOpenFiles(true); } public static List getOpenFiles(boolean filtered) { @@ -92,27 +89,6 @@ public class NoProcessFilesBehind extends TestWatcher { return openFiles; } - - private static List getDiffFiles(List xOpenFiles, List yOpenFiles) { - ArrayList diffOpenFiles = new ArrayList<>(); - for (String xOpenFile : xOpenFiles) { - boolean found = false; - Iterator yOpenFilesIterator = yOpenFiles.iterator(); - String xOpenFileS = xOpenFile.replaceAll("\\s+", "\\\\s+"); - - while (yOpenFilesIterator.hasNext() && !found) { - String yOpenFileS = yOpenFilesIterator.next().replaceAll("\\s+", "\\\\s+"); - found = yOpenFileS.equals(xOpenFileS); - } - - if (!found) { - diffOpenFiles.add(xOpenFile); - } - } - - return diffOpenFiles; - } - private static int getProcessId() throws ReflectiveOperationException { java.lang.management.RuntimeMXBean runtime = java.lang.management.ManagementFactory.getRuntimeMXBean(); java.lang.reflect.Field jvmField = runtime.getClass().getDeclaredField("jvm"); @@ -123,9 +99,6 @@ public class NoProcessFilesBehind extends TestWatcher { return (Integer) getProcessIdMethod.invoke(jvm); } - public void tearDown() { - openFilesAfter = getOpenFiles(true); - } @Override protected void failed(Throwable e, Description description) { @@ -135,68 +108,27 @@ public class NoProcessFilesBehind extends TestWatcher { protected void succeeded(Description description) { } - List getVariance() { - - long fdAfter = getOpenFD(); - - long variance = fdAfter - fdBefore; - - if (variance > 0) { - List currOpenFiles = getOpenFiles(true); - List diffOpenFiles = getDiffFiles(currOpenFiles, openFilesBefore); - List skippingOpenFiles = getDiffFiles(currOpenFiles, openFilesAfter); - List leavingOpenFiles = getDiffFiles(diffOpenFiles, skippingOpenFiles); - - return leavingOpenFiles; - } else { - return new ArrayList<>(); - } - } - /** * Override to tear down your specific external resource. */ @Override protected void finished(Description description) { - long fdAfter = getOpenFD(); - List variance = getVariance(); - - if (variance.size() > 0) { - log.warn("test " + description.toString() + " is leaving " + variance.size() + " files open with a total number of files open = " + fdAfter); - System.err.println("test " + description.toString() + " is leaving " + variance.size() + " files open with a total number of files open = " + fdAfter); - - for (String openFile : variance) { - System.err.println(openFile); + Wait.waitFor(() -> getOpenFD() < maxFiles, 5000, 0); + if (getOpenFD() >= maxFiles) { + List openFiles = getOpenFiles(true); + StringWriter stringWriter = new StringWriter(); + PrintWriter printWriter = new PrintWriter(stringWriter); + boolean first = true; + for (String str : openFiles) { + if (!first) printWriter.print(", "); + first = false; + printWriter.print(str); } + Assert.fail("Too many files open (" + maxFiles + "). A possible list: " + stringWriter.toString()); } - - if (maxVariance > 0) { - VarianceCondition varianceCondition = new VarianceCondition(); - Wait.assertTrue("The test " + description.toString() + " is leaving " + varianceCondition.getVarianceSize() + " files open, which is more than " + maxVariance + " max open", varianceCondition, 5000, 0); - } - Wait.assertTrue("Too many open files", () -> getOpenFD() < maxFiles, 5000, 0); } - class VarianceCondition implements Wait.Condition { - private List variance = null; - - public long getVarianceSize() { - if (variance != null) { - return variance.size(); - } else { - return 0; - } - } - - @Override - public boolean isSatisfied() throws Exception { - variance = getVariance(); - - return variance.size() < maxVariance; - } - } - }