Search in sources :

Example 16 with JettySolrRunner

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

the class RulesTest method testInvokeApi.

@Test
public void testInvokeApi() throws Exception {
    JettySolrRunner jetty = cluster.getRandomJetty(random());
    try (SolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
        GenericSolrRequest req = new GenericSolrRequest(GET, "/____v2/node/invoke", new ModifiableSolrParams().add("class", ImplicitSnitch.class.getName()).add("cores", "1").add("freedisk", "1"));
        SimpleSolrResponse rsp = req.process(client);
        assertNotNull(((Map) rsp.getResponse().get(ImplicitSnitch.class.getName())).get("cores"));
        assertNotNull(((Map) rsp.getResponse().get(ImplicitSnitch.class.getName())).get("freedisk"));
    }
}
Also used : GenericSolrRequest(org.apache.solr.client.solrj.request.GenericSolrRequest) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SimpleSolrResponse(org.apache.solr.client.solrj.response.SimpleSolrResponse) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Test(org.junit.Test)

Example 17 with JettySolrRunner

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

the class TestReplicationHandler method doTestDetails.

@Test
public void doTestDetails() throws Exception {
    slaveJetty.stop();
    slave.copyConfigFile(CONF_DIR + "solrconfig-slave.xml", "solrconfig.xml");
    slaveJetty = createJetty(slave);
    slaveClient.close();
    masterClient.close();
    masterClient = createNewSolrClient(masterJetty.getLocalPort());
    slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
    clearIndexWithReplication();
    {
        NamedList<Object> details = getDetails(masterClient);
        assertEquals("master isMaster?", "true", details.get("isMaster"));
        assertEquals("master isSlave?", "false", details.get("isSlave"));
        assertNotNull("master has master section", details.get("master"));
    }
    // check details on the slave a couple of times before & after fetching
    for (int i = 0; i < 3; i++) {
        NamedList<Object> details = getDetails(slaveClient);
        assertNotNull(i + ": " + details);
        assertNotNull(i + ": " + details.toString(), details.get("slave"));
        if (i > 0) {
            rQuery(i, "*:*", slaveClient);
            List replicatedAtCount = (List) ((NamedList) details.get("slave")).get("indexReplicatedAtList");
            int tries = 0;
            while ((replicatedAtCount == null || replicatedAtCount.size() < i) && tries++ < 5) {
                Thread.currentThread().sleep(1000);
                details = getDetails(slaveClient);
                replicatedAtCount = (List) ((NamedList) details.get("slave")).get("indexReplicatedAtList");
            }
            assertNotNull("Expected to see that the slave has replicated" + i + ": " + details.toString(), replicatedAtCount);
            // we can have more replications than we added docs because a replication can legally fail and try 
            // again (sometimes we cannot merge into a live index and have to try again)
            assertTrue("i:" + i + " replicationCount:" + replicatedAtCount.size(), replicatedAtCount.size() >= i);
        }
        assertEquals(i + ": " + "slave isMaster?", "false", details.get("isMaster"));
        assertEquals(i + ": " + "slave isSlave?", "true", details.get("isSlave"));
        assertNotNull(i + ": " + "slave has slave section", details.get("slave"));
        // SOLR-2677: assert not false negatives
        Object timesFailed = ((NamedList) details.get("slave")).get(IndexFetcher.TIMES_FAILED);
        // SOLR-7134: we can have a fail because some mock index files have no checksum, will
        // always be downloaded, and may not be able to be moved into the existing index
        assertTrue(i + ": " + "slave has fetch error count: " + (String) timesFailed, timesFailed == null || ((String) timesFailed).equals("1"));
        if (3 != i) {
            // index & fetch
            index(masterClient, "id", i, "name", "name = " + i);
            masterClient.commit();
            pullFromTo(masterJetty, slaveJetty);
        }
    }
    SolrInstance repeater = null;
    JettySolrRunner repeaterJetty = null;
    SolrClient repeaterClient = null;
    try {
        repeater = new SolrInstance(createTempDir("solr-instance").toFile(), "repeater", masterJetty.getLocalPort());
        repeater.setUp();
        repeaterJetty = createJetty(repeater);
        repeaterClient = createNewSolrClient(repeaterJetty.getLocalPort());
        NamedList<Object> details = getDetails(repeaterClient);
        assertEquals("repeater isMaster?", "true", details.get("isMaster"));
        assertEquals("repeater isSlave?", "true", details.get("isSlave"));
        assertNotNull("repeater has master section", details.get("master"));
        assertNotNull("repeater has slave section", details.get("slave"));
    } finally {
        try {
            if (repeaterJetty != null)
                repeaterJetty.stop();
        } catch (Exception e) {
        /* :NOOP: */
        }
        if (repeaterClient != null)
            repeaterClient.close();
    }
}
Also used : HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient) SolrClient(org.apache.solr.client.solrj.SolrClient) NamedList(org.apache.solr.common.util.NamedList) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrDocumentList(org.apache.solr.common.SolrDocumentList) List(java.util.List) ArrayList(java.util.ArrayList) NamedList(org.apache.solr.common.util.NamedList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrException(org.apache.solr.common.SolrException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with JettySolrRunner

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

the class TestReplicationHandler method createJetty.

private static JettySolrRunner createJetty(SolrInstance instance) throws Exception {
    FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));
    Properties nodeProperties = new Properties();
    nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
    JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").setPort(0).build();
    JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, jettyConfig);
    jetty.start();
    return jetty;
}
Also used : JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Properties(java.util.Properties) File(java.io.File)

