mirror of https://github.com/apache/lucene.git
SOLR-5700: Always consumes the response's HttpEntity and cleaned up the test a little.
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1566179 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b22840f3f6
commit
fad3886db8
|
@ -384,7 +384,7 @@ Other Changes
|
|||
(Markus Jelsma, Anshum Gupta via shalin)
|
||||
|
||||
* SOLR-5700: Improve error handling of remote queries (proxied requests).
|
||||
(Greg Chanan via Mark Miller)
|
||||
(Greg Chanan, Steve Davids via Mark Miller)
|
||||
|
||||
================== 4.6.1 ==================
|
||||
|
||||
|
|
|
@ -23,11 +23,11 @@ import org.apache.http.client.HttpClient;
|
|||
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpOptions;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HeaderIterator;
|
||||
import org.apache.http.HttpEntity;
|
||||
|
@ -99,7 +99,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
/**
|
||||
* This filter looks at the incoming URL maps them to handlers defined in solrconfig.xml
|
||||
|
@ -512,6 +511,7 @@ public class SolrDispatchFilter implements Filter
|
|||
private void remoteQuery(String coreUrl, HttpServletRequest req,
|
||||
SolrQueryRequest solrReq, HttpServletResponse resp) throws IOException {
|
||||
HttpRequestBase method = null;
|
||||
HttpEntity httpEntity = null;
|
||||
boolean success = false;
|
||||
try {
|
||||
String urlstr = coreUrl;
|
||||
|
@ -553,7 +553,7 @@ public class SolrDispatchFilter implements Filter
|
|||
|
||||
final HttpResponse response = httpClient.execute(method);
|
||||
int httpStatus = response.getStatusLine().getStatusCode();
|
||||
HttpEntity httpEntity = response.getEntity();
|
||||
httpEntity = response.getEntity();
|
||||
|
||||
resp.setStatus(httpStatus);
|
||||
for (HeaderIterator responseHeaders = response.headerIterator(); responseHeaders.hasNext();) {
|
||||
|
@ -587,6 +587,7 @@ public class SolrDispatchFilter implements Filter
|
|||
SolrException.ErrorCode.SERVER_ERROR,
|
||||
"Error trying to proxy request for url: " + coreUrl, e));
|
||||
} finally {
|
||||
EntityUtils.consumeQuietly(httpEntity);
|
||||
if (method != null && !success) {
|
||||
method.abort();
|
||||
}
|
||||
|
|
|
@ -21,43 +21,15 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import org.apache.lucene.util.LuceneTestCase.Slow;
|
||||
import org.apache.solr.client.solrj.embedded.JettySolrRunner;
|
||||
import org.apache.solr.client.solrj.impl.HttpSolrServer;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.SolrInputDocument;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Verify that remote (proxied) queries return proper error messages
|
||||
*/
|
||||
|
||||
@Slow
|
||||
public class RemoteQueryErrorTest extends AbstractFullDistribZkTestBase {
|
||||
@BeforeClass
|
||||
public static void beforeSuperClass() throws Exception {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterSuperClass() {
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
System.setProperty("numShards", Integer.toString(sliceCount));
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
resetExceptionIgnores();
|
||||
}
|
||||
|
||||
public RemoteQueryErrorTest() {
|
||||
super();
|
||||
|
@ -83,16 +55,15 @@ public class RemoteQueryErrorTest extends AbstractFullDistribZkTestBase {
|
|||
checkForCollection("collection2", numShardsNumReplicaList, null);
|
||||
waitForRecoveriesToFinish("collection2", true);
|
||||
|
||||
HttpSolrServer solrServer = null;
|
||||
for (JettySolrRunner jetty : jettys) {
|
||||
int port = port = jetty.getLocalPort();
|
||||
solrServer = new HttpSolrServer("http://127.0.0.1:" + port + context + "/collection2");
|
||||
for (SolrServer solrServer : clients) {
|
||||
try {
|
||||
SolrInputDocument emptyDoc = new SolrInputDocument();
|
||||
solrServer.add(emptyDoc);
|
||||
fail("Expected unique key exceptoin");
|
||||
} catch (Exception ex) {
|
||||
assert(ex.getMessage().contains("Document is missing mandatory uniqueKey field: id"));
|
||||
} catch (SolrException ex) {
|
||||
assertEquals("Document is missing mandatory uniqueKey field: id", ex.getMessage());
|
||||
} catch(Exception ex) {
|
||||
fail("Expected a SolrException to occur, instead received: " + ex.getClass());
|
||||
} finally {
|
||||
solrServer.shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue