Search in sources :

Example 96 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class TestCollectionStateWatchers method testWaitForStateWatcherIsRetainedOnPredicateFailure.

@Test
public void testWaitForStateWatcherIsRetainedOnPredicateFailure() throws Exception {
    CloudSolrClient client = cluster.getSolrClient();
    CollectionAdminRequest.createCollection("falsepredicate", "config", 4, 1).processAndWait(client, MAX_WAIT_TIMEOUT);
    client.waitForState("falsepredicate", MAX_WAIT_TIMEOUT, TimeUnit.SECONDS, (n, c) -> DocCollection.isFullyActive(n, c, 4, 1));
    final CountDownLatch firstCall = new CountDownLatch(1);
    // stop a node, then add a watch waiting for all nodes to be back up
    JettySolrRunner node1 = cluster.stopJettySolrRunner(random().nextInt(cluster.getJettySolrRunners().size()));
    Future<Boolean> future = waitInBackground("falsepredicate", MAX_WAIT_TIMEOUT, TimeUnit.SECONDS, (liveNodes, collectionState) -> {
        firstCall.countDown();
        return DocCollection.isFullyActive(liveNodes, collectionState, 4, 1);
    });
    // first, stop another node; the watch should not be fired after this!
    JettySolrRunner node2 = cluster.stopJettySolrRunner(random().nextInt(cluster.getJettySolrRunners().size()));
    // now start them both back up
    cluster.startJettySolrRunner(node1);
    assertTrue("CollectionStateWatcher not called after 30 seconds", firstCall.await(MAX_WAIT_TIMEOUT, TimeUnit.SECONDS));
    cluster.startJettySolrRunner(node2);
    Boolean result = future.get();
    assertTrue("Did not see a fully active cluster after 30 seconds", result);
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CountDownLatch(java.util.concurrent.CountDownLatch) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) Test(org.junit.Test)

Example 97 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class SolrJettyTestBase method createJetty.

public static JettySolrRunner createJetty(String solrHome, Properties nodeProperties, JettyConfig jettyConfig) throws Exception {
    initCore(null, null, solrHome);
    Path coresDir = createTempDir().resolve("cores");
    Properties props = new Properties();
    props.setProperty("name", DEFAULT_TEST_CORENAME);
    props.setProperty("configSet", "collection1");
    props.setProperty("config", "${solrconfig:solrconfig.xml}");
    props.setProperty("schema", "${schema:schema.xml}");
    writeCoreProperties(coresDir.resolve("core"), props, "RestTestBase");
    Properties nodeProps = new Properties(nodeProperties);
    nodeProps.setProperty("coreRootDirectory", coresDir.toString());
    nodeProps.setProperty("configSetBaseDir", solrHome);
    jetty = new JettySolrRunner(solrHome, nodeProps, jettyConfig);
    jetty.start();
    port = jetty.getLocalPort();
    log.info("Jetty Assigned Port#" + port);
    return jetty;
}
Also used : Path(java.nio.file.Path) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Properties(java.util.Properties)

Example 98 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class BaseDistributedSearchTestCase method createServers.

protected void createServers(int numShards) throws Exception {
    System.setProperty("configSetBaseDir", getSolrHome());
    controlJetty = createControlJetty();
    controlClient = createNewSolrClient(controlJetty.getLocalPort());
    shardsArr = new String[numShards];
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < numShards; i++) {
        if (sb.length() > 0)
            sb.append(',');
        final String shardname = "shard" + i;
        Path jettyHome = testDir.toPath().resolve(shardname);
        File jettyHomeFile = jettyHome.toFile();
        seedSolrHome(jettyHomeFile);
        seedCoreRootDirWithDefaultTestCore(jettyHome.resolve("cores"));
        JettySolrRunner j = createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
        jettys.add(j);
        clients.add(createNewSolrClient(j.getLocalPort()));
        String shardStr = buildUrl(j.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME;
        shardsArr[i] = shardStr;
        sb.append(shardStr);
    }
    shards = sb.toString();
}
Also used : Path(java.nio.file.Path) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) File(java.io.File)

Example 99 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class BaseDistributedSearchTestCase method createControlJetty.

protected JettySolrRunner createControlJetty() throws Exception {
    Path jettyHome = testDir.toPath().resolve("control");
    File jettyHomeFile = jettyHome.toFile();
    seedSolrHome(jettyHomeFile);
    seedCoreRootDirWithDefaultTestCore(jettyHome.resolve("cores"));
    JettySolrRunner jetty = createJetty(jettyHomeFile, null, null, getSolrConfigFile(), getSchemaFile());
    return jetty;
}
Also used : Path(java.nio.file.Path) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) File(java.io.File)

Example 100 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner in project lucene-solr by apache.

the class TestAuthenticationFramework method collectionCreateSearchDelete.

public void collectionCreateSearchDelete(MiniSolrCloudCluster miniCluster) throws Exception {
    final String collectionName = "testcollection";
    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
    assertNotNull(miniCluster.getZkServer());
    List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
    assertEquals(NUM_SERVERS, jettys.size());
    for (JettySolrRunner jetty : jettys) {
        assertTrue(jetty.isRunning());
    }
    // create collection
    log.info("#### Creating a collection");
    final String asyncId = (random().nextBoolean() ? null : "asyncId(" + collectionName + ".create)=" + random().nextInt());
    createCollection(miniCluster, collectionName, asyncId);
    ZkStateReader zkStateReader = miniCluster.getSolrClient().getZkStateReader();
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
    // modify/query collection
    log.info("#### updating a querying collection");
    cloudSolrClient.setDefaultCollection(collectionName);
    SolrInputDocument doc = new SolrInputDocument();
    doc.setField("id", "1");
    cloudSolrClient.add(doc);
    cloudSolrClient.commit();
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    QueryResponse rsp = cloudSolrClient.query(query);
    assertEquals(1, rsp.getResults().getNumFound());
    // delete the collection we created earlier
    CollectionAdminRequest.deleteCollection(collectionName).process(miniCluster.getSolrClient());
    // create it again
    String asyncId2 = (random().nextBoolean() ? null : "asyncId(" + collectionName + ".create)=" + random().nextInt());
    createCollection(miniCluster, collectionName, asyncId2);
    AbstractDistribZkTestBase.waitForRecoveriesToFinish(collectionName, zkStateReader, true, true, 330);
    // check that there's no left-over state
    assertEquals(0, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
    cloudSolrClient.add(doc);
    cloudSolrClient.commit();
    assertEquals(1, cloudSolrClient.query(new SolrQuery("*:*")).getResults().getNumFound());
}
Also used : ZkStateReader(org.apache.solr.common.cloud.ZkStateReader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrQuery(org.apache.solr.client.solrj.SolrQuery) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Aggregations

JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)137 Test (org.junit.Test)52 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)29 Replica (org.apache.solr.common.cloud.Replica)28 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)25 SolrInputDocument (org.apache.solr.common.SolrInputDocument)20 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)20 File (java.io.File)19 SolrQuery (org.apache.solr.client.solrj.SolrQuery)19 DocCollection (org.apache.solr.common.cloud.DocCollection)18 Slice (org.apache.solr.common.cloud.Slice)18 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)15 Properties (java.util.Properties)15 SolrClient (org.apache.solr.client.solrj.SolrClient)15 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)15 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)15 CoreContainer (org.apache.solr.core.CoreContainer)14 BeforeClass (org.junit.BeforeClass)14 ClusterState (org.apache.solr.common.cloud.ClusterState)13