Search in sources :

Example 76 with JettySolrRunner

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

the class MiniSolrCloudClusterTest method testErrorsInShutdown.

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

        @Override
        protected JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {
            JettySolrRunner j = super.stopJettySolrRunner(jetty);
            if (jettyIndex.incrementAndGet() == 2)
                throw new IOException("Fake IOException on shutdown!");
            return j;
        }
    };
    try {
        cluster.shutdown();
        fail("Expected an exception to be thrown on MiniSolrCloudCluster shutdown");
    } catch (Exception e) {
        assertEquals("Error shutting down MiniSolrCloudCluster", e.getMessage());
        assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);
        assertEquals("Fake IOException on shutdown!", e.getSuppressed()[0].getMessage());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 77 with JettySolrRunner

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

the class RulesTest method testPortRule.

@Test
public void testPortRule() throws Exception {
    JettySolrRunner jetty = cluster.getRandomJetty(random());
    String port = Integer.toString(jetty.getLocalPort());
    String rulesColl = "portRuleColl";
    CollectionAdminRequest.createCollectionWithImplicitRouter(rulesColl, "conf", "shard1", 2).setRule("port:" + port).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
    DocCollection rulesCollection = getCollectionState(rulesColl);
    List list = (List) rulesCollection.get("rule");
    assertEquals(1, list.size());
    assertEquals(port, ((Map) list.get(0)).get("port"));
    list = (List) rulesCollection.get("snitch");
    assertEquals(1, list.size());
    assertEquals("ImplicitSnitch", ((Map) list.get(0)).get("class"));
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) List(java.util.List) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Example 78 with JettySolrRunner

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

the class RulesTest method testHostFragmentRule.

@Test
public void testHostFragmentRule() throws Exception {
    String rulesColl = "hostFragment";
    JettySolrRunner jetty = cluster.getRandomJetty(random());
    String host = jetty.getBaseUrl().getHost();
    String[] ipFragments = host.split("\\.");
    String ip_1 = ipFragments[ipFragments.length - 1];
    String ip_2 = ipFragments[ipFragments.length - 2];
    CollectionAdminRequest.createCollectionWithImplicitRouter(rulesColl, "conf", "shard1", 2).setRule("ip_2:" + ip_2, "ip_1:" + ip_1).setSnitch("class:ImplicitSnitch").process(cluster.getSolrClient());
    DocCollection rulesCollection = getCollectionState(rulesColl);
    List<Map> list = (List<Map>) rulesCollection.get("rule");
    assertEquals(2, list.size());
    assertEquals(ip_2, list.get(0).get("ip_2"));
    assertEquals(ip_1, list.get(1).get("ip_1"));
    list = (List) rulesCollection.get("snitch");
    assertEquals(1, list.size());
    assertEquals("ImplicitSnitch", list.get(0).get("class"));
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) List(java.util.List) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) DocCollection(org.apache.solr.common.cloud.DocCollection) Map(java.util.Map) Test(org.junit.Test)

Example 79 with JettySolrRunner

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

the class TestTlogReplica method getSolrRunner.

private List<JettySolrRunner> getSolrRunner(boolean isLeader) {
    List<JettySolrRunner> rs = new ArrayList<>();
    CloudSolrClient cloudClient = cluster.getSolrClient();
    DocCollection docCollection = cloudClient.getZkStateReader().getClusterState().getCollection(collectionName);
    for (JettySolrRunner solrRunner : cluster.getJettySolrRunners()) {
        if (solrRunner.getCoreContainer() == null)
            continue;
        for (SolrCore solrCore : solrRunner.getCoreContainer().getCores()) {
            CloudDescriptor cloudDescriptor = solrCore.getCoreDescriptor().getCloudDescriptor();
            Slice slice = docCollection.getSlice(cloudDescriptor.getShardId());
            Replica replica = docCollection.getReplica(cloudDescriptor.getCoreNodeName());
            if (slice.getLeader() == replica && isLeader) {
                rs.add(solrRunner);
            } else if (slice.getLeader() != replica && !isLeader) {
                rs.add(solrRunner);
            }
        }
    }
    return rs;
}
Also used : JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) SolrCore(org.apache.solr.core.SolrCore) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient)

Example 80 with JettySolrRunner

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

the class TestTlogReplica method getSolrCore.

private List<SolrCore> getSolrCore(boolean isLeader) {
    List<SolrCore> rs = new ArrayList<>();
    CloudSolrClient cloudClient = cluster.getSolrClient();
    DocCollection docCollection = cloudClient.getZkStateReader().getClusterState().getCollection(collectionName);
    for (JettySolrRunner solrRunner : cluster.getJettySolrRunners()) {
        if (solrRunner.getCoreContainer() == null)
            continue;
        for (SolrCore solrCore : solrRunner.getCoreContainer().getCores()) {
            CloudDescriptor cloudDescriptor = solrCore.getCoreDescriptor().getCloudDescriptor();
            Slice slice = docCollection.getSlice(cloudDescriptor.getShardId());
            Replica replica = docCollection.getReplica(cloudDescriptor.getCoreNodeName());
            if (slice.getLeader().equals(replica) && isLeader) {
                rs.add(solrCore);
            } else if (!slice.getLeader().equals(replica) && !isLeader) {
                rs.add(solrCore);
            }
        }
    }
    return rs;
}
Also used : SolrCore(org.apache.solr.core.SolrCore) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) Slice(org.apache.solr.common.cloud.Slice) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Replica(org.apache.solr.common.cloud.Replica) 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