Example 19 with JettySolrRunner

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

the class PingRequestHandlerTest method testPingInClusterWithNoHealthCheck.

public void testPingInClusterWithNoHealthCheck() throws Exception {
    MiniSolrCloudCluster miniCluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), buildJettyConfig("/solr"));
    final CloudSolrClient cloudSolrClient = miniCluster.getSolrClient();
    try {
        assertNotNull(miniCluster.getZkServer());
        List<JettySolrRunner> jettys = miniCluster.getJettySolrRunners();
        assertEquals(NUM_SERVERS, jettys.size());
        for (JettySolrRunner jetty : jettys) {
            assertTrue(jetty.isRunning());
        }
        // create collection
        String collectionName = "testSolrCloudCollection";
        String configName = "solrCloudCollectionConfig";
        miniCluster.uploadConfigSet(SolrTestCaseJ4.TEST_PATH().resolve("collection1").resolve("conf"), configName);
        CollectionAdminRequest.createCollection(collectionName, configName, NUM_SHARDS, REPLICATION_FACTOR).process(miniCluster.getSolrClient());
        // Send distributed and non-distributed ping query
        SolrPingWithDistrib reqDistrib = new SolrPingWithDistrib();
        reqDistrib.setDistrib(true);
        SolrPingResponse rsp = reqDistrib.process(cloudSolrClient, collectionName);
        assertEquals(0, rsp.getStatus());
        assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));
        SolrPing reqNonDistrib = new SolrPing();
        rsp = reqNonDistrib.process(cloudSolrClient, collectionName);
        assertEquals(0, rsp.getStatus());
        assertTrue(rsp.getResponseHeader().getBooleanArg(("zkConnected")));
    } finally {
        miniCluster.shutdown();
    }
}
Also used : SolrPingResponse(org.apache.solr.client.solrj.response.SolrPingResponse) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrPing(org.apache.solr.client.solrj.request.SolrPing) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 20 with JettySolrRunner

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

the class TestRestoreCore method createJetty.

private static JettySolrRunner createJetty(TestReplicationHandler.SolrInstance instance) throws Exception {
    FileUtils.copyFile(new File(SolrTestCaseJ4.TEST_HOME(), "solr.xml"), new File(instance.getHomeDir(), "solr.xml"));
    Properties nodeProperties = new Properties();
    nodeProperties.setProperty("solr.data.dir", instance.getDataDir());
    JettyConfig jettyConfig = JettyConfig.builder().setContext("/solr").setPort(0).build();
    JettySolrRunner jetty = new JettySolrRunner(instance.getHomeDir(), nodeProperties, jettyConfig);
    jetty.start();
    return jetty;
}
Also used : JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Properties(java.util.Properties) File(java.io.File)

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