vvova15 commented on code in PR #4260: URL: https://github.com/apache/solr/pull/4260#discussion_r3037054731
########## solr/solrj/src/test/org/apache/solr/client/solrj/impl/CloudClientConnectionStringTest.java: ########## @@ -0,0 +1,185 @@ +/* + * 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. + */ +package org.apache.solr.client.solrj.impl; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import org.apache.solr.SolrTestCase; +import org.junit.Assert; +import org.junit.Test; + +public class CloudClientConnectionStringTest extends SolrTestCase { + + private static <T> boolean collectionEqual(Collection<T> coll, Collection<T> coll2) { + return coll.size() == coll2.size() + && Set.copyOf(coll).containsAll(coll2) + && Set.copyOf(coll2).containsAll(coll); + } + + @Test + public void testBuildQuorumForZk() { + CloudClientConnectionString parsed = + CloudClientConnectionString.parse("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181/solr"); + Assert.assertTrue(parsed.isZk()); + List<String> expectedQuorum = List.of("zookeeper1:2181", "zookeeper2:2181", "zookeeper3:2181"); + Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems())); + Assert.assertEquals("/solr", parsed.zkChroot()); + } + + @Test + public void testBuildQuorumForZkIpV4() { + CloudClientConnectionString parsed = + CloudClientConnectionString.parse( + "192.194.10.10:2181,192.194.10.11:2181,192.194.10.12:2181/solr"); + Assert.assertTrue(parsed.isZk()); + List<String> expectedQuorum = + List.of("192.194.10.10:2181", "192.194.10.11:2181", "192.194.10.12:2181"); + Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems())); + Assert.assertEquals("/solr", parsed.zkChroot()); + } + + @Test + public void testBuildQuorumForZkIpV6() { + CloudClientConnectionString parsed = + CloudClientConnectionString.parse( + "[2001:db8:85a3::8a2e:370:7334]:2181," + + "[2001:db8:85a3::8a2e:370:7335]:2181," + + "[2001:db8:85a3::8a2e:370:7336]:2181/solr"); + Assert.assertTrue(parsed.isZk()); + List<String> expectedQuorum = + List.of( + "[2001:db8:85a3::8a2e:370:7334]:2181", + "[2001:db8:85a3::8a2e:370:7335]:2181", + "[2001:db8:85a3::8a2e:370:7336]:2181"); + Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems())); + Assert.assertEquals("/solr", parsed.zkChroot()); + } + + @Test + public void testBuildQuorumForZkNoChroot() { + CloudClientConnectionString parsed = + CloudClientConnectionString.parse("zookeeper1:2181,zookeeper2:2181,zookeeper3:2181"); + Assert.assertTrue(parsed.isZk()); + List<String> expectedQuorum = List.of("zookeeper1:2181", "zookeeper2:2181", "zookeeper3:2181"); + Assert.assertTrue(collectionEqual(expectedQuorum, parsed.quorumItems())); + Assert.assertNull(parsed.zkChroot()); + } + + @Test + public void testBuildQuorumForZkWithSpaces() { + CloudClientConnectionString parsed = + CloudClientConnectionString.parse( + " zookeeper1:2181 , zookeeper2:2181 , zookeeper3:2181 /solr "); Review Comment: Okay, I've removed all the unnecessary validation. ########## solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java: ########## @@ -241,6 +241,44 @@ public Builder(ClusterStateProvider stateProvider) { this.stateProvider = stateProvider; } + /** + * Creates a client builder based on a connection string of 2 possible formats: + * + * <ul> + * <li>ZooKeeper connection string (optionally with chroot), e.g. {@code + * zk1:2181,zk2:2181,zk3:2181/solr} + * <li>Comma-separated list of Solr node base URLs (HTTP or HTTPS), e.g. {@code + * http://solr1:8983/solr,http://solr2:8983/solr} + * </ul> + * + * <p>Usage examples: + * + * <pre>{@code + * // ZooKeeper with chroot + * new CloudSolrClient.Builder("zk1:2181,zk2:2181,zk3:2181/solr"); + * + * // ZooKeeper without chroot + * new CloudSolrClient.Builder("zk1:2181,zk2:2181,zk3:2181"); + * + * // Direct HTTPS connections + * new CloudSolrClient.Builder("https://solr1:8983/solr,https://solr2:8983/solr"); + * }</pre> + * + * @param connectionString a string specifying either ZooKeeper connection string or HTTP(S) + * Solr URLs + * @throws IllegalArgumentException if string is null, empty, or malformed + * @since 11.0.0 Review Comment: fixed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
