SOLR-4166: LBHttpSolrServer ignores ResponseParser passed in constructor.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1420362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Robert Miller 2012-12-11 19:49:29 +00:00
parent 5b04be1195
commit e8d2289a3f
3 changed files with 61 additions and 2 deletions

View File

@ -134,6 +134,9 @@ New Features
* SOLR-4030: Allow rate limiting Directory IO based on the IO context.
(Mark Miller, Radim Kolar)
* SOLR-4166: LBHttpSolrServer ignores ResponseParser passed in constructor.
(Steve Molloy via Mark Miller)
Optimizations
----------------------

View File

@ -85,7 +85,7 @@ public class LBHttpSolrServer extends SolrServer {
private final AtomicInteger counter = new AtomicInteger(-1);
private static final SolrQuery solrQuery = new SolrQuery("*:*");
private static final BinaryResponseParser binaryParser = new BinaryResponseParser();
private final ResponseParser parser;
static {
solrQuery.setRows(0);
@ -189,6 +189,7 @@ public class LBHttpSolrServer extends SolrServer {
public LBHttpSolrServer(HttpClient httpClient, ResponseParser parser, String... solrServerUrl)
throws MalformedURLException {
clientIsInternal = (httpClient == null);
this.parser = parser;
if (httpClient == null) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(HttpClientUtil.PROP_USE_RETRY, false);
@ -210,7 +211,7 @@ public class LBHttpSolrServer extends SolrServer {
}
protected HttpSolrServer makeServer(String server) throws MalformedURLException {
return new HttpSolrServer(server, httpClient, binaryParser);
return new HttpSolrServer(server, httpClient, parser);
}

View File

@ -0,0 +1,55 @@
/**
*
*/
package org.apache.solr.client.solrj.impl;
import static org.junit.Assert.*;
import java.net.MalformedURLException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.solr.client.solrj.ResponseParser;
import org.junit.Test;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Test the LBHttpSolrServer.
*/
public class LBHttpSolrServerTest {
/**
* Test method for {@link org.apache.solr.client.solrj.impl.LBHttpSolrServer#LBHttpSolrServer(org.apache.http.client.HttpClient, org.apache.solr.client.solrj.ResponseParser, java.lang.String[])}.
*
* Validate that the parser passed in is used in the <code>HttpSolrServer</code> instances created.
*
* @throws MalformedURLException If URL is invalid, no URL passed, so won't happen.
*/
@Test
public void testLBHttpSolrServerHttpClientResponseParserStringArray() throws MalformedURLException {
LBHttpSolrServer testServer = new LBHttpSolrServer(new DefaultHttpClient(), (ResponseParser) null);
HttpSolrServer httpServer = testServer.makeServer("http://127.0.0.1:8080");
assertNull("Generated server should have null parser.", httpServer.getParser());
ResponseParser parser = new BinaryResponseParser();
testServer = new LBHttpSolrServer(new DefaultHttpClient(), parser);
httpServer = testServer.makeServer("http://127.0.0.1:8080");
assertEquals("Invalid parser passed to generated server.", parser, httpServer.getParser());
}
}