protected void doAccept(String collection, MiniSolrCloudCluster cluster) { try { CollectionAdminRequest .createCollection(collection, "conf", numShards, numReplicas) .setMaxShardsPerNode(maxShardsPerNode) .processAndWait(cluster.getSolrClient(), SolrCloudTestCase.DEFAULT_TIMEOUT); AbstractDistribZkTestBase.waitForRecoveriesToFinish(collection, cluster.getSolrClient().getZkStateReader(), false, true, SolrCloudTestCase.DEFAULT_TIMEOUT); } catch (Exception e) { throw new RuntimeException(e); } }
/** * Create a Solr collection with a given number of shards. * * @param collectionName name of the collection to be created * @param configName name of the config for the collection * @param numShards number of shards in the collection */ public void createCollection(String collectionName, String configName, int numShards) throws IOException { int TIMEOUT = 30; // seconds CloudSolrClient solrClient = new CloudSolrClient.Builder().withZkHost(getZkConnectString()).build(); solrClient.setDefaultCollection(collectionName); CollectionAdminRequest.Create request = CollectionAdminRequest.createCollection( collectionName, configName, numShards, 1); request.setMaxShardsPerNode(numShards); RequestStatusState state; try { state = request.processAndWait(solrClient, TIMEOUT); } catch (SolrServerException | InterruptedException e) { throw new RuntimeException(e); } if (state != RequestStatusState.COMPLETED && state != RequestStatusState.RUNNING) { throw new IllegalStateException("Unexpected state: " + state); } waitForRecoveriesToFinish( collectionName, solrClient.getZkStateReader(), true, true, TIMEOUT); }
@BeforeClass public static void setupCluster() throws Exception { configureCluster(2) .addConfig("conf", SOLR_CONF_DIR.toPath()) .configure(); CollectionAdminRequest.createCollection(COLLECTION, "conf", 2, 1) .processAndWait(cluster.getSolrClient(), TIMEOUT); AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTION, cluster.getSolrClient().getZkStateReader(), false, true, TIMEOUT); }