Search in sources :

Example 1 with NodeConfig

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

the class TestEmbeddedSolrServerConstructors method testNodeConfigConstructor.

@Test
public void testNodeConfigConstructor() throws Exception {
    Path path = createTempDir();
    SolrResourceLoader loader = new SolrResourceLoader(path);
    NodeConfig config = new NodeConfig.NodeConfigBuilder("testnode", loader).setConfigSetBaseDirectory(Paths.get(TEST_HOME()).resolve("configsets").toString()).build();
    try (EmbeddedSolrServer server = new EmbeddedSolrServer(config, "newcore")) {
        CoreAdminRequest.Create createRequest = new CoreAdminRequest.Create();
        createRequest.setCoreName("newcore");
        createRequest.setConfigSet("minimal");
        server.request(createRequest);
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("articleid", "test");
        server.add("newcore", doc);
        server.commit();
        assertEquals(1, server.query(new SolrQuery("*:*")).getResults().getNumFound());
        assertEquals(1, server.query("newcore", new SolrQuery("*:*")).getResults().getNumFound());
    }
}
Also used : Path(java.nio.file.Path) SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) SolrInputDocument(org.apache.solr.common.SolrInputDocument) CoreAdminRequest(org.apache.solr.client.solrj.request.CoreAdminRequest) SolrQuery(org.apache.solr.client.solrj.SolrQuery) NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 2 with NodeConfig

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

the class MetricsConfigTest method testCustomSupplier.

@Test
public void testCustomSupplier() throws Exception {
    System.setProperty("counter.class", MockCounterSupplier.class.getName());
    System.setProperty("meter.class", MockMeterSupplier.class.getName());
    System.setProperty("timer.class", MockTimerSupplier.class.getName());
    System.setProperty("histogram.class", MockHistogramSupplier.class.getName());
    NodeConfig cfg = loadNodeConfig();
    SolrMetricManager mgr = new SolrMetricManager(loader, cfg.getMetricsConfig());
    assertTrue(mgr.getCounterSupplier() instanceof MockCounterSupplier);
    assertTrue(mgr.getMeterSupplier() instanceof MockMeterSupplier);
    assertTrue(mgr.getTimerSupplier() instanceof MockTimerSupplier);
    assertTrue(mgr.getHistogramSupplier() instanceof MockHistogramSupplier);
    // assert setter-based configuration
    MockCounterSupplier mockCounterSupplier = ((MockCounterSupplier) mgr.getCounterSupplier());
    assertEquals("bar", mockCounterSupplier.foo);
    MockMeterSupplier mockMeterSupplier = ((MockMeterSupplier) mgr.getMeterSupplier());
    assertEquals("bar", mockMeterSupplier.foo);
    MockTimerSupplier mockTimerSupplier = ((MockTimerSupplier) mgr.getTimerSupplier());
    assertEquals(true, mockTimerSupplier.boolParam);
    assertEquals("strParam", mockTimerSupplier.strParam);
    assertEquals(-100, mockTimerSupplier.intParam);
    // assert PluginInfoInitialized-based configuration
    MockHistogramSupplier mockHistogramSupplier = ((MockHistogramSupplier) mgr.getHistogramSupplier());
    assertNotNull(mockHistogramSupplier.info);
}
Also used : NodeConfig(org.apache.solr.core.NodeConfig) Test(org.junit.Test)

Example 3 with NodeConfig

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

the class SolrTestCaseJ4 method createCoreContainer.

public static CoreContainer createCoreContainer(String coreName, String dataDir, String solrConfig, String schema) {
    NodeConfig nodeConfig = TestHarness.buildTestNodeConfig(new SolrResourceLoader(TEST_PATH()));
    CoresLocator locator = new TestHarness.TestCoresLocator(coreName, dataDir, solrConfig, schema);
    CoreContainer cc = createCoreContainer(nodeConfig, locator);
    h.coreName = coreName;
    return cc;
}
Also used : SolrResourceLoader(org.apache.solr.core.SolrResourceLoader) CoreContainer(org.apache.solr.core.CoreContainer) CoresLocator(org.apache.solr.core.CoresLocator) NodeConfig(org.apache.solr.core.NodeConfig)

