You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2014/04/16 20:03:32 UTC

git commit: ACCUMULO-2675 Clean up creation of temp test files/dirs

Repository: accumulo
Updated Branches:
  refs/heads/1.6.0-SNAPSHOT 77dc446cf -> 9cfa4b582


ACCUMULO-2675 Clean up creation of temp test files/dirs


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

Branch: refs/heads/1.6.0-SNAPSHOT
Commit: 9cfa4b582d9a3e2ab405d80ee7dd4b9860ea2fb3
Parents: 77dc446
Author: Christopher Tubbs <ct...@apache.org>
Authored: Wed Apr 16 14:00:55 2014 -0400
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Wed Apr 16 14:01:37 2014 -0400

----------------------------------------------------------------------
 .../accumulo/core/cli/TestClientOpts.java       | 112 +++++++++----------
 .../core/client/mock/MockNamespacesTest.java    |   3 -
 2 files changed, 55 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/9cfa4b58/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
index eb7f85b..ff49bc0 100644
--- a/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
+++ b/core/src/test/java/org/apache/accumulo/core/cli/TestClientOpts.java
@@ -32,14 +32,21 @@ import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
 import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.security.Authorizations;
-import org.apache.commons.io.FileUtils;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.rules.TestName;
 
 import com.beust.jcommander.JCommander;
-import com.google.common.io.Files;
 
 public class TestClientOpts {
 
+  @Rule
+  public TemporaryFolder tmpDir = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
+
+  @Rule
+  public TestName testName = new TestName();
+
   @Test
   public void test() {
     BatchWriterConfig cfg = new BatchWriterConfig();
@@ -86,66 +93,57 @@ public class TestClientOpts {
 
   @Test
   public void testVolumes() throws IOException {
-    File tmpDir = Files.createTempDir();
-    try {
-      File instanceId = new File(tmpDir, "instance_id");
-      instanceId.mkdir();
-      File uuid = new File(instanceId, UUID.randomUUID().toString());
-      uuid.createNewFile();
-      // document the defaults
-      ClientOpts args = new ClientOpts();
-      File siteXml = File.createTempFile("TestClientOpts", "testVolumes-site.xml");
-      FileWriter fileWriter = new FileWriter(siteXml);
-      fileWriter.append("<configuration>\n");
-
-      fileWriter.append("<property><name>" + Property.INSTANCE_VOLUMES.getKey() + "</name><value>" + tmpDir.toURI().toString() + "</value></property>\n");
-      fileWriter.append("<property><name>" + ClientProperty.INSTANCE_NAME + "</name><value>foo</value></property>\n");
-
-      fileWriter.append("</configuration>\n");
-      fileWriter.close();
-
-      JCommander jc = new JCommander();
-      jc.addObject(args);
-
-      jc.parse("--site-file", siteXml.getAbsolutePath());
-
-      args.getInstance();
-    } finally {
-      FileUtils.deleteQuietly(tmpDir);
-    }
+    File instanceId = tmpDir.newFolder("instance_id");
+    File uuid = new File(instanceId, UUID.randomUUID().toString());
+    uuid.createNewFile();
+    // document the defaults
+    ClientOpts args = new ClientOpts();
+    File siteXml = tmpDir.newFile(this.getClass().getSimpleName() + "-" + testName.getMethodName() + "-site.xml");
+    FileWriter fileWriter = new FileWriter(siteXml);
+    fileWriter.append("<configuration>\n");
+
+    fileWriter.append("<property><name>" + Property.INSTANCE_VOLUMES.getKey() + "</name><value>" + tmpDir.getRoot().toURI().toString()
+        + "</value></property>\n");
+    fileWriter.append("<property><name>" + ClientProperty.INSTANCE_NAME + "</name><value>foo</value></property>\n");
+
+    fileWriter.append("</configuration>\n");
+    fileWriter.close();
+
+    JCommander jc = new JCommander();
+    jc.addObject(args);
+
+    jc.parse("--site-file", siteXml.getAbsolutePath());
+
+    args.getInstance();
   }
 
   @SuppressWarnings("deprecation")
   @Test
   public void testInstanceDir() throws IOException {
-    File tmpDir = Files.createTempDir();
-    try {
-      File instanceId = new File(tmpDir, "instance_id");
-      instanceId.mkdir();
-      File uuid = new File(instanceId, UUID.randomUUID().toString());
-      uuid.createNewFile();
-      // document the defaults
-      ClientOpts args = new ClientOpts();
-      File siteXml = File.createTempFile("TestClientOpts", "testVolumes-site.xml");
-      FileWriter fileWriter = new FileWriter(siteXml);
-      fileWriter.append("<configuration>\n");
-
-      fileWriter.append("<property><name>" + Property.INSTANCE_DFS_DIR.getKey() + "</name><value>" + tmpDir.getAbsolutePath() + "</value></property>\n");
-      fileWriter.append("<property><name>" + Property.INSTANCE_DFS_URI.getKey() + "</name><value>file://</value></property>\n");
-      fileWriter.append("<property><name>" + ClientProperty.INSTANCE_NAME + "</name><value>foo</value></property>\n");
-
-      fileWriter.append("</configuration>\n");
-      fileWriter.close();
-
-      JCommander jc = new JCommander();
-      jc.addObject(args);
-
-      jc.parse("--site-file", siteXml.getAbsolutePath());
-
-      args.getInstance();
-    } finally {
-      FileUtils.deleteQuietly(tmpDir);
-    }
+    File instanceId = tmpDir.newFolder("instance_id");
+    instanceId.mkdir();
+    File uuid = new File(instanceId, UUID.randomUUID().toString());
+    uuid.createNewFile();
+    // document the defaults
+    ClientOpts args = new ClientOpts();
+    File siteXml = tmpDir.newFile(this.getClass().getSimpleName() + "-" + testName.getMethodName() + "-site.xml");
+    FileWriter fileWriter = new FileWriter(siteXml);
+    fileWriter.append("<configuration>\n");
+
+    fileWriter
+        .append("<property><name>" + Property.INSTANCE_DFS_DIR.getKey() + "</name><value>" + tmpDir.getRoot().getAbsolutePath() + "</value></property>\n");
+    fileWriter.append("<property><name>" + Property.INSTANCE_DFS_URI.getKey() + "</name><value>file://</value></property>\n");
+    fileWriter.append("<property><name>" + ClientProperty.INSTANCE_NAME + "</name><value>foo</value></property>\n");
+
+    fileWriter.append("</configuration>\n");
+    fileWriter.close();
+
+    JCommander jc = new JCommander();
+    jc.addObject(args);
+
+    jc.parse("--site-file", siteXml.getAbsolutePath());
+
+    args.getInstance();
   }
 
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/9cfa4b58/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java b/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
index c06df51..db4a12b 100644
--- a/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
+++ b/core/src/test/java/org/apache/accumulo/core/client/mock/MockNamespacesTest.java
@@ -20,7 +20,6 @@ package org.apache.accumulo.core.client.mock;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.io.File;
 import java.util.EnumSet;
 import java.util.HashSet;
 import java.util.Map.Entry;
@@ -49,12 +48,10 @@ import org.apache.accumulo.core.iterators.Filter;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 import org.apache.accumulo.core.security.Authorizations;
 import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
 
 public class MockNamespacesTest {
 
   Random random = new Random();
-  public static TemporaryFolder folder = new TemporaryFolder(new File(System.getProperty("user.dir") + "/target"));
 
   /**
    * This test creates a table without specifying a namespace. In this case, it puts the table into the default namespace.