Пример #1
0
  @Test
  public void shouldSaveNewConfig() {
    when(settingsFacade.asProperties()).thenReturn(new Properties());

    MetricsConfig config = ConfigUtil.getDefaultConfig();
    metricsConfigFacade.saveMetricsConfig(config);

    verify(settingsFacade).saveConfigProperties(any(), propertiesCaptor.capture());

    Properties properties = propertiesCaptor.getValue();

    assertNotNull(properties);

    assertEquals(properties.getProperty(METRICS_ENABLED), "true");

    assertEquals(properties.getProperty(CONSOLE_REPORTER_ENABLED), "true");
    assertEquals(properties.getProperty(CONSOLE_REPORTER_REPORTING_FREQUENCY_VALUE), "1");
    assertEquals(properties.getProperty(CONSOLE_REPORTER_REPORTING_FREQUENCY_UNIT), "SECONDS");
    assertEquals(properties.getProperty(CONSOLE_REPORTER_CONVERT_RATES_UNIT), "MILLISECONDS");
    assertEquals(properties.getProperty(CONSOLE_REPORTER_CONVERT_DURATIONS_UNIT), "SECONDS");

    assertEquals(properties.getProperty(GRAPHITE_REPORTER_ENABLED), "true");
    assertEquals(
        properties.getProperty(GRAPHITE_REPORTER_GRAPHITE_SERVER_URI), "http://foo.com/graphite");
    assertEquals(properties.getProperty(GRAPHITE_REPORTER_GRAPHITE_SERVER_PORT), "2003");
    assertEquals(properties.getProperty(GRAPHITE_REPORTER_REPORTING_FREQUENCY_VALUE), "1");
    assertEquals(properties.getProperty(GRAPHITE_REPORTER_REPORTING_FREQUENCY_UNIT), "SECONDS");
    assertEquals(properties.getProperty(GRAPHITE_REPORTER_CONVERT_RATES_UNIT), "MILLISECONDS");
    assertEquals(properties.getProperty(GRAPHITE_REPORTER_CONVERT_DURATIONS_UNIT), "SECONDS");
  }
Пример #2
0
  @Test
  public void shouldGetMetricsConfig() {
    when(settingsFacade.getProperty(METRICS_ENABLED)).thenReturn("true");

    when(settingsFacade.getProperty(CONSOLE_REPORTER_ENABLED)).thenReturn("true");
    when(settingsFacade.getProperty(CONSOLE_REPORTER_REPORTING_FREQUENCY_VALUE)).thenReturn("1");
    when(settingsFacade.getProperty(CONSOLE_REPORTER_REPORTING_FREQUENCY_UNIT))
        .thenReturn("SECONDS");
    when(settingsFacade.getProperty(CONSOLE_REPORTER_CONVERT_RATES_UNIT))
        .thenReturn("MILLISECONDS");
    when(settingsFacade.getProperty(CONSOLE_REPORTER_CONVERT_DURATIONS_UNIT)).thenReturn("SECONDS");

    when(settingsFacade.getProperty(GRAPHITE_REPORTER_ENABLED)).thenReturn("true");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_GRAPHITE_SERVER_URI))
        .thenReturn("http://foo.com/graphite");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_GRAPHITE_SERVER_PORT)).thenReturn("2003");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_REPORTING_FREQUENCY_VALUE)).thenReturn("1");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_REPORTING_FREQUENCY_UNIT))
        .thenReturn("SECONDS");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_CONVERT_RATES_UNIT))
        .thenReturn("MILLISECONDS");
    when(settingsFacade.getProperty(GRAPHITE_REPORTER_CONVERT_DURATIONS_UNIT))
        .thenReturn("SECONDS");

    MetricsConfig config = metricsConfigFacade.getMetricsConfig();

    assertNotNull(config);
    assertEquals(config.isMetricsEnabled(), true);

    ConsoleReporterConfig crConfig = config.getConsoleReporterConfig();
    assertNotNull(crConfig);
    assertEquals(crConfig.isEnabled(), true);
    assertEquals(crConfig.getFrequency(), 1);
    assertEquals(crConfig.getFrequencyUnit(), TimeUnit.SECONDS);
    assertEquals(crConfig.getConvertRates(), TimeUnit.MILLISECONDS);
    assertEquals(crConfig.getConvertDurations(), TimeUnit.SECONDS);

    GraphiteReporterConfig grConfig = config.getGraphiteReporterConfig();
    assertNotNull(grConfig);
    assertEquals(grConfig.isEnabled(), true);
    assertEquals(grConfig.getServerUri(), "http://foo.com/graphite");
    assertEquals(grConfig.getServerPort(), 2003);
    assertEquals(grConfig.getFrequency(), 1);
    assertEquals(grConfig.getFrequencyUnit(), TimeUnit.SECONDS);
    assertEquals(grConfig.getConvertRates(), TimeUnit.MILLISECONDS);
    assertEquals(grConfig.getConvertDurations(), TimeUnit.SECONDS);
  }
  @PostConstruct
  public void init() {
    // register the default metrics only when the module first loads
    if (!defaultMetricsRegistered) {
      registerDefaultMetrics();
      defaultMetricsRegistered = true;
    }

    stopReporters();

    MetricsConfig metricsConfig = metricsConfigFacade.getMetricsConfig();

    metricRegistryService.setEnabled(metricsConfig.isMetricsEnabled());

    if (metricsConfig.isMetricsEnabled()) {
      configureConsoleReporter(metricsConfig.getConsoleReporterConfig());
      configureGraphiteReporter(metricsConfig.getGraphiteReporterConfig());
    }
  }
Пример #4
0
  @Test
  public void shouldGetMetricsEnabled() {
    when(settingsFacade.getProperty(METRICS_ENABLED)).thenReturn("true");

    assertTrue(metricsConfigFacade.isMetricsEnabled());
  }