Search in sources :

Example 71 with JettySolrRunner

use of org.apache.solr.client.solrj.embedded.JettySolrRunner 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 72 with JettySolrRunner

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

the class TestTlogReplica method testRecovery.

@SuppressWarnings("unchecked")
public void testRecovery() throws Exception {
    boolean useKill = random().nextBoolean();
    createAndWaitForCollection(1, 0, 2, 0);
    CloudSolrClient cloudClient = cluster.getSolrClient();
    new UpdateRequest().add(sdoc("id", "3")).add(sdoc("id", "4")).commit(cloudClient, collectionName);
    new UpdateRequest().add(sdoc("id", "5")).process(cloudClient, collectionName);
    JettySolrRunner solrRunner = getSolrRunner(false).get(0);
    if (useKill) {
        ChaosMonkey.kill(solrRunner);
    } else {
        ChaosMonkey.stop(solrRunner);
    }
    waitForState("Replica still up", collectionName, activeReplicaCount(0, 1, 0));
    new UpdateRequest().add(sdoc("id", "6")).process(cloudClient, collectionName);
    ChaosMonkey.start(solrRunner);
    waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
    // We skip peerSync, so replica will always trigger commit on leader
    // We query only the non-leader replicas, since we haven't opened a new searcher on the leader yet
    // Should be immediate
    waitForNumDocsInAllReplicas(4, getNonLeaderReplias(collectionName), 0);
    // Options are, wait or retry...
    for (int i = 0; i < 3; i++) {
        UpdateRequest ureq = new UpdateRequest().add(sdoc("id", "7"));
        ureq.setParam("collection", collectionName);
        ureq.setParam(UpdateRequest.MIN_REPFACT, "2");
        NamedList<Object> response = cloudClient.request(ureq);
        if ((Integer) ((NamedList<Object>) response.get("responseHeader")).get(UpdateRequest.REPFACT) >= 2) {
            break;
        }
        LOG.info("Min RF not achieved yet. retrying");
    }
    checkRTG(3, 7, cluster.getJettySolrRunners());
    DirectUpdateHandler2.commitOnClose = false;
    ChaosMonkey.stop(solrRunner);
    waitForState("Replica still up", collectionName, activeReplicaCount(0, 1, 0));
    DirectUpdateHandler2.commitOnClose = true;
    ChaosMonkey.start(solrRunner);
    waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
    checkRTG(3, 7, cluster.getJettySolrRunners());
    // Should be immediate
    waitForNumDocsInAllReplicas(5, getNonLeaderReplias(collectionName), 0);
    cluster.getSolrClient().commit(collectionName);
    // Test replica recovery apply buffer updates
    Semaphore waitingForBufferUpdates = new Semaphore(0);
    Semaphore waitingForReplay = new Semaphore(0);
    RecoveryStrategy.testing_beforeReplayBufferingUpdates = () -> {
        try {
            waitingForReplay.release();
            waitingForBufferUpdates.acquire();
        } catch (InterruptedException e) {
            e.printStackTrace();
            fail("Test interrupted: " + e.getMessage());
        }
    };
    if (useKill) {
        ChaosMonkey.kill(solrRunner);
    } else {
        ChaosMonkey.stop(solrRunner);
    }
    ChaosMonkey.start(solrRunner);
    waitingForReplay.acquire();
    new UpdateRequest().add(sdoc("id", "8")).add(sdoc("id", "9")).process(cloudClient, collectionName);
    waitingForBufferUpdates.release();
    RecoveryStrategy.testing_beforeReplayBufferingUpdates = null;
    waitForState("Replica didn't recover", collectionName, activeReplicaCount(0, 2, 0));
    checkRTG(3, 9, cluster.getJettySolrRunners());
    for (SolrCore solrCore : getSolrCore(false)) {
        RefCounted<IndexWriter> iwRef = solrCore.getUpdateHandler().getSolrCoreState().getIndexWriter(null);
        assertFalse("IndexWriter at replicas must not see updates ", iwRef.get().hasUncommittedChanges());
        iwRef.decref();
    }
}
Also used : UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) NamedList(org.apache.solr.common.util.NamedList) SolrCore(org.apache.solr.core.SolrCore) Semaphore(java.util.concurrent.Semaphore) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) SolrIndexWriter(org.apache.solr.update.SolrIndexWriter) IndexWriter(org.apache.lucene.index.IndexWriter)

Example 73 with JettySolrRunner

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

the class TestTlogReplica method tearDown.

@Override
public void tearDown() throws Exception {
    for (JettySolrRunner jetty : cluster.getJettySolrRunners()) {
        if (!jetty.isRunning()) {
            LOG.warn("Jetty {} not running, probably some bad test. Starting it", jetty.getLocalPort());
            ChaosMonkey.start(jetty);
        }
    }
    if (cluster.getSolrClient().getZkStateReader().getClusterState().getCollectionOrNull(collectionName) != null) {
        LOG.info("tearDown deleting collection");
        CollectionAdminRequest.deleteCollection(collectionName).process(cluster.getSolrClient());
        waitForDeletion(collectionName);
    }
    super.tearDown();
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner)

Example 74 with JettySolrRunner

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

the class MiniSolrCloudClusterTest method testErrorsInStartup.

@Test
public void testErrorsInStartup() throws Exception {
    AtomicInteger jettyIndex = new AtomicInteger();
    MiniSolrCloudCluster cluster = null;
    try {
        cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {

            @Override
            public JettySolrRunner startJettySolrRunner(String name, String context, JettyConfig config) throws Exception {
                if (jettyIndex.incrementAndGet() != 2)
                    return super.startJettySolrRunner(name, context, config);
                throw new IOException("Fake exception on startup!");
            }
        };
        fail("Expected an exception to be thrown from MiniSolrCloudCluster");
    } catch (Exception e) {
        assertEquals("Error starting up MiniSolrCloudCluster", e.getMessage());
        assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);
        assertEquals("Fake exception on startup!", e.getSuppressed()[0].getMessage());
    } finally {
        if (cluster != null)
            cluster.shutdown();
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 75 with JettySolrRunner

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

the class JettySolrRunnerTest method testRestartPorts.

@Test
public void testRestartPorts() throws Exception {
    Path solrHome = createTempDir();
    Files.write(solrHome.resolve("solr.xml"), MiniSolrCloudCluster.DEFAULT_CLOUD_SOLR_XML.getBytes(Charset.defaultCharset()));
    JettyConfig config = JettyConfig.builder().build();
    JettySolrRunner jetty = new JettySolrRunner(solrHome.toString(), config);
    try {
        jetty.start();
        URL url = jetty.getBaseUrl();
        int usedPort = url.getPort();
        jetty.stop();
        jetty.start();
        assertEquals("After restart, jetty port should be the same", usedPort, jetty.getBaseUrl().getPort());
        jetty.stop();
        jetty.start(false);
        assertThat("After restart, jetty port should be different", jetty.getBaseUrl().getPort(), not(usedPort));
    } finally {
        if (jetty.isRunning())
            jetty.stop();
    }
}
Also used : Path(java.nio.file.Path) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) URL(java.net.URL) Test(org.junit.Test)

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