ThreadPoolEnabledPropertyProvider extends AbstractPropertyProvider { protected static String getCacheKeyForException(final Throwable throwable) { if (throwable == null) { return ""; } StringBuilder sb = new StringBuilder(); for (Throwable t : Throwables.getCausalChain(throwable)) { if (t != null) { sb.append(t.getClass().getName()); } sb.append('\n'); } return sb.toString(); } ThreadPoolEnabledPropertyProvider(Map<String, Map<String, PropertyInfo>> componentMetrics,
                                           String hostNamePropertyId,
                                           MetricHostProvider metricHostProvider,
                                           String clusterNamePropertyId); @Inject static void init(Configuration configuration); @Override Set<Resource> populateResources(Set<Resource> resources, Request request, Predicate predicate); String getHost(Resource resource, String clusterName, String componentName); static final Set<String> healthyStates; }
@Test public void testGetCacheKeyForException() throws Exception { ObjectMapper jmxObjectMapper = new ObjectMapper(); jmxObjectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false); ObjectReader jmxObjectReader = jmxObjectMapper.reader(JMXMetricHolder.class); List<Exception> exceptions = new ArrayList<>(); for (int i = 0; i < 2; i++) { try{ jmxObjectReader.readValue("Invalid string"); } catch (Exception e) { exceptions.add(e); } } Assert.assertEquals(ThreadPoolEnabledPropertyProvider.getCacheKeyForException(exceptions.get(0)), ThreadPoolEnabledPropertyProvider.getCacheKeyForException(exceptions.get(1))); }