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());
}
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);
}
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);
}
}
}
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()));
}
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);
}
Aggregations