use of info.ganglia.gmetric4j.gmetric.GMetric in project lucene-solr by apache.
the class SolrGangliaReporterTest method testReporter.
@Test
public void testReporter() 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");
GMetric ganglia = mock(GMetric.class);
final List<String> names = new ArrayList<>();
doAnswer(invocation -> {
final Object[] args = invocation.getArguments();
names.add((String) args[0]);
return null;
}).when(ganglia).announce(anyString(), anyString(), any(GMetricType.class), anyString(), any(GMetricSlope.class), anyInt(), anyInt(), anyString());
String solrXml = FileUtils.readFileToString(Paths.get(home.toString(), "solr-gangliareporter.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");
assertTrue(reporters.toString(), reporters.size() >= 1);
SolrMetricReporter reporter = reporters.get("test");
assertNotNull(reporter);
assertTrue(reporter instanceof SolrGangliaReporter);
SolrGangliaReporter gangliaReporter = (SolrGangliaReporter) reporter;
gangliaReporter.setGMetric(ganglia);
gangliaReporter.start();
Thread.sleep(5000);
assertTrue(names.size() >= 3);
String[] frozenNames = (String[]) names.toArray(new String[names.size()]);
for (String name : frozenNames) {
assertTrue(name, name.startsWith("test.solr.node.CONTAINER.cores."));
}
}
Aggregations