You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by kt...@apache.org on 2014/01/07 03:07:18 UTC

[3/6] git commit: ACCUMULO-2128 added test for static clean up utility

ACCUMULO-2128 added test for static clean up utility


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

Branch: refs/heads/master
Commit: 8f9fe41751415ab66ddbce6d6dec058999afc1d3
Parents: c94a73f
Author: Keith Turner <kt...@apache.org>
Authored: Mon Jan 6 20:17:45 2014 -0500
Committer: Keith Turner <kt...@apache.org>
Committed: Mon Jan 6 20:17:59 2014 -0500

----------------------------------------------------------------------
 .../server/test/functional/CleanUpTest.java     | 153 +++++++++++++++++++
 test/system/auto/simple/cleanup.py              |  30 ++++
 2 files changed, 183 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/8f9fe417/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java
----------------------------------------------------------------------
diff --git a/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java b/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java
new file mode 100644
index 0000000..99fbcfe
--- /dev/null
+++ b/src/server/src/main/java/org/apache/accumulo/server/test/functional/CleanUpTest.java
@@ -0,0 +1,153 @@
+/*
+ * 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.accumulo.server.test.functional;
+
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.util.CleanUp;
+
+/**
+ * 
+ */
+public class CleanUpTest extends FunctionalTest {
+
+  @Override
+  public Map<String,String> getInitialConfig() {
+    return Collections.emptyMap();
+  }
+
+  @Override
+  public List<TableSetup> getTablesToCreate() {
+    return Collections.emptyList();
+  }
+
+  @Override
+  public void run() throws Exception {
+
+
+    getConnector().tableOperations().create("test");
+
+    BatchWriter bw = getConnector().createBatchWriter("test", 1000000, 60000, 1);
+
+    Mutation m1 = new Mutation("r1");
+    m1.put("cf1", "cq1", 1, "5");
+
+    bw.addMutation(m1);
+
+    bw.flush();
+
+    Scanner scanner = getConnector().createScanner("test", new Authorizations());
+
+    int count = 0;
+    for (Entry<Key,Value> entry : scanner) {
+      count++;
+      if (!entry.getValue().toString().equals("5")) {
+        throw new Exception("Unexpected value " + entry.getValue());
+      }
+    }
+
+    if (count != 1) {
+      throw new Exception("Unexpected count " + count);
+    }
+
+    if (countThreads() < 2) {
+      printThreadNames();
+      throw new Exception("Not seeing expected threads");
+    }
+
+    CleanUp.shutdownNow();
+
+    Mutation m2 = new Mutation("r2");
+    m2.put("cf1", "cq1", 1, "6");
+
+    try {
+      bw.addMutation(m1);
+      bw.flush();
+      throw new Exception("batch writer did not fail");
+    } catch (Exception e) {
+
+    }
+
+    try {
+      // expect this to fail also, want to clean up batch writer threads
+      bw.close();
+      throw new Exception("batch writer close not fail");
+    } catch (Exception e) {
+
+    }
+
+    try {
+      count = 0;
+      Iterator<Entry<Key,Value>> iter = scanner.iterator();
+      while (iter.hasNext()) {
+        iter.next();
+        count++;
+      }
+      throw new Exception("scanner did not fail");
+    } catch (Exception e) {
+
+    }
+
+    if (countThreads() > 0) {
+      printThreadNames();
+      throw new Exception("Threads did not go away");
+    }
+  }
+
+  private void printThreadNames() {
+    Set<Thread> threads = Thread.getAllStackTraces().keySet();
+    for (Thread thread : threads) {
+      System.out.println("thread name:" + thread.getName());
+      thread.getStackTrace();
+
+    }
+  }
+
+  /**
+   * count threads that should be cleaned up
+   * 
+   */
+  private int countThreads() {
+    int count = 0;
+    Set<Thread> threads = Thread.getAllStackTraces().keySet();
+    for (Thread thread : threads) {
+
+      if (thread.getName().toLowerCase().contains("sendthread") || thread.getName().toLowerCase().contains("eventthread"))
+        count++;
+
+      if (thread.getName().toLowerCase().contains("thrift") && thread.getName().toLowerCase().contains("pool"))
+        count++;
+    }
+
+    return count;
+  }
+
+  @Override
+  public void cleanup() throws Exception {}
+
+}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/8f9fe417/test/system/auto/simple/cleanup.py
----------------------------------------------------------------------
diff --git a/test/system/auto/simple/cleanup.py b/test/system/auto/simple/cleanup.py
new file mode 100755
index 0000000..1ed8aff
--- /dev/null
+++ b/test/system/auto/simple/cleanup.py
@@ -0,0 +1,30 @@
+# 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.
+
+from JavaTest import JavaTest
+
+import unittest
+
+class CleanUpTest(JavaTest):
+    "Test clean up util"
+
+    order = 21
+    testClass="org.apache.accumulo.server.test.functional.CleanUpTest"
+
+
+def suite():
+    result = unittest.TestSuite()
+    result.addTest(CleanUpTest())
+    return result