Example 4 with NodeConfig

use of org.apache.solr.core.NodeConfig 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 5 with NodeConfig

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

the class TestHarness method buildTestNodeConfig.

public static NodeConfig buildTestNodeConfig(SolrResourceLoader loader) {
    CloudConfig cloudConfig = new CloudConfig.CloudConfigBuilder(System.getProperty("host"), Integer.getInteger("hostPort", 8983), System.getProperty("hostContext", "")).setZkClientTimeout(Integer.getInteger("zkClientTimeout", 30000)).build();
    if (System.getProperty("zkHost") == null)
        cloudConfig = null;
    UpdateShardHandlerConfig updateShardHandlerConfig = new UpdateShardHandlerConfig(UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONS, UpdateShardHandlerConfig.DEFAULT_MAXUPDATECONNECTIONSPERHOST, 30000, 30000, UpdateShardHandlerConfig.DEFAULT_METRICNAMESTRATEGY, UpdateShardHandlerConfig.DEFAULT_MAXRECOVERYTHREADS);
    // universal default metric reporter
    Map<String, Object> attributes = new HashMap<>();
    attributes.put("name", "default");
    attributes.put("class", SolrJmxReporter.class.getName());
    PluginInfo defaultPlugin = new PluginInfo("reporter", attributes);
    MetricsConfig metricsConfig = new MetricsConfig.MetricsConfigBuilder().setMetricReporterPlugins(new PluginInfo[] { defaultPlugin }).build();
    return new NodeConfig.NodeConfigBuilder("testNode", loader).setUseSchemaCache(Boolean.getBoolean("shareSchema")).setCloudConfig(cloudConfig).setUpdateShardHandlerConfig(updateShardHandlerConfig).setMetricsConfig(metricsConfig).build();
}
Also used : HashMap(java.util.HashMap) CloudConfig(org.apache.solr.core.CloudConfig) MetricsConfig(org.apache.solr.core.MetricsConfig) UpdateShardHandlerConfig(org.apache.solr.update.UpdateShardHandlerConfig) PluginInfo(org.apache.solr.core.PluginInfo) SolrJmxReporter(org.apache.solr.metrics.reporters.SolrJmxReporter) NodeConfig(org.apache.solr.core.NodeConfig)

Aggregations

NodeConfig (org.apache.solr.core.NodeConfig)15 SolrResourceLoader (org.apache.solr.core.SolrResourceLoader)9 Test (org.junit.Test)8 Path (java.nio.file.Path)6 CoreContainer (org.apache.solr.core.CoreContainer)6 TestHarness (org.apache.solr.util.TestHarness)4 PluginInfo (org.apache.solr.core.PluginInfo)3 SolrMetricManager (org.apache.solr.metrics.SolrMetricManager)3 SolrMetricReporter (org.apache.solr.metrics.SolrMetricReporter)3 ExponentiallyDecayingReservoir (com.codahale.metrics.ExponentiallyDecayingReservoir)2 Reservoir (com.codahale.metrics.Reservoir)2 SlidingTimeWindowReservoir (com.codahale.metrics.SlidingTimeWindowReservoir)2 UniformReservoir (com.codahale.metrics.UniformReservoir)2 CoreAdminRequest (org.apache.solr.client.solrj.request.CoreAdminRequest)2 Before (org.junit.Before)2 Clock (com.codahale.metrics.Clock)1 GMetric (info.ganglia.gmetric4j.gmetric.GMetric)1 GMetricSlope (info.ganglia.gmetric4j.gmetric.GMetricSlope)1 GMetricType (info.ganglia.gmetric4j.gmetric.GMetricType)1 File (java.io.File)1