mirror of https://github.com/apache/lucene.git
SOLR-10826: Fix CloudSolrClient to expand the collection parameter correctly
This commit is contained in:
parent
b64c924e3e
commit
74b609cf88
|
@ -321,6 +321,8 @@ Bug Fixes
|
|||
|
||||
* SOLR-10983: Fix DOWNNODE -> queue-work explosion (Scott Blum, Joshua Humphries)
|
||||
|
||||
* SOLR-10826: Fix CloudSolrClient to expand the collection parameter correctly (Tim Owen via Varun Thacker)
|
||||
|
||||
Optimizations
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -1129,7 +1129,7 @@ public class CloudSolrClient extends SolrClient {
|
|||
// validate collections
|
||||
for (String collectionName : rawCollectionsList) {
|
||||
if (stateProvider.getState(collectionName) == null) {
|
||||
String alias = stateProvider.getAlias(collection);
|
||||
String alias = stateProvider.getAlias(collectionName);
|
||||
if (alias != null) {
|
||||
List<String> aliasList = StrUtils.splitSmart(alias, ",", true);
|
||||
collectionNames.addAll(aliasList);
|
||||
|
|
|
@ -85,6 +85,7 @@ import org.slf4j.LoggerFactory;
|
|||
public class CloudSolrClientTest extends SolrCloudTestCase {
|
||||
|
||||
private static final String COLLECTION = "collection1";
|
||||
private static final String COLLECTION2 = "2nd_collection";
|
||||
|
||||
private static final String id = "id";
|
||||
|
||||
|
@ -173,19 +174,49 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
|
|||
|
||||
@Test
|
||||
public void testAliasHandling() throws Exception {
|
||||
|
||||
CollectionAdminRequest.createCollection(COLLECTION2, "conf", 2, 1).process(cluster.getSolrClient());
|
||||
AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTION2, cluster.getSolrClient().getZkStateReader(),
|
||||
false, true, TIMEOUT);
|
||||
|
||||
CloudSolrClient client = getRandomClient();
|
||||
SolrInputDocument doc = new SolrInputDocument("id", "1", "title_s", "my doc");
|
||||
client.add(COLLECTION, doc);
|
||||
client.commit(COLLECTION);
|
||||
|
||||
CollectionAdminRequest.createAlias("testalias", COLLECTION).process(cluster.getSolrClient());
|
||||
|
||||
// ensure that the alias has been registered
|
||||
assertEquals(COLLECTION,
|
||||
new CollectionAdminRequest.ListAliases().process(cluster.getSolrClient()).getAliases().get("testalias"));
|
||||
SolrInputDocument doc2 = new SolrInputDocument("id", "2", "title_s", "my doc too");
|
||||
client.add(COLLECTION2, doc2);
|
||||
client.commit(COLLECTION2);
|
||||
CollectionAdminRequest.createAlias("testalias2", COLLECTION2).process(cluster.getSolrClient());
|
||||
|
||||
CollectionAdminRequest.createAlias("testaliascombined", COLLECTION + "," + COLLECTION2).process(cluster.getSolrClient());
|
||||
|
||||
// ensure that the aliases have been registered
|
||||
Map<String, String> aliases = new CollectionAdminRequest.ListAliases().process(cluster.getSolrClient()).getAliases();
|
||||
assertEquals(COLLECTION, aliases.get("testalias"));
|
||||
assertEquals(COLLECTION2, aliases.get("testalias2"));
|
||||
assertEquals(COLLECTION + "," + COLLECTION2, aliases.get("testaliascombined"));
|
||||
|
||||
assertEquals(1, client.query(COLLECTION, params("q", "*:*")).getResults().getNumFound());
|
||||
assertEquals(1, client.query("testalias", params("q", "*:*")).getResults().getNumFound());
|
||||
|
||||
assertEquals(1, client.query(COLLECTION2, params("q", "*:*")).getResults().getNumFound());
|
||||
assertEquals(1, client.query("testalias2", params("q", "*:*")).getResults().getNumFound());
|
||||
|
||||
assertEquals(2, client.query("testaliascombined", params("q", "*:*")).getResults().getNumFound());
|
||||
|
||||
ModifiableSolrParams paramsWithBothCollections = params("q", "*:*", "collection", COLLECTION + "," + COLLECTION2);
|
||||
assertEquals(2, client.query(null, paramsWithBothCollections).getResults().getNumFound());
|
||||
|
||||
ModifiableSolrParams paramsWithBothAliases = params("q", "*:*", "collection", "testalias,testalias2");
|
||||
assertEquals(2, client.query(null, paramsWithBothAliases).getResults().getNumFound());
|
||||
|
||||
ModifiableSolrParams paramsWithCombinedAlias = params("q", "*:*", "collection", "testaliascombined");
|
||||
assertEquals(2, client.query(null, paramsWithCombinedAlias).getResults().getNumFound());
|
||||
|
||||
ModifiableSolrParams paramsWithMixedCollectionAndAlias = params("q", "*:*", "collection", "testalias," + COLLECTION2);
|
||||
assertEquals(2, client.query(null, paramsWithMixedCollectionAndAlias).getResults().getNumFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue