Search in sources :

Example 76 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class TestHashPartitioner method doIndex.

public void doIndex(DocCollection coll, String id, String expectedShard) {
    DocRouter router = coll.getRouter();
    Slice target = router.getTargetSlice(id, null, null, null, coll);
    assertEquals(expectedShard, target.getName());
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocRouter(org.apache.solr.common.cloud.DocRouter)

Example 77 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class TestHashPartitioner method doQuery.

public void doQuery(DocCollection coll, String id, String expectedShards) {
    DocRouter router = coll.getRouter();
    Collection<Slice> slices = router.getSearchSlices(id, null, coll);
    List<String> expectedShardStr = StrUtils.splitSmart(expectedShards, ",", true);
    HashSet<String> expectedSet = new HashSet<>(expectedShardStr);
    HashSet<String> obtainedSet = new HashSet<>();
    for (Slice slice : slices) {
        obtainedSet.add(slice.getName());
    }
    // make sure no repeated slices
    assertEquals(slices.size(), obtainedSet.size());
    assertEquals(expectedSet, obtainedSet);
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocRouter(org.apache.solr.common.cloud.DocRouter) HashSet(java.util.HashSet)

Example 78 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class TestHashPartitioner method testNonConformingCompositeIds.

/** Make sure CompositeIdRouter doesn't throw exceptions for non-conforming IDs */
public void testNonConformingCompositeIds() throws Exception {
    DocRouter router = DocRouter.getDocRouter(CompositeIdRouter.NAME);
    DocCollection coll = createCollection(4, router);
    String[] ids = { "A!B!C!D", "!!!!!!", "A!!!!B", "A!!B!!C", "A/59!B", "A/8/!B/19/", "A!B/-5", "!/130!", "!!A/1000", "A//8!B///10!C////" };
    for (int i = 0; i < ids.length; ++i) {
        try {
            Slice targetSlice = coll.getRouter().getTargetSlice(ids[i], null, null, null, coll);
            assertNotNull(targetSlice);
        } catch (Exception e) {
            throw new Exception("Exception routing id '" + ids[i] + "'", e);
        }
    }
}
Also used : Slice(org.apache.solr.common.cloud.Slice) DocRouter(org.apache.solr.common.cloud.DocRouter) DocCollection(org.apache.solr.common.cloud.DocCollection)

Example 79 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class TestSolrConfigHandlerCloud method getRandomServer.

public static String getRandomServer(CloudSolrClient cloudClient, String collName) {
    DocCollection coll = cloudClient.getZkStateReader().getClusterState().getCollection(collName);
    List<String> urls = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) urls.add("" + replica.get(ZkStateReader.BASE_URL_PROP) + "/" + replica.get(ZkStateReader.CORE_NAME_PROP));
    }
    return urls.get(random().nextInt(urls.size()));
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) Replica(org.apache.solr.common.cloud.Replica)

Example 80 with Slice

use of org.apache.solr.common.cloud.Slice in project lucene-solr by apache.

the class BasicAuthIntegrationTest method getRandomReplica.

public static Replica getRandomReplica(DocCollection coll, Random random) {
    ArrayList<Replica> l = new ArrayList<>();
    for (Slice slice : coll.getSlices()) {
        for (Replica replica : slice.getReplicas()) {
            l.add(replica);
        }
    }
    Collections.shuffle(l, random);
    return l.isEmpty() ? null : l.get(0);
}
Also used : Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) Replica(org.apache.solr.common.cloud.Replica)

Aggregations

Slice (org.apache.solr.common.cloud.Slice)220 Replica (org.apache.solr.common.cloud.Replica)142 DocCollection (org.apache.solr.common.cloud.DocCollection)121 ClusterState (org.apache.solr.common.cloud.ClusterState)81 ArrayList (java.util.ArrayList)79 HashMap (java.util.HashMap)67 ZkStateReader (org.apache.solr.common.cloud.ZkStateReader)50 SolrException (org.apache.solr.common.SolrException)49 Map (java.util.Map)46 Test (org.junit.Test)37 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 HashSet (java.util.HashSet)24 SolrQuery (org.apache.solr.client.solrj.SolrQuery)24 IOException (java.io.IOException)23 NamedList (org.apache.solr.common.util.NamedList)23 List (java.util.List)22 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)22 DocRouter (org.apache.solr.common.cloud.DocRouter)20 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)20