use of org.apache.solr.metrics.reporters.MockMetricReporter in project lucene-solr by apache.
the class SolrMetricsIntegrationTest method afterTest.
@After
public void afterTest() throws Exception {
SolrCoreMetricManager coreMetricManager = h.getCore().getCoreMetricManager();
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
deleteCore();
for (String reporterName : RENAMED_REPORTERS) {
SolrMetricReporter reporter = reporters.get(reporterName + "@" + tag);
MockMetricReporter mockReporter = (MockMetricReporter) reporter;
assertTrue("Reporter " + reporterName + " was not closed: " + mockReporter, mockReporter.didClose);
}
}
use of org.apache.solr.metrics.reporters.MockMetricReporter in project lucene-solr by apache.
the class SolrMetricsIntegrationTest method testConfigureReporter.
@Test
public void testConfigureReporter() throws Exception {
Random random = random();
String metricName = SolrMetricManager.mkName(METRIC_NAME, HANDLER_CATEGORY.toString(), HANDLER_NAME);
SolrCoreMetricManager coreMetricManager = h.getCore().getCoreMetricManager();
Timer timer = (Timer) metricManager.timer(null, coreMetricManager.getRegistryName(), metricName);
long initialCount = timer.getCount();
int iterations = TestUtil.nextInt(random, 0, MAX_ITERATIONS);
for (int i = 0; i < iterations; ++i) {
h.query(req("*"));
}
long finalCount = timer.getCount();
assertEquals("metric counter incorrect", iterations, finalCount - initialCount);
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertEquals(RENAMED_REPORTERS.length + jmxReporter, reporters.size());
// specific to collection1
for (String reporterName : RENAMED_REPORTERS) {
SolrMetricReporter reporter = reporters.get(reporterName + "@" + tag);
assertNotNull("Reporter " + reporterName + " was not found.", reporter);
assertTrue(reporter instanceof MockMetricReporter);
MockMetricReporter mockReporter = (MockMetricReporter) reporter;
assertTrue("Reporter " + reporterName + " was not initialized: " + mockReporter, mockReporter.didInit);
assertTrue("Reporter " + reporterName + " was not validated: " + mockReporter, mockReporter.didValidate);
assertFalse("Reporter " + reporterName + " was incorrectly closed: " + mockReporter, mockReporter.didClose);
}
}
use of org.apache.solr.metrics.reporters.MockMetricReporter in project lucene-solr by apache.
the class SolrMetricReporterTest method testInit.
@Test
public void testInit() throws Exception {
Random random = random();
SolrMetricManager metricManager = new SolrMetricManager();
final String registryName = TestUtil.randomSimpleString(random);
final MockMetricReporter reporter = new MockMetricReporter(metricManager, registryName);
Map<String, Object> attrs = new HashMap<>();
attrs.put(FieldType.CLASS_NAME, MockMetricReporter.class.getName());
attrs.put(CoreAdminParams.NAME, TestUtil.randomUnicodeString(random));
attrs.put("enabled", random.nextBoolean());
boolean shouldDefineConfigurable = random.nextBoolean();
String configurable = TestUtil.randomUnicodeString(random);
if (shouldDefineConfigurable)
attrs.put("configurable", configurable);
boolean shouldDefinePlugin = random.nextBoolean();
String type = TestUtil.randomUnicodeString(random);
PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(type, attrs) : null;
try {
reporter.init(pluginInfo);
assertNotNull(pluginInfo);
assertEquals(configurable, attrs.get("configurable"));
assertTrue(reporter.didValidate);
assertNotNull(reporter.configurable);
assertEquals(configurable, reporter.configurable);
} catch (IllegalStateException e) {
assertTrue(pluginInfo == null || attrs.get("configurable") == null);
assertTrue(reporter.didValidate);
assertNull(reporter.configurable);
} finally {
reporter.close();
}
}
use of org.apache.solr.metrics.reporters.MockMetricReporter in project lucene-solr by apache.
the class SolrCoreMetricManagerTest method testLoadReporter.
@Test
public void testLoadReporter() throws Exception {
Random random = random();
String className = MockMetricReporter.class.getName();
String reporterName = TestUtil.randomUnicodeString(random);
String taggedName = reporterName + "@" + coreMetricManager.getTag();
Map<String, Object> attrs = new HashMap<>();
attrs.put(FieldType.CLASS_NAME, className);
attrs.put(CoreAdminParams.NAME, reporterName);
boolean shouldDefineConfigurable = random.nextBoolean();
String configurable = TestUtil.randomUnicodeString(random);
if (shouldDefineConfigurable)
attrs.put("configurable", configurable);
boolean shouldDefinePlugin = random.nextBoolean();
PluginInfo pluginInfo = shouldDefinePlugin ? new PluginInfo(TestUtil.randomUnicodeString(random), attrs) : null;
try {
metricManager.loadReporter(coreMetricManager.getRegistryName(), coreMetricManager.getCore().getResourceLoader(), pluginInfo, String.valueOf(coreMetricManager.getCore().hashCode()));
assertNotNull(pluginInfo);
Map<String, SolrMetricReporter> reporters = metricManager.getReporters(coreMetricManager.getRegistryName());
assertTrue("reporters.size should be > 0, but was + " + reporters.size(), reporters.size() > 0);
assertNotNull("reporter " + reporterName + " not present among " + reporters, reporters.get(taggedName));
assertTrue("wrong reporter class: " + reporters.get(taggedName), reporters.get(taggedName) instanceof MockMetricReporter);
} catch (IllegalArgumentException e) {
assertTrue(pluginInfo == null || attrs.get("configurable") == null);
assertNull(metricManager.getReporters(coreMetricManager.getRegistryName()).get(taggedName));
}
}
use of org.apache.solr.metrics.reporters.MockMetricReporter in project lucene-solr by apache.
the class SolrMetricsIntegrationTest method beforeTest.
@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(new SolrResourceLoader(home), solrXml);
cc = createCoreContainer(cfg, new TestHarness.TestCoresLocator(DEFAULT_TEST_CORENAME, initCoreDataDir.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);
}
Aggregations