From d025a6d7226ff1a29ab4342fb636522fbc93f211 Mon Sep 17 00:00:00 2001 From: stack Date: Thu, 2 Apr 2020 18:29:05 -0700 Subject: [PATCH] HBASE-24072 Nightlies reporting OutOfMemoryError: unable to create new native thread DEBUG. NOT FOR COMMIT. --- .../org/apache/hadoop/hbase/TestPrintEnv.java | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 hbase-common/src/test/java/org/apache/hadoop/hbase/TestPrintEnv.java diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestPrintEnv.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestPrintEnv.java new file mode 100644 index 0000000000..7fe422597b --- /dev/null +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestPrintEnv.java @@ -0,0 +1,105 @@ +/** + * 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.hadoop.hbase; + +import com.sun.management.UnixOperatingSystemMXBean; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.lang.management.ManagementFactory; +import org.apache.hadoop.hbase.testclassification.SmallTests; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category(SmallTests.class) +public class TestPrintEnv { + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestPrintEnv.class); + private static Object S = new Object(); + private static int COUNT = 0; + + @Test + public void testn() throws Exception { + Process p = Runtime.getRuntime().exec(new String [] {"/bin/bash", "-c", "ulimit -n"}); + int errCode = p.waitFor(); + System.out.println("errCode=" + errCode); + BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = is.readLine()) != null) { + System.out.println(line); + } + is.close(); + is = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = is.readLine()) != null) { + System.out.println(line); + } + } + + @Test + public void testu() throws Exception { + Process p = Runtime.getRuntime().exec(new String [] {"/bin/bash", "-c", "ulimit -u"}); + int errCode = p.waitFor(); + System.out.println("errCode=" + errCode); + BufferedReader is = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line; + while ((line = is.readLine()) != null) { + System.out.println(line); + } + is.close(); + is = new BufferedReader(new InputStreamReader(p.getErrorStream())); + while ((line = is.readLine()) != null) { + System.out.println(line); + } + } + + @Test + public void testfds() throws InterruptedException, IOException { + final UnixOperatingSystemMXBean osMBean = + (UnixOperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); + System.out.println("opendfs: " + osMBean.getOpenFileDescriptorCount()); + System.out.println("maxfds: " + osMBean.getMaxFileDescriptorCount()); + } + + @org.junit.Ignore @Test + public void testthreds() throws InterruptedException, IOException { + try { + Runtime rt = Runtime.getRuntime(); + while (true) { + new Thread(new Runnable() { + public void run() { + synchronized (S) { + COUNT += 1; + System.err.println("New thread #" + COUNT); + } + for (; ; ) { + try { + Thread.sleep(10); + } catch (Exception e) { + System.err.println(e); + } + } + } + }).start(); + Thread.sleep(10); + } + } catch (Throwable t) { + } + } +} -- 2.19.1