Java Code Examples for org.apache.solr.core.SolrXmlConfig#fromString()
The following examples show how to use
org.apache.solr.core.SolrXmlConfig#fromString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JvmMetricsTest.java From lucene-solr with Apache License 2.0 | 6 votes |
@Test public void testHiddenSysProps() throws Exception { Path home = Paths.get(TEST_HOME()); // default config String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr.xml").toFile(), "UTF-8"); NodeConfig config = SolrXmlConfig.fromString(home, solrXml); NodeConfig.NodeConfigBuilder.DEFAULT_HIDDEN_SYS_PROPS.forEach(s -> { assertTrue(s, config.getMetricsConfig().getHiddenSysProps().contains(s)); }); // custom config solrXml = FileUtils.readFileToString(home.resolve("solr-hiddensysprops.xml").toFile(), "UTF-8"); NodeConfig config2 = SolrXmlConfig.fromString(home, solrXml); Arrays.asList("foo", "bar", "baz").forEach(s -> { assertTrue(s, config2.getMetricsConfig().getHiddenSysProps().contains(s)); }); }
Example 2
Source File: SolrGraphiteReporterTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@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(home, solrXml); CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator (DEFAULT_TEST_CORENAME, initAndGetDataDir().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 = mock.lines.toArray(new String[mock.lines.size()]); for (String line : frozenLines) { assertTrue(line, line.startsWith("test.solr.node.CONTAINER.cores.")); } } finally { mock.close(); } }
Example 3
Source File: SolrMetricsIntegrationTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Before public void beforeTest() throws Exception { 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"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-metricreporter.xml").toFile(), "UTF-8"); NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml); cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(), "solrconfig.xml", "schema.xml")); h.coreName = DEFAULT_TEST_CORENAME; jmxReporter = JmxUtil.findFirstMBeanServer() != null ? 1 : 0; metricManager = cc.getMetricManager(); tag = h.getCore().getCoreMetricManager().getTag(); // initially there are more reporters, because two of them are added via a matching collection name Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.core." + DEFAULT_TEST_CORENAME); assertEquals(INITIAL_REPORTERS.length + jmxReporter, reporters.size()); for (String r : INITIAL_REPORTERS) { assertTagged(reporters, r); } // test rename operation cc.rename(DEFAULT_TEST_CORENAME, CORE_NAME); h.coreName = CORE_NAME; cfg = cc.getConfig(); PluginInfo[] plugins = cfg.getMetricsConfig().getMetricReporters(); assertNotNull(plugins); assertEquals(10 + jmxReporter, plugins.length); reporters = metricManager.getReporters("solr.node"); assertEquals(4 + jmxReporter, reporters.size()); assertTrue("Reporter '" + REPORTER_NAMES[0] + "' missing in solr.node", reporters.containsKey(REPORTER_NAMES[0])); assertTrue("Reporter '" + UNIVERSAL + "' missing in solr.node", reporters.containsKey(UNIVERSAL)); assertTrue("Reporter '" + MULTIGROUP + "' missing in solr.node", reporters.containsKey(MULTIGROUP)); assertTrue("Reporter '" + MULTIREGISTRY + "' missing in solr.node", reporters.containsKey(MULTIREGISTRY)); SolrMetricReporter reporter = reporters.get(REPORTER_NAMES[0]); assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter); reporter = reporters.get(UNIVERSAL); assertTrue("Reporter " + reporter + " is not an instance of " + MockMetricReporter.class.getName(), reporter instanceof MockMetricReporter); }
Example 4
Source File: SolrSlf4jReporterTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testReporter() throws Exception { ensureLoggingConfiguredAppropriately(); 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"); String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-slf4jreporter.xml").toFile(), "UTF-8"); NodeConfig cfg = SolrXmlConfig.fromString(home, solrXml); CoreContainer cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator (DEFAULT_TEST_CORENAME, initAndGetDataDir().getAbsolutePath(), "solrconfig.xml", "schema.xml")); h.coreName = DEFAULT_TEST_CORENAME; SolrMetricManager metricManager = cc.getMetricManager(); Map<String, SolrMetricReporter> reporters = metricManager.getReporters("solr.node"); assertTrue(reporters.toString(), reporters.size() >= 2); SolrMetricReporter reporter1 = reporters.get("test1"); assertNotNull(reporter1); assertTrue(reporter1 instanceof SolrSlf4jReporter); SolrMetricReporter reporter2 = reporters.get("test2"); assertNotNull(reporter2); assertTrue(reporter2 instanceof SolrSlf4jReporter); LogWatcherConfig watcherCfg = new LogWatcherConfig(true, null, null, 100); @SuppressWarnings({"rawtypes"}) LogWatcher watcher = LogWatcher.newRegisteredLogWatcher(watcherCfg, null); watcher.setThreshold("INFO"); watcher.reset(); int cnt = 20; boolean active; do { Thread.sleep(1000); cnt--; active = ((SolrSlf4jReporter)reporter1).isActive() && ((SolrSlf4jReporter)reporter2).isActive(); } while (!active && cnt > 0); if (!active) { fail("One or more reporters didn't become active in 20 seconds"); } Thread.sleep(10000); SolrDocumentList history = watcher.getHistory(-1, null); // dot-separated names are treated like class names and collapsed // in regular log output, but here we get the full name if (history.stream().filter(d -> "solr.node".equals(d.getFirstValue("logger"))).count() == 0) { fail("No 'solr.node' logs in: " + history.toString()); } if (history.stream().filter(d -> "foobar".equals(d.getFirstValue("logger"))).count() == 0) { fail("No 'foobar' logs in: " + history.toString()); } if (history.stream().filter(d -> "x:collection1".equals(d.getFirstValue("core"))).count() == 0) { fail("No 'solr.core' or MDC context in logs: " + history.toString()); } }
Example 5
Source File: TestHarness.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Create a TestHarness using a specific solr home directory and solr xml * @param solrHome the solr home directory * @param solrXml the text of a solrxml */ public TestHarness(Path solrHome, String solrXml) { this(SolrXmlConfig.fromString(solrHome, solrXml)); }