@Test public void testParseConfiguration() throws Exception { JmxTransExporterConfiguration config = new JmxTransConfigurationXmlLoader("classpath:jmxtrans-agent.xml").loadConfiguration(); assertThat(config.collectInterval, is(11)); assertThat(config.collectIntervalTimeUnit, is(TimeUnit.SECONDS)); assertThat(config.getConfigReloadInterval(), equalTo(-1)); OutputWriter decoratedOutputWriter = config.outputWriter; // CircuitBreaker assertTrue(decoratedOutputWriter.getClass().equals(OutputWriterCircuitBreakerDecorator.class)); OutputWriterCircuitBreakerDecorator circuitBreakerDecorator = (OutputWriterCircuitBreakerDecorator) decoratedOutputWriter; assertThat(circuitBreakerDecorator.isDisabled(), is(false)); // Graphite Writer assertTrue( circuitBreakerDecorator.delegate.getClass().equals(GraphitePlainTextTcpOutputWriter.class)); GraphitePlainTextTcpOutputWriter graphiteWriter = (GraphitePlainTextTcpOutputWriter) circuitBreakerDecorator.delegate; assertThat(graphiteWriter.graphiteServerHostAndPort.getPort(), is(2203)); assertThat(graphiteWriter.graphiteServerHostAndPort.getHost(), is("localhost")); assertThat(graphiteWriter.getMetricPathPrefix(), is("app_123456.server.i876543.")); assertThat(config.queries.size(), is(13)); Map<String, Query> queriesByResultAlias = indexQueriesByResultAlias(config.queries); { Query query = queriesByResultAlias.get("os.systemLoadAverage"); assertThat(query.objectName, is(new ObjectName("java.lang:type=OperatingSystem"))); assertThat(query.getAttributes(), contains("SystemLoadAverage")); assertThat(query.resultAlias, is("os.systemLoadAverage")); assertThat(query.key, is((String) null)); } { Query query = queriesByResultAlias.get("jvm.heapMemoryUsage.used"); assertThat(query.objectName, is(new ObjectName("java.lang:type=Memory"))); assertThat(query.getAttributes(), contains("HeapMemoryUsage")); assertThat(query.resultAlias, is("jvm.heapMemoryUsage.used")); assertThat(query.key, is("used")); } Map<String, Invocation> invocationsByResultAlias = indexInvocationsByResultAlias(config.invocations); { Invocation invocation = invocationsByResultAlias.get("jvm.gc"); assertThat(invocation.objectName, is(new ObjectName("java.lang:type=Memory"))); assertThat(invocation.operationName, is("gc")); assertThat(invocation.resultAlias, is("jvm.gc")); } }
@Test public void testParseConfiguration2() throws Exception { JmxTransExporterConfiguration config = new JmxTransConfigurationXmlLoader("classpath:jmxtrans-agent-2.xml").loadConfiguration(); assertThat(config.collectInterval, is(12)); assertThat(config.collectIntervalTimeUnit, is(TimeUnit.SECONDS)); assertTrue(config.outputWriter.getClass().equals(OutputWritersChain.class)); OutputWritersChain outputWritersChain = (OutputWritersChain) config.outputWriter; assertThat(outputWritersChain.outputWriters.size(), is(2)); { OutputWriter decoratedOutputWriter = outputWritersChain.outputWriters.get(0); // CircuitBreaker assertTrue( decoratedOutputWriter.getClass().equals(OutputWriterCircuitBreakerDecorator.class)); OutputWriterCircuitBreakerDecorator circuitBreakerDecorator = (OutputWriterCircuitBreakerDecorator) decoratedOutputWriter; assertThat(circuitBreakerDecorator.isDisabled(), is(true)); // Graphite Writer assertTrue( circuitBreakerDecorator .delegate .getClass() .equals(GraphitePlainTextTcpOutputWriter.class)); GraphitePlainTextTcpOutputWriter writer = (GraphitePlainTextTcpOutputWriter) circuitBreakerDecorator.delegate; assertThat(writer.graphiteServerHostAndPort.getPort(), is(2003)); assertThat(writer.graphiteServerHostAndPort.getHost(), is("localhost")); assertThat(writer.getMetricPathPrefix(), is("servers.localhost.")); } { OutputWriter decoratedOutputWriter = outputWritersChain.outputWriters.get(1); // Circuit Breaker assertTrue( decoratedOutputWriter.getClass().equals(OutputWriterCircuitBreakerDecorator.class)); OutputWriterCircuitBreakerDecorator circuitBreakerDecorator = (OutputWriterCircuitBreakerDecorator) decoratedOutputWriter; assertThat(circuitBreakerDecorator.isDisabled(), is(true)); // Console Writer assertTrue(circuitBreakerDecorator.delegate.getClass().equals(ConsoleOutputWriter.class)); } assertThat(config.queries.size(), is(13)); Map<String, Query> queriesByResultAlias = indexQueriesByResultAlias(config.queries); { Query query = queriesByResultAlias.get("os.systemLoadAverage"); assertThat(query.objectName, is(new ObjectName("java.lang:type=OperatingSystem"))); assertThat(query.getAttributes(), contains("SystemLoadAverage")); assertThat(query.resultAlias, is("os.systemLoadAverage")); assertThat(query.key, is((String) null)); } { Query query = queriesByResultAlias.get("jvm.heapMemoryUsage.used"); assertThat(query.objectName, is(new ObjectName("java.lang:type=Memory"))); assertThat(query.getAttributes(), contains("HeapMemoryUsage")); assertThat(query.resultAlias, is("jvm.heapMemoryUsage.used")); assertThat(query.key, is("used")); } }