accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhava...@apache.org
Subject [2/3] git commit: ACCUMULO-2429 Add shell shutdown for thread cleanup
Date Fri, 07 Mar 2014 16:27:46 GMT
ACCUMULO-2429 Add shell shutdown for thread cleanup

The JLine 2 ConsoleReader used by Shell spawns a thread which should be cleaned up when
done with the Shell. Otherwise, the thread leaks, taking up resources when the shell is
used programmatically. This commit adds a shutdown() method to Shell for cleaning up the
thread. This enables ShellServerIT to pass reliably and not flood the OS with leaked
threads.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/8acdf534
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/8acdf534
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/8acdf534

Branch: refs/heads/master
Commit: 8acdf534ceb92627075a1417e61c5e14790ee9d8
Parents: a4e5626
Author: Bill Havanki <bhavanki@cloudera.com>
Authored: Wed Mar 5 11:23:32 2014 -0500
Committer: Bill Havanki <bhavanki@cloudera.com>
Committed: Fri Mar 7 11:26:11 2014 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/core/util/shell/Shell.java    | 14 ++++++++++++--
 .../accumulo/core/util/shell/ShellConfigTest.java     |  1 +
 .../core/util/shell/ShellSetInstanceTest.java         |  1 +
 .../apache/accumulo/core/util/shell/ShellTest.java    |  6 ++++++
 .../java/org/apache/accumulo/test/ShellServerIT.java  | 10 +++++-----
 5 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/8acdf534/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
index 850816c..420d465 100644
--- a/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
+++ b/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
@@ -458,9 +458,13 @@ public class Shell extends ShellOptions {
 
   public static void main(String args[]) throws IOException {
     Shell shell = new Shell();
-    shell.config(args);
+    try {
+      shell.config(args);
 
-    System.exit(shell.start());
+      System.exit(shell.start());
+    } finally {
+      shell.shutdown();
+    }
   }
 
   public int start() throws IOException {
@@ -555,6 +559,12 @@ public class Shell extends ShellOptions {
     }
   }
 
+  public void shutdown() {
+    if (reader != null) {
+      reader.shutdown();
+    }
+  }
+
   public void printInfo() throws IOException {
     reader.print("\n" + SHELL_DESCRIPTION + "\n" + "- \n" + "- version: " + Constants.VERSION
+ "\n" + "- instance name: "
         + connector.getInstance().getInstanceName() + "\n" + "- instance id: " + connector.getInstance().getInstanceID()
+ "\n" + "- \n"

http://git-wip-us.apache.org/repos/asf/accumulo/blob/8acdf534/core/src/test/java/org/apache/accumulo/core/util/shell/ShellConfigTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellConfigTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellConfigTest.java
index df4d817..c9914da 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellConfigTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellConfigTest.java
@@ -53,6 +53,7 @@ public class ShellConfigTest {
   
   @After
   public void teardown() throws Exception {
+    shell.shutdown();
     output.clear();
     System.setOut(out);
   }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/8acdf534/core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
index 5a6cc8a..2929b04 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellSetInstanceTest.java
@@ -99,6 +99,7 @@ public class ShellSetInstanceTest {
   }
   @After
   public void tearDown() {
+    shell.shutdown();
     SiteConfiguration.clearInstance();
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/8acdf534/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
index bf203f7..4771f2c 100644
--- a/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/util/shell/ShellTest.java
@@ -30,6 +30,7 @@ import jline.console.ConsoleReader;
 
 import org.apache.accumulo.core.util.format.DateStringFormatter;
 import org.apache.log4j.Level;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -108,6 +109,11 @@ public class ShellTest {
     shell.config("--fake", "-u", "test", "-p", "secret");
   }
 
+  @After
+  public void teardown() {
+    shell.shutdown();
+  }
+
   void assertGoodExit(String s, boolean stringPresent) {
     Shell.log.debug(output.get());
     assertEquals(shell.getExitCode(), 0);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/8acdf534/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
index da094e8..7a1121f 100644
--- a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
@@ -185,11 +185,6 @@ public class ShellServerIT extends SimpleMacIT {
     exec("quit", true);
     shell.start();
     shell.setExit(false);
-
-    traceProcess = getStaticCluster().exec(TraceServer.class);
-
-    // give the tracer some time to start
-    UtilWaitThread.sleep(1000);
   }
 
   @AfterClass
@@ -210,6 +205,11 @@ public class ShellServerIT extends SimpleMacIT {
     }
   }
 
+  @After
+  public void tearDownShell() {
+    shell.shutdown();
+  }
+
   @Test(timeout = 60000)
   public void exporttableImporttable() throws Exception {
     final String table = name.getMethodName(), table2 = table + "2";


Mime
View raw message