UaaMetricsEmitter { public void enableNotification() { try { logger.debug("Trying to enable notification"); NotificationEmitter emitter = metricsUtils.getUaaMetricsSubscriber(server); emitter.addNotificationListener((notification, handback) -> { String key = notification.getType(); String prefix = key.startsWith("/") ? key.substring(1) : key; statsDClient.time(String.format("requests.%s.latency", prefix), (Long) notification.getSource()); }, null, null); notificationsEnabled = true; } catch(Exception instanceNotFound) { try { throwIfOtherThanNotFound(instanceNotFound); } catch (Exception e) { logger.info("Unable to create server request metric bean", e); } } } UaaMetricsEmitter(MetricsUtils metricsUtils, StatsDClient statsDClient, MBeanServerConnection server); @Scheduled(fixedRate = 5000, initialDelay = 0) void emitMetrics(); @Scheduled(fixedRate = 5000, initialDelay = 1000) void emitGlobalRequestMetrics(); @Scheduled(fixedRate = 5000, initialDelay = 1000) void emitUrlGroupRequestMetrics(); void emitGlobalServerStats(UaaMetrics metrics); void emitGlobalRequestMetrics(UaaMetrics metrics); @Scheduled(fixedRate = 5000, initialDelay = 2000) void emitVmVitals(); @Scheduled(fixedRate = 5000, initialDelay = 3000) void emitJvmVitals(); void throwIfOtherThanNotFound(Exception x); Number getValueFromBean(Object mbean, String getter); Object getValueFromMap(Map<String, ?> map, String path); void enableNotification(); long getMetricDelta(String name, long gaugeValue); boolean isNotificationEnabled();  }
@Test void sendNotification() { uaaMetricsEmitter.enableNotification(); emitter.sendNotification(new Notification("/api", 45L, 0)); Mockito.verify(statsDClient).time("requests.api.latency", 45L); }