Search in sources :

Example 26 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class SolrShardReporterTest method test.

@Test
public void test() throws Exception {
    waitForRecoveriesToFinish("control_collection", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
    waitForRecoveriesToFinish("collection1", jettys.get(0).getCoreContainer().getZkController().getZkStateReader(), false);
    printLayout();
    // wait for at least two reports
    Thread.sleep(10000);
    ClusterState state = jettys.get(0).getCoreContainer().getZkController().getClusterState();
    for (JettySolrRunner jetty : jettys) {
        CoreContainer cc = jetty.getCoreContainer();
        SolrMetricManager metricManager = cc.getMetricManager();
        for (final String coreName : cc.getLoadedCoreNames()) {
            CoreDescriptor cd = cc.getCoreDescriptor(coreName);
            if (cd.getCloudDescriptor() == null) {
                // not a cloud collection
                continue;
            }
            CloudDescriptor cloudDesc = cd.getCloudDescriptor();
            DocCollection docCollection = state.getCollection(cloudDesc.getCollectionName());
            String replicaName = SolrCoreMetricManager.parseReplicaName(cloudDesc.getCollectionName(), coreName);
            if (replicaName == null) {
                replicaName = cloudDesc.getCoreNodeName();
            }
            String registryName = SolrCoreMetricManager.createRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId(), replicaName, null);
            String leaderRegistryName = SolrCoreMetricManager.createLeaderRegistryName(true, cloudDesc.getCollectionName(), cloudDesc.getShardId());
            boolean leader = cloudDesc.isLeader();
            Slice slice = docCollection.getSlice(cloudDesc.getShardId());
            int numReplicas = slice.getReplicas().size();
            if (leader) {
                assertTrue(metricManager.registryNames() + " doesn't contain " + leaderRegistryName, metricManager.registryNames().contains(leaderRegistryName));
                Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
                metrics.forEach((k, v) -> {
                    assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
                    AggregateMetric am = (AggregateMetric) v;
                    if (!k.startsWith("REPLICATION.peerSync")) {
                        assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), numReplicas, am.size());
                    }
                });
            } else {
                assertFalse(metricManager.registryNames() + " contains " + leaderRegistryName + " but it's not a leader!", metricManager.registryNames().contains(leaderRegistryName));
                Map<String, Metric> metrics = metricManager.registry(leaderRegistryName).getMetrics();
                metrics.forEach((k, v) -> {
                    assertTrue("Unexpected type of " + k + ": " + v.getClass().getName() + ", " + v, v instanceof AggregateMetric);
                    AggregateMetric am = (AggregateMetric) v;
                    if (!k.startsWith("REPLICATION.peerSync")) {
                        assertEquals(coreName + "::" + registryName + "::" + k + ": " + am.toString(), 1, am.size());
                    }
                });
            }
            assertTrue(metricManager.registryNames() + " doesn't contain " + registryName, metricManager.registryNames().contains(registryName));
        }
    }
    SolrMetricManager metricManager = controlJetty.getCoreContainer().getMetricManager();
    assertTrue(metricManager.registryNames().contains("solr.cluster"));
}
Also used : ClusterState(org.apache.solr.common.cloud.ClusterState) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CoreDescriptor(org.apache.solr.core.CoreDescriptor) AggregateMetric(org.apache.solr.metrics.AggregateMetric) CloudDescriptor(org.apache.solr.cloud.CloudDescriptor) CoreContainer(org.apache.solr.core.CoreContainer) Slice(org.apache.solr.common.cloud.Slice) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric) DocCollection(org.apache.solr.common.cloud.DocCollection) Test(org.junit.Test)

Example 27 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class SolrGraphiteReporterTest method testReporter.

