From e8d2289a3f822323a771e652925352e7061b4c53 Mon Sep 17 00:00:00 2001 From: Mark Robert Miller Date: Tue, 11 Dec 2012 19:49:29 +0000 Subject: [PATCH] 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 --- solr/CHANGES.txt | 3 + .../client/solrj/impl/LBHttpSolrServer.java | 5 +- .../solrj/impl/LBHttpSolrServerTest.java | 55 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrServerTest.java diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 886eef0ffb1..8ae83ca49e9 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 ---------------------- diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java index a5b244a600b..9180d04588c 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/LBHttpSolrServer.java @@ -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); } diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrServerTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrServerTest.java new file mode 100644 index 00000000000..fd166c6ce53 --- /dev/null +++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/LBHttpSolrServerTest.java @@ -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 HttpSolrServer 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()); + } + +} \ No newline at end of file