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 2018/03/23 18:45:18 UTC

lucene-solr:branch_7x: SOLR-10075: Move assumes to @BeforeTest instead of changing to if statements to prevent false fails.

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 56009132b -> bf33c0a4c


SOLR-10075: Move assumes to @BeforeTest instead of changing to if statements to prevent false fails.

# Conflicts:
#	solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/bf33c0a4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/bf33c0a4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/bf33c0a4

Branch: refs/heads/branch_7x
Commit: bf33c0a4c0d518a2afd4e06acff06931a61ef16c
Parents: 5600913
Author: markrmiller <ma...@apache.org>
Authored: Fri Mar 23 13:45:11 2018 -0500
Committer: markrmiller <ma...@apache.org>
Committed: Fri Mar 23 13:45:11 2018 -0500

----------------------------------------------------------------------
 .../dataimport/TestNonWritablePersistFile.java  | 59 +++++++++++---------
 1 file changed, 32 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bf33c0a4/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
----------------------------------------------------------------------
diff --git a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
index a7d3d0a..1307927 100644
--- a/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
+++ b/solr/contrib/dataimporthandler/src/test/org/apache/solr/handler/dataimport/TestNonWritablePersistFile.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.commons.io.FileUtils;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -49,49 +50,53 @@ public class TestNonWritablePersistFile extends AbstractDataImportHandlerTestCas
     "</dataConfig>\n";
   private static String tmpSolrHome;
 
+  private static File f;
+
   @BeforeClass
   public static void createTempSolrHomeAndCore() throws Exception {
     tmpSolrHome = createTempDir().toFile().getAbsolutePath();
     FileUtils.copyDirectory(getFile("dih/solr"), new File(tmpSolrHome).getAbsoluteFile());
     initCore("dataimport-solrconfig.xml", "dataimport-schema.xml", 
              new File(tmpSolrHome).getAbsolutePath());
-  }  
-
-  @Test
-  @SuppressWarnings("unchecked")
-  public void testNonWritablePersistFile() throws Exception {
+    
     // See SOLR-2551
     String configDir = h.getCore().getResourceLoader().getConfigDir();
     String filePath = configDir;
     if (configDir != null && !configDir.endsWith(File.separator))
       filePath += File.separator;
     filePath += "dataimport.properties";
-    File f = new File(filePath);
-
-    try {
-      // execute the test only if we are able to set file to read only mode
-      assumeTrue("No dataimport.properties file", f.exists() || f.createNewFile());
-      assumeTrue("dataimport.properties can't be set read only", f.setReadOnly());
-      assumeFalse("dataimport.properties is still writable even though " + 
-                  "marked readonly - test running as superuser?", f.canWrite());
+    f = new File(filePath);
+    // execute the test only if we are able to set file to read only mode
+    assumeTrue("No dataimport.properties file", f.exists() || f.createNewFile());
+    assumeTrue("dataimport.properties can't be set read only", f.setReadOnly());
+    assumeFalse("dataimport.properties is still writable even though " + 
+                "marked readonly - test running as superuser?", f.canWrite());
+  }
+  
+  @AfterClass
+  public static void afterClass() throws Exception {
+    if (f != null) {
+      f.setWritable(true);
+    }
+  }
 
-      ignoreException("Properties is not writable");
+  @Test
+  @SuppressWarnings("unchecked")
+  public void testNonWritablePersistFile() throws Exception {
+    ignoreException("Properties is not writable");
 
-      @SuppressWarnings("rawtypes")
-      List parentRow = new ArrayList();
-      parentRow.add(createMap("id", "1"));
-      MockDataSource.setIterator(FULLIMPORT_QUERY, parentRow.iterator());
+    @SuppressWarnings("rawtypes")
+    List parentRow = new ArrayList();
+    parentRow.add(createMap("id", "1"));
+    MockDataSource.setIterator(FULLIMPORT_QUERY, parentRow.iterator());
       
-      @SuppressWarnings("rawtypes")
-      List childRow = new ArrayList();
-      childRow.add(createMap("desc", "hello"));
-      MockDataSource.setIterator("select * from y where y.A='1'",
+    @SuppressWarnings("rawtypes")
+    List childRow = new ArrayList();
+    childRow.add(createMap("desc", "hello"));
+    MockDataSource.setIterator("select * from y where y.A='1'",
                                  childRow.iterator());
       
-      runFullImport(dataConfig_delta);
-      assertQ(req("id:1"), "//*[@numFound='0']");
-    } finally {
-      f.setWritable(true);
-    }
+    runFullImport(dataConfig_delta);
+    assertQ(req("id:1"), "//*[@numFound='0']");
   }  
 }