You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2015/09/02 07:28:21 UTC
svn commit: r1700706 - in /lucene/dev/trunk/solr: CHANGES.txt
core/src/java/org/apache/solr/request/SolrQueryRequest.java
core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
Author: uschindler
Date: Wed Sep 2 05:28:21 2015
New Revision: 1700706
URL: http://svn.apache.org/r1700706
Log:
SOLR-7999: SolrRequestParser tests no longer depend on external URLs that may fail to work
Modified:
lucene/dev/trunk/solr/CHANGES.txt
lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
lucene/dev/trunk/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1700706&r1=1700705&r2=1700706&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Wed Sep 2 05:28:21 2015
@@ -244,6 +244,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/trunk/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java?rev=1700706&r1=1700705&r2=1700706&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java (original)
+++ lucene/dev/trunk/solr/core/src/java/org/apache/solr/request/SolrQueryRequest.java Wed Sep 2 05:28:21 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/trunk/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java?rev=1700706&r1=1700705&r2=1700706&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java (original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/servlet/SolrRequestParserTest.java Wed Sep 2 05:28:21 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 ) );
+ }
}
}