@Test
public void testReporter() throws Exception {
    int jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0;
    Path home = Paths.get(TEST_HOME());
    // define these properties, they are used in solrconfig.xml
    System.setProperty("solr.test.sys.prop1", "propone");
    System.setProperty("solr.test.sys.prop2", "proptwo");
    MockGraphite mock = new MockGraphite();
    try {
        mock.start();
        Thread.sleep(1000);
        // define the port where MockGraphite is running
        System.setProperty("mock-graphite-port", String.valueOf(mock.port));
        String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-graphitereporter.xml").toFile(), "UTF-8");
        NodeConfig cfg = SolrXmlConfig.fromString(new SolrResourceLoader(home), solrXml);
        CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.getAbsolutePath(), "solrconfig.xml", "schema.xml"));
        h.coreName = DEFAULT_TEST_CORENAME;
        SolrMetricManager metricManager = cc.getMetricManager();
        Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node");
        assertEquals(1 + jmxReporter, reporters.size());
        SolrMetricReporter reporter = reporters.get("test");
        assertNotNull(reporter);
        assertTrue(reporter instanceof SolrGraphiteReporter);
        Thread.sleep(5000);
        assertTrue(mock.lines.size() >= 3);
        String[] frozenLines = (String[]) mock.lines.toArray(new String[mock.lines.size()]);
        for (String line : frozenLines) {
            assertTrue(line, line.startsWith("test.solr.node.CONTAINER.cores."));
        }
    } finally {
        mock.close();
    }
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) TestHarness(org.apache.solr.util.TestHarness) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) NodeConfig(org.apache.solr.core.NodeConfig) SolrMetricReporter(org.apache.solr.metrics.SolrMetricReporter) Test(org.junit.Test)

Example 28 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class TestSubQueryTransformerCrossCore method beforeTests.

@BeforeClass
public static void beforeTests() throws Exception {
    // schema12 doesn't support _version_
    System.setProperty("enable.update.log", "false");
    initCore("solrconfig-basic.xml", "schema-docValuesJoin.xml");
    final CoreContainer coreContainer = h.getCoreContainer();
    fromCore = //FileSystems.getDefault().getPath( TEST_HOME()), ImmutableMap.of("config","solrconfig-basic.xml","schema","schema-docValuesJoin.xml"
    coreContainer.create(//FileSystems.getDefault().getPath( TEST_HOME()), ImmutableMap.of("config","solrconfig-basic.xml","schema","schema-docValuesJoin.xml"
    "fromCore", ImmutableMap.of("configSet", "minimal"));
    assertU(add(doc("id", "1", "name_s", "john", "title_s", "Director", "dept_ss_dv", "Engineering", "text_t", "These guys develop stuff")));
    assertU(add(doc("id", "2", "name_s", "mark", "title_s", "VP", "dept_ss_dv", "Marketing", "text_t", "These guys make you look good")));
    assertU(add(doc("id", "3", "name_s", "nancy", "title_s", "MTS", "dept_ss_dv", "Sales", "text_t", "These guys sell stuff")));
    assertU(add(doc("id", "4", "name_s", "dave", "title_s", "MTS", "dept_ss_dv", "Support", "dept_ss_dv", "Engineering", "text_t", "These guys help customers")));
    assertU(add(doc("id", "5", "name_s", "tina", "title_s", "VP", "dept_ss_dv", "Engineering", "text_t", "These guys develop stuff")));
    assertU(commit());
    update(fromCore, add(doc("id", "10", "dept_id_s", "Engineering", "text_t", "These guys develop stuff", "salary_i_dv", "1000")));
    update(fromCore, add(doc("id", "11", "dept_id_s", "Marketing", "text_t", "These guys make you look good", "salary_i_dv", "1500")));
    update(fromCore, add(doc("id", "12", "dept_id_s", "Sales", "text_t", "These guys sell stuff", "salary_i_dv", "1600")));
    update(fromCore, add(doc("id", "13", "dept_id_s", "Support", "text_t", "These guys help customers", "salary_i_dv", "800")));
    update(fromCore, commit());
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) BeforeClass(org.junit.BeforeClass)

Example 29 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class TestIndexSearcher method testUseColdSearcher.

