Search in sources :

Example 96 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestTolerantUpdateProcessorRandomCloud method createMiniSolrCloudCluster.

@BeforeClass
public static void createMiniSolrCloudCluster() throws Exception {
    final String configName = "solrCloudCollectionConfig";
    final File configDir = new File(TEST_HOME() + File.separator + "collection1" + File.separator + "conf");
    final int numShards = TestUtil.nextInt(random(), 2, TEST_NIGHTLY ? 5 : 3);
    final int repFactor = TestUtil.nextInt(random(), 2, TEST_NIGHTLY ? 5 : 3);
    // at least one server won't have any replicas
    final int numServers = 1 + (numShards * repFactor);
    log.info("Configuring cluster: servers={}, shards={}, repfactor={}", numServers, numShards, repFactor);
    configureCluster(numServers).addConfig(configName, configDir.toPath()).configure();
    TestTolerantUpdateProcessorCloud.assertSpinLoopAllJettyAreRunning(cluster);
    Map<String, String> collectionProperties = new HashMap<>();
    collectionProperties.put("config", "solrconfig-distrib-update-processor-chains.xml");
    // string id 
    collectionProperties.put("schema", "schema15.xml");
    CLOUD_CLIENT = cluster.getSolrClient();
    CLOUD_CLIENT.setDefaultCollection(COLLECTION_NAME);
    CollectionAdminRequest.createCollection(COLLECTION_NAME, configName, numShards, repFactor).setProperties(collectionProperties).process(CLOUD_CLIENT);
    if (NODE_CLIENTS != null) {
        for (HttpSolrClient client : NODE_CLIENTS) {
            client.close();
        }
    }
    NODE_CLIENTS = new ArrayList<HttpSolrClient>(numServers);
    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
        URL jettyURL = jetty.getBaseUrl();
        NODE_CLIENTS.add(getHttpSolrClient(jettyURL.toString() + "/" + COLLECTION_NAME + "/"));
    }
    assertEquals(numServers, NODE_CLIENTS.size());
    ZkStateReader zkStateReader = CLOUD_CLIENT.getZkStateReader();
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(COLLECTION_NAME, zkStateReader, true, true, 330);
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) HashMap(java.util.HashMap) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) File(java.io.File) URL(java.net.URL) BeforeClass(org.junit.BeforeClass)

Example 97 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestCustomStream method setupHarnesses.

private void setupHarnesses() {
    for (final SolrClient client : clients) {
        RestTestHarness harness = new RestTestHarness(() -> ((HttpSolrClient) client).getBaseURL());
        restTestHarnesses.add(harness);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient)

Example 98 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class OneQuery method buildClients.

private void buildClients() throws Exception {
    jetty.start();
    url = buildUrl(jetty.getLocalPort(), "/solr/");
    for (int idx = 0; idx < indexingThreads; ++idx) {
        HttpSolrClient client = getHttpSolrClient(url);
        client.setConnectionTimeout(30000);
        client.setSoTimeout(60000);
        indexingClients.add(client);
    }
    for (int idx = 0; idx < queryThreads; ++idx) {
        HttpSolrClient client = getHttpSolrClient(url);
        client.setConnectionTimeout(30000);
        client.setSoTimeout(30000);
        queryingClients.add(client);
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Example 99 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class TestSolrJ method doCommitPerf.

public void doCommitPerf() throws Exception {
    try (HttpSolrClient client = getHttpSolrClient("http://127.0.0.1:8983/solr")) {
        final RTimer timer = new RTimer();
        for (int i = 0; i < 10000; i++) {
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", Integer.toString(i % 13));
            client.add(doc);
            client.commit(true, true, true);
        }
        System.out.println("TIME: " + timer.getTime());
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrInputDocument(org.apache.solr.common.SolrInputDocument) RTimer(org.apache.solr.util.RTimer)

Example 100 with HttpSolrClient

use of org.apache.solr.client.solrj.impl.HttpSolrClient in project lucene-solr by apache.

the class AbstractFullDistribZkTestBase method reloadCollection.

protected boolean reloadCollection(Replica replica, String testCollectionName) throws Exception {
    ZkCoreNodeProps coreProps = new ZkCoreNodeProps(replica);
    String coreName = coreProps.getCoreName();
    boolean reloadedOk = false;
    try (HttpSolrClient client = getHttpSolrClient(coreProps.getBaseUrl())) {
        CoreAdminResponse statusResp = CoreAdminRequest.getStatus(coreName, client);
        long leaderCoreStartTime = statusResp.getStartTime(coreName).getTime();
        Thread.sleep(1000);
        // send reload command for the collection
        log.info("Sending RELOAD command for " + testCollectionName);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set("action", CollectionParams.CollectionAction.RELOAD.toString());
        params.set("name", testCollectionName);
        QueryRequest request = new QueryRequest(params);
        request.setPath("/admin/collections");
        client.request(request);
        // reload can take a short while
        Thread.sleep(2000);
        // verify reload is done, waiting up to 30 seconds for slow test environments
        long timeout = System.nanoTime() + TimeUnit.NANOSECONDS.convert(30, TimeUnit.SECONDS);
        while (System.nanoTime() < timeout) {
            statusResp = CoreAdminRequest.getStatus(coreName, client);
            long startTimeAfterReload = statusResp.getStartTime(coreName).getTime();
            if (startTimeAfterReload > leaderCoreStartTime) {
                reloadedOk = true;
                break;
            }
            // else ... still waiting to see the reloaded core report a later start time
            Thread.sleep(1000);
        }
    }
    return reloadedOk;
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) QueryRequest(org.apache.solr.client.solrj.request.QueryRequest) CoreAdminResponse(org.apache.solr.client.solrj.response.CoreAdminResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Aggregations

HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)187 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)48 SolrClient (org.apache.solr.client.solrj.SolrClient)46 Test (org.junit.Test)46 SolrQuery (org.apache.solr.client.solrj.SolrQuery)38 ArrayList (java.util.ArrayList)35 Replica (org.apache.solr.common.cloud.Replica)34 SolrInputDocument (org.apache.solr.common.SolrInputDocument)31 IOException (java.io.IOException)26 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)25 Slice (org.apache.solr.common.cloud.Slice)25 QueryRequest (org.apache.solr.client.solrj.request.QueryRequest)24 SolrException (org.apache.solr.common.SolrException)23 SolrServerException (org.apache.solr.client.solrj.SolrServerException)21 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)20 NamedList (org.apache.solr.common.util.NamedList)19 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)18 DocCollection (org.apache.solr.common.cloud.DocCollection)18 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 ZkCoreNodeProps (org.apache.solr.common.cloud.ZkCoreNodeProps)15