lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From uschind...@apache.org
Subject svn commit: r1700707 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/CHANGES.txt solr/core/ solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
Date Wed, 02 Sep 2015 05:32:21 GMT
Author: uschindler
Date: Wed Sep  2 05:32:20 2015
New Revision: 1700707

URL: http://svn.apache.org/r1700707
Log:
Merged revision(s) 1700706 from lucene/dev/trunk:
SOLR-7999: SolrRequestParser tests no longer depend on external URLs that may fail to work

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
    lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1700707&r1=1700706&r2=1700707&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Wed Sep  2 05:32:20 2015
@@ -153,6 +153,9 @@ Other Changes
 * SOLR-7966: Solr Admin UI Solr now sets the HTTP header X-Frame-Options to DENY
   to avoid clickjacking. (yonik)
 
+* SOLR-7999: SolrRequestParser tests no longer depend on external URLs
+  that may fail to work.  (Uwe Schindler)
+
 ==================  5.3.0 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java?rev=1700707&r1=1700706&r2=1700707&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
Wed Sep  2 05:32:20 2015
@@ -33,7 +33,7 @@ import java.util.Map;
  * 
  *
  */
-public interface SolrQueryRequest {
+public interface SolrQueryRequest extends AutoCloseable {
 
   /** returns the current request parameters */
   public SolrParams getParams();

Modified: lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java?rev=1700707&r1=1700706&r2=1700707&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
(original)
+++ lucene/dev/branches/branch_5x/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
Wed Sep  2 05:32:20 2015
@@ -24,9 +24,9 @@ import static org.easymock.EasyMock.repl
 
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.SocketTimeoutException;
+import java.io.InputStream;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
@@ -40,6 +40,7 @@ import javax.servlet.ReadListener;
 import javax.servlet.ServletInputStream;
 import javax.servlet.http.HttpServletRequest;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrException;
@@ -122,41 +123,47 @@ public class SolrRequestParserTest exten
   }
   
   @Test
-  @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/SOLR-7999")
   public void testStreamURL() throws Exception
   {
-    String url = "http://www.apache.org/dist/lucene/solr/";
-    byte[] bytes = null;
-    try {
-      URL u = new URL(url);
-      HttpURLConnection connection = (HttpURLConnection)u.openConnection();
-      connection.setConnectTimeout(5000);
-      connection.setReadTimeout(5000);
-      connection.connect();
-      int code = connection.getResponseCode();
-      assumeTrue("wrong response code from server: " + code, 200 == code);
-      bytes = IOUtils.toByteArray( connection.getInputStream());
-    }
-    catch( Exception ex ) {
-      assumeNoException("Unable to connect to " + url + " to run the test.", ex);
-      return;
+    URL url = getClass().getResource("/README");
+    assertNotNull("Missing file 'README' in test-resources root folder.", url);
+    
+    byte[] bytes = IOUtils.toByteArray(url);
+
+    SolrCore core = h.getCore();
+    
+    Map<String,String[]> args = new HashMap<>();
+    args.put( CommonParams.STREAM_URL, new String[] { url.toExternalForm() } );
+    
+    // Make sure it got a single stream in and out ok
+    List<ContentStream> streams = new ArrayList<>();
+    try (SolrQueryRequest req = parser.buildRequestFrom( core, new MultiMapSolrParams( args
), streams )) {
+      assertEquals( 1, streams.size() );
+      try (InputStream in = streams.get(0).getStream()) {
+        assertArrayEquals( bytes, IOUtils.toByteArray( in ) );
+      }
     }
+  }
+  
+  @Test
+  public void testStreamFile() throws Exception
+  {
+    File file = getFile("README");
+    
+    byte[] bytes = FileUtils.readFileToByteArray(file);
 
     SolrCore core = h.getCore();
     
     Map<String,String[]> args = new HashMap<>();
-    args.put( CommonParams.STREAM_URL, new String[] {url} );
+    args.put( CommonParams.STREAM_FILE, new String[] { file.getAbsolutePath() } );
     
     // Make sure it got a single stream in and out ok
     List<ContentStream> streams = new ArrayList<>();
-    SolrQueryRequest req = parser.buildRequestFrom( core, new MultiMapSolrParams( args ),
streams );
-    assertEquals( 1, streams.size() );
-    try {
-      assertArrayEquals( bytes, IOUtils.toByteArray( streams.get(0).getStream() ) );
-    } catch (SocketTimeoutException ex) {
-      assumeNoException("Problems retrieving from " + url + " to run the test.", ex);
-    } finally {
-      req.close();
+    try (SolrQueryRequest req = parser.buildRequestFrom( core, new MultiMapSolrParams( args
), streams )) {
+      assertEquals( 1, streams.size() );
+      try (InputStream in = streams.get(0).getStream()) {
+        assertArrayEquals( bytes, IOUtils.toByteArray( in ) );
+      }
     }
   }
   



Mime
View raw message