Search in sources :

Example 1 with ThreadDeadlockDetector

use of com.codahale.metrics.jvm.ThreadDeadlockDetector in project metrics by dropwizard.

the class ThreadDeadlockHealthCheckTest method isUnhealthyIfThreadsAreDeadlocked.

@Test
public void isUnhealthyIfThreadsAreDeadlocked() throws Exception {
    final Set<String> threads = new TreeSet<String>();
    threads.add("one");
    threads.add("two");
    final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
    final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck(detector);
    when(detector.getDeadlockedThreads()).thenReturn(threads);
    final HealthCheck.Result result = healthCheck.execute();
    assertThat(result.isHealthy()).isFalse();
    assertThat(result.getMessage()).isEqualTo("[one, two]");
}
Also used : ThreadDeadlockDetector(com.codahale.metrics.jvm.ThreadDeadlockDetector) TreeSet(java.util.TreeSet) HealthCheck(com.codahale.metrics.health.HealthCheck) Test(org.junit.Test)

Example 2 with ThreadDeadlockDetector

use of com.codahale.metrics.jvm.ThreadDeadlockDetector in project metrics by dropwizard.

the class ThreadDeadlockHealthCheckTest method isHealthyIfNoThreadsAreDeadlocked.

@Test
public void isHealthyIfNoThreadsAreDeadlocked() throws Exception {
    final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
    final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck(detector);
    when(detector.getDeadlockedThreads()).thenReturn(Collections.<String>emptySet());
    assertThat(healthCheck.execute().isHealthy()).isTrue();
}
Also used : ThreadDeadlockDetector(com.codahale.metrics.jvm.ThreadDeadlockDetector) Test(org.junit.Test)

Aggregations

ThreadDeadlockDetector (com.codahale.metrics.jvm.ThreadDeadlockDetector)2 Test (org.junit.Test)2 HealthCheck (com.codahale.metrics.health.HealthCheck)1 TreeSet (java.util.TreeSet)1