You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2013/07/05 03:00:51 UTC

svn commit: r1499894 - /lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java

Author: markrmiller
Date: Fri Jul  5 01:00:50 2013
New Revision: 1499894

URL: http://svn.apache.org/r1499894
Log:
SOLR-5007: clean up resource management

Modified:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java?rev=1499894&r1=1499893&r2=1499894&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/search/TestRecoveryHdfs.java Fri Jul  5 01:00:50 2013
@@ -49,19 +49,18 @@ import org.apache.solr.update.HdfsUpdate
 import org.apache.solr.update.UpdateHandler;
 import org.apache.solr.update.UpdateLog;
 import org.apache.solr.update.processor.DistributedUpdateProcessor.DistribPhase;
+import org.apache.solr.util.IOUtils;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.noggit.ObjectBuilder;
 
-import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
 
 @ThreadLeakScope(Scope.NONE) // hdfs mini cluster currently leaks threads
-@ThreadLeakLingering(linger = 0)
-// TODO: longer term this should be combined with TestRecovery somehow
+// TODO: longer term this should be combined with TestRecovery somehow ??
 public class TestRecoveryHdfs extends SolrTestCaseJ4 {
 
   // means that we've seen the leader and have version info (i.e. we are a non-leader replica)
@@ -73,6 +72,8 @@ public class TestRecoveryHdfs extends So
 
   private static String hdfsUri;
   
+  private static FileSystem fs;
+  
   @BeforeClass
   public static void beforeClass() throws Exception {
     dfsCluster = HdfsTestUtil.setupClass(new File(TEMP_DIR,
@@ -80,6 +81,15 @@ public class TestRecoveryHdfs extends So
             + System.currentTimeMillis()).getAbsolutePath());
     hdfsUri = dfsCluster.getFileSystem().getUri().toString();
     
+    try {
+      URI uri = new URI(hdfsUri);
+      fs = FileSystem.newInstance(uri, new Configuration());
+    } catch (IOException e) {
+      throw new RuntimeException(e);
+    } catch (URISyntaxException e) {
+      throw new RuntimeException(e);
+    }
+    
     hdfsDataDir = hdfsUri + "/solr/shard1";
     System.setProperty("solr.data.dir", hdfsUri + "/solr/shard1");
     System.setProperty("solr.ulog.dir", hdfsUri + "/solr/shard1");
@@ -93,10 +103,13 @@ public class TestRecoveryHdfs extends So
     System.clearProperty("solr.data.dir");
     System.clearProperty("test.build.data");
     System.clearProperty("test.cache.data");
+    deleteCore();
+    IOUtils.closeQuietly(fs);
+    fs = null;
+    HdfsTestUtil.teardownClass(dfsCluster);
+    
     hdfsDataDir = null;
     dfsCluster = null;
-    HdfsTestUtil.teardownClass(dfsCluster);
-    FileSystem.closeAll();
   }
 
   // since we make up fake versions in these tests, we can get messed up by a DBQ with a real version
@@ -740,19 +753,6 @@ public class TestRecoveryHdfs extends So
       assertU(commit());
 
       String logDir = h.getCore().getUpdateHandler().getUpdateLog().getLogDir();
- 
-      
-      Configuration conf = new Configuration();
-      conf.setBoolean("fs.hdfs.impl.disable.cache", true);
-      FileSystem fs;
-      try {
-        URI uri = new URI(hdfsUri);
-        fs = FileSystem.newInstance(uri, conf);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      } catch (URISyntaxException e) {
-        throw new RuntimeException(e);
-      }
       
       h.close();
 
@@ -872,18 +872,6 @@ public class TestRecoveryHdfs extends So
       assertU(adoc("id","F1"));
       assertU(adoc("id","F2"));
       assertU(adoc("id","F3"));
-
-      Configuration conf = new Configuration();
-      conf.setBoolean("fs.hdfs.impl.disable.cache", true);
-      FileSystem fs;
-      try {
-        URI uri = new URI(hdfsUri);
-        fs = FileSystem.newInstance(uri, conf);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      } catch (URISyntaxException e) {
-        throw new RuntimeException(e);
-      }
       
       h.close();
       
@@ -944,17 +932,6 @@ public class TestRecoveryHdfs extends So
       assertU(adoc("id","G3"));
 
       h.close();
-      Configuration conf = new Configuration();
-      conf.setBoolean("fs.hdfs.impl.disable.cache", true);
-      FileSystem fs;
-      try {
-        URI uri = new URI(hdfsUri);
-        fs = FileSystem.newInstance(uri, conf);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      } catch (URISyntaxException e) {
-        throw new RuntimeException(e);
-      }
 
       String[] files = HdfsUpdateLog.getLogList(fs, new Path(logDir));
       Arrays.sort(files);
@@ -1027,17 +1004,7 @@ public class TestRecoveryHdfs extends So
       };
 
       String logDir = h.getCore().getUpdateHandler().getUpdateLog().getLogDir();
-      Configuration conf = new Configuration();
-      conf.setBoolean("fs.hdfs.impl.disable.cache", true);
-      FileSystem fs;
-      try {
-        URI uri = new URI(hdfsUri);
-        fs = FileSystem.newInstance(uri, conf);
-      } catch (IOException e) {
-        throw new RuntimeException(e);
-      } catch (URISyntaxException e) {
-        throw new RuntimeException(e);
-      }
+
       clearIndex();
       assertU(commit());
 
@@ -1120,17 +1087,7 @@ public class TestRecoveryHdfs extends So
   // stops the core, removes the transaction logs, restarts the core.
   void deleteLogs() throws Exception {
     String logDir = h.getCore().getUpdateHandler().getUpdateLog().getLogDir();
-    Configuration conf = new Configuration();
-    conf.setBoolean("fs.hdfs.impl.disable.cache", true);
-    FileSystem fs;
-    try {
-      URI uri = new URI(hdfsUri);
-      fs = FileSystem.newInstance(uri, conf);
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    } catch (URISyntaxException e) {
-      throw new RuntimeException(e);
-    }
+
     h.close();
 
     try {