Skip to content
Snippets Groups Projects
Commit 8362ba07 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XWIKI-18564: Solr remote url configuration retrocompatibility could be better

parent c9f030d8
No related branches found
No related tags found
No related merge requests found
......@@ -51,8 +51,11 @@ public class RemoteSolr extends AbstractSolr implements Initializable
/**
* Default URL to use when none is specified.
*
* @since 13.3RC1
* @since 12.10.7
*/
public static final String DEFAULT_REMOTE_URL = "http://localhost:8983/solr/";
public static final String DEFAULT_BASE_URL = "http://localhost:8983/solr";
/**
* The name of the core containing the XWiki search index.
......@@ -67,15 +70,33 @@ public class RemoteSolr extends AbstractSolr implements Initializable
@Override
public void initialize() throws InitializationException
{
String baseURL = this.configuration.getInstanceConfiguration(TYPE, "baseURL", DEFAULT_REMOTE_URL);
this.rootClient = new HttpSolrClient.Builder(baseURL).build();
String baseURL = this.configuration.getInstanceConfiguration(TYPE, "baseURL", null);
// RETRO COMPATIBILITY: the seach core used to be configured using "solr.remote.url" property
String searchCoreURL = this.configuration.getInstanceConfiguration(TYPE, "url", null);
if (searchCoreURL != null) {
this.clients.put(SolrClientInstance.CORE_NAME, new HttpSolrClient.Builder(searchCoreURL).build());
// If the base URL is not provided try to guess it from the search core URL
if (baseURL == null) {
baseURL = searchCoreURL.substring(0, searchCoreURL.lastIndexOf('/'));
this.logger.warn("[solr.remote.url] property in xwiki.properties file is deprecated, "
+ "use [solr.remote.baseURL] instead");
}
}
// Fallback on the default base URL
if (baseURL == null) {
baseURL = DEFAULT_BASE_URL;
}
this.rootClient = new HttpSolrClient.Builder(baseURL).build();
}
HttpSolrClient getRootClient()
{
return this.rootClient;
}
@Override
......
/*
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.xwiki.search.solr.internal;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.search.solr.Solr;
import org.xwiki.search.solr.internal.api.SolrConfiguration;
import org.xwiki.test.LogLevel;
import org.xwiki.test.annotation.ComponentList;
import org.xwiki.test.junit5.LogCaptureExtension;
import org.xwiki.test.junit5.mockito.ComponentTest;
import org.xwiki.test.junit5.mockito.InjectComponentManager;
import org.xwiki.test.junit5.mockito.MockComponent;
import org.xwiki.test.mockito.MockitoComponentManager;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/**
* Validate {@link RemoteSolr}.
*
* @version $Id$
*/
@ComponentTest
@ComponentList(RemoteSolr.class)
class RemoteSolrTest
{
@RegisterExtension
LogCaptureExtension logCapture = new LogCaptureExtension(LogLevel.INFO);
@MockComponent
SolrConfiguration solrConfiguration;
@InjectComponentManager
MockitoComponentManager componentManager;
@Test
void init() throws ComponentLookupException
{
RemoteSolr solr = this.componentManager.getInstance(Solr.class, RemoteSolr.TYPE);
assertEquals(RemoteSolr.DEFAULT_BASE_URL, solr.getRootClient().getBaseURL());
}
@Test
void initWithBaseURL() throws ComponentLookupException
{
when(this.solrConfiguration.getInstanceConfiguration(RemoteSolr.TYPE, "baseURL", null))
.thenReturn("http://baseurl/");
RemoteSolr solr = this.componentManager.getInstance(Solr.class, RemoteSolr.TYPE);
assertEquals("http://baseurl", solr.getRootClient().getBaseURL());
}
@Test
void initWithURL() throws ComponentLookupException
{
when(this.solrConfiguration.getInstanceConfiguration(RemoteSolr.TYPE, "url", null))
.thenReturn("http://host/xwiki");
RemoteSolr solr = this.componentManager.getInstance(Solr.class, RemoteSolr.TYPE);
assertEquals("http://host", solr.getRootClient().getBaseURL());
assertEquals(
"[solr.remote.url] property in xwiki.properties file is deprecated, use [solr.remote.baseURL] instead",
this.logCapture.getMessage(0));
}
@Test
void initWithURLandBaseURL() throws ComponentLookupException
{
when(this.solrConfiguration.getInstanceConfiguration(RemoteSolr.TYPE, "url", null))
.thenReturn("http://host/xwiki");
when(this.solrConfiguration.getInstanceConfiguration(RemoteSolr.TYPE, "baseURL", null))
.thenReturn("http://baseurl/");
RemoteSolr solr = this.componentManager.getInstance(Solr.class, RemoteSolr.TYPE);
assertEquals("http://baseurl", solr.getRootClient().getBaseURL());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment