-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1095 from dropwizard/shared_health_checks
Add support for the default shared health check registry name
- Loading branch information
Showing
2 changed files
with
146 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...althchecks/src/test/java/com/codahale/metrics/health/SharedHealthCheckRegistriesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.codahale.metrics.health; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.util.concurrent.atomic.AtomicReference; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SharedHealthCheckRegistriesTest { | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
@Before | ||
public void setUp() { | ||
SharedHealthCheckRegistries.setDefaultRegistryName(new AtomicReference<String>()); | ||
SharedHealthCheckRegistries.clear(); | ||
} | ||
|
||
@Test | ||
public void savesCreatedRegistry() { | ||
final HealthCheckRegistry one = SharedHealthCheckRegistries.getOrCreate("db"); | ||
final HealthCheckRegistry two = SharedHealthCheckRegistries.getOrCreate("db"); | ||
|
||
assertThat(one).isSameAs(two); | ||
} | ||
|
||
@Test | ||
public void returnsSetOfCreatedRegistries() { | ||
SharedHealthCheckRegistries.getOrCreate("db"); | ||
|
||
assertThat(SharedHealthCheckRegistries.names()).containsOnly("db"); | ||
} | ||
|
||
@Test | ||
public void registryCanBeRemoved() { | ||
final HealthCheckRegistry first = SharedHealthCheckRegistries.getOrCreate("db"); | ||
SharedHealthCheckRegistries.remove("db"); | ||
|
||
assertThat(SharedHealthCheckRegistries.names()).isEmpty(); | ||
assertThat(SharedHealthCheckRegistries.getOrCreate("db")).isNotEqualTo(first); | ||
} | ||
|
||
@Test | ||
public void registryCanBeCleared() { | ||
SharedHealthCheckRegistries.getOrCreate("db"); | ||
SharedHealthCheckRegistries.getOrCreate("web"); | ||
|
||
SharedHealthCheckRegistries.clear(); | ||
|
||
assertThat(SharedHealthCheckRegistries.names()).isEmpty(); | ||
} | ||
|
||
@Test | ||
public void defaultRegistryIsNotSetByDefault() { | ||
expectedException.expect(IllegalStateException.class); | ||
expectedException.expectMessage("Default registry name has not been set."); | ||
|
||
SharedHealthCheckRegistries.getDefault(); | ||
} | ||
|
||
@Test | ||
public void defaultRegistryCanBeSet() { | ||
HealthCheckRegistry registry = SharedHealthCheckRegistries.setDefault("default"); | ||
|
||
assertThat(SharedHealthCheckRegistries.getDefault()).isEqualTo(registry); | ||
} | ||
|
||
@Test | ||
public void specificRegistryCanBeSetAsDefault() { | ||
HealthCheckRegistry registry = new HealthCheckRegistry(); | ||
SharedHealthCheckRegistries.setDefault("default", registry); | ||
|
||
assertThat(SharedHealthCheckRegistries.getDefault()).isEqualTo(registry); | ||
} | ||
|
||
@Test | ||
public void unableToSetDefaultRegistryTwice() { | ||
expectedException.expect(IllegalStateException.class); | ||
expectedException.expectMessage("Default health check registry is already set."); | ||
|
||
SharedHealthCheckRegistries.setDefault("default"); | ||
SharedHealthCheckRegistries.setDefault("default"); | ||
} | ||
|
||
@Test | ||
public void unableToSetCustomDefaultRegistryTwice() { | ||
expectedException.expect(IllegalStateException.class); | ||
expectedException.expectMessage("Default health check registry is already set."); | ||
|
||
SharedHealthCheckRegistries.setDefault("default", new HealthCheckRegistry()); | ||
SharedHealthCheckRegistries.setDefault("default", new HealthCheckRegistry()); | ||
} | ||
} |