public void testUseColdSearcher() throws Exception {
    MockSearchComponent.registerFirstSearcherListener = false;
    MockSearchComponent.registerNewSearcherListener = false;
    MockSearchComponent.registerSlowSearcherListener = true;
    final AtomicBoolean querySucceeded = new AtomicBoolean(false);
    SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
    SlowSearcherListener.latch = new CountDownLatch(1);
    CoreContainer cores = h.getCoreContainer();
    CoreDescriptor cd = h.getCore().getCoreDescriptor();
    final SolrCore newCore;
    boolean coreCreated = false;
    try {
        System.setProperty("tests.solr.useColdSearcher", "true");
        // Create a new core, this should call all the firstSearcherListeners
        newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
        coreCreated = true;
        //validate that the new core was created with the correct solrconfig
        assertNotNull(newCore.getSearchComponent("mock"));
        assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
        assertTrue(newCore.getSolrConfig().useColdSearcher);
        Thread t = new Thread() {

            public void run() {
                try {
                    doQuery(newCore);
                    querySucceeded.set(true);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            ;
        };
        t.start();
        // validate that the query runs before the searcher warmer finishes
        for (int i = 0; i <= 1000; i++) {
            if (querySucceeded.get()) {
                break;
            }
            if (i == 1000) {
                fail("Query didn't succeed after 10 secoonds");
            }
            Thread.sleep(10);
        }
        assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
    } finally {
        System.getProperties().remove("tests.solr.useColdSearcher");
        if (coreCreated) {
            SlowSearcherListener.latch.countDown();
            cores.unload("core1");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoreContainer(org.apache.solr.core.CoreContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Example 30 with CoreContainer

use of org.apache.solr.core.CoreContainer in project lucene-solr by apache.

the class TestIndexSearcher method testDontUseColdSearcher.

public void testDontUseColdSearcher() throws Exception {
    MockSearchComponent.registerFirstSearcherListener = false;
    MockSearchComponent.registerNewSearcherListener = false;
    MockSearchComponent.registerSlowSearcherListener = true;
    final AtomicBoolean querySucceeded = new AtomicBoolean(false);
    SlowSearcherListener.numberOfTimesCalled = new AtomicInteger(0);
    SlowSearcherListener.latch = new CountDownLatch(1);
    CoreContainer cores = h.getCoreContainer();
    CoreDescriptor cd = h.getCore().getCoreDescriptor();
    final SolrCore newCore;
    boolean coreCreated = false;
    try {
        // Create a new core, this should call all the firstSearcherListeners
        newCore = cores.create("core1", cd.getInstanceDir(), ImmutableMap.of("config", "solrconfig-searcher-listeners1.xml"), false);
        coreCreated = true;
        //validate that the new core was created with the correct solrconfig
        assertNotNull(newCore.getSearchComponent("mock"));
        assertEquals(MockSearchComponent.class, newCore.getSearchComponent("mock").getClass());
        assertFalse(newCore.getSolrConfig().useColdSearcher);
        Thread t = new Thread() {

            public void run() {
                try {
                    doQuery(newCore);
                    querySucceeded.set(true);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }

            ;
        };
        t.start();
        if (System.getProperty(SYSPROP_NIGHTLY) != null) {
            // even if we wait here, the SearcherListener should not finish
            Thread.sleep(500);
        }
        // validate that the searcher warmer didn't finish yet. 
        assertEquals(0, SlowSearcherListener.numberOfTimesCalled.get());
        assertFalse("Query should be waiting for warming to finish", querySucceeded.get());
        // Let warmer finish 
        SlowSearcherListener.latch.countDown();
        // Validate that the query eventually succeeds
        for (int i = 0; i <= 1000; i++) {
            if (querySucceeded.get()) {
                break;
            }
            if (i == 1000) {
                fail("Query didn't succeed after 10 secoonds");
            }
            Thread.sleep(10);
        }
    } finally {
        if (coreCreated) {
            cores.unload("core1");
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CoreContainer(org.apache.solr.core.CoreContainer) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CoreDescriptor(org.apache.solr.core.CoreDescriptor) SolrCore(org.apache.solr.core.SolrCore) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException)

Aggregations

CoreContainer (org.apache.solr.core.CoreContainer)95 SolrCore (org.apache.solr.core.SolrCore)30 Test (org.junit.Test)23 SolrException (org.apache.solr.common.SolrException)16 JettySolrRunner (org.apache.solr.client.solrj.embedded.JettySolrRunner)14 File (java.io.File)13 HashMap (java.util.HashMap)11 Replica (org.apache.solr.common.cloud.Replica)11 CoreDescriptor (org.apache.solr.core.CoreDescriptor)11 Path (java.nio.file.Path)10 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)8 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)8 SolrQueryResponse (org.apache.solr.response.SolrQueryResponse)8 Map (java.util.Map)7 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)7 Properties (java.util.Properties)6 DocCollection (org.apache.solr.common.cloud.DocCollection)6 Slice (org.apache.solr.common.cloud.Slice)6 SolrZkClient (org.apache.solr.common.cloud.SolrZkClient)6