@Test
public void testCheckException() throws Exception {
TestCassandraHealthCheck testCassandraHealthCheck = new TestCassandraHealthCheck(TEST_SERVER);
testCassandraHealthCheck.cluster = testCluster;
FieldUtils.writeField(testCassandraHealthCheck, "logger", loggerMock, true);
Mockito.when(session.execute(Matchers.anyString())).thenThrow(new RuntimeException("crap"));
Result result = testCassandraHealthCheck.check();
Assert.assertFalse(result.isHealthy());
Mockito.verify(session).close();
Mockito.verify(session).execute(Matchers.anyString());
Assert.assertEquals(1, testCluster.nbrTimesCloseCalled);
ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
Mockito.verify(loggerMock).error(Matchers.anyString(), exCaptor.capture());
Assert.assertEquals(3, exCaptor.getValue().getContextLabels().size());
Assert.assertEquals(result.getError(), exCaptor.getValue());
}
java类com.codahale.metrics.health.HealthCheck.Result的实例源码
CassandraHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 35
收藏 0
点赞 0
评论 0
MongoDbHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testCheckInvalidDatabase() throws Exception {
TestMongoDbHealthCheck healthCheck = setTpcheckMocks();
Mockito.when(commandResult.get(Matchers.anyString())).thenReturn(Integer.valueOf(0));
Result result = healthCheck.check();
Mockito.verify(loggerMock).debug("connectionUrl={} databaseList={} stats={}", TEST_CONNECT_URL, "",
"commandResult");
Mockito.verify(mongoClientMock).close();
Assert.assertFalse(result.isHealthy());
ArgumentCaptor<ContextedRuntimeException> exCaptor = ArgumentCaptor.forClass(ContextedRuntimeException.class);
Mockito.verify(loggerMock).error(Matchers.anyString(), exCaptor.capture());
Assert.assertEquals(4, exCaptor.getValue().getContextLabels().size());
Assert.assertEquals("Database has nothing in it.", exCaptor.getValue().getCause().getMessage());
}
HealthCheckFilter.java 文件源码
项目:fili
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
RequestLog.startTiming(this);
String path = requestContext.getUriInfo().getAbsolutePath().getPath();
if (path.startsWith("/v1/data") || path.startsWith("/data")) {
// See if we have any unhealthy checks
Map<String, Result> unhealthyChecks = getUnhealthy();
if (!unhealthyChecks.keySet().isEmpty()) {
unhealthyChecks.entrySet()
.forEach(entry -> LOG.error("Healthcheck '{}' failed: {}", entry.getKey(), entry.getValue()));
RequestLog.stopTiming(this);
requestContext.abortWith(
Response.status(Status.SERVICE_UNAVAILABLE)
.entity("Service is unhealthy. At least 1 healthcheck is failing")
.build()
);
return;
}
}
RequestLog.stopTiming(this);
}
DbcpConnectionPoolHealthCheckTest.java 文件源码
项目:moneta
阅读 23
收藏 0
点赞 0
评论 0
@Test
public void testBasic() throws Exception {
Assert.assertTrue(healthCheck.execute().equals(Result.healthy()));
Assert.assertTrue(connectionPool.getNumActive()==0);
poolableConnectionFactory.setValidationQuery("crap");
Result testResult = healthCheck.execute();
Assert.assertTrue(!testResult.isHealthy());
Assert.assertTrue(testResult.getMessage() != null);
Assert.assertTrue(testResult.getMessage().contains("validation error"));
poolableConnectionFactory.setValidationQuery(VALIDATION_SQL);
healthCheck.setMaxWaitingConnections(-1);
testResult = healthCheck.execute();
Assert.assertTrue(!testResult.isHealthy());
Assert.assertTrue(testResult.getMessage() != null);
Assert.assertTrue(testResult.getMessage().contains("Overloaded connection pool"));
Assert.assertTrue(healthCheck.getMaxWaitingConnections() == -1);
}
JStormHealthReporter.java 文件源码
项目:jstrom
阅读 30
收藏 0
点赞 0
评论 0
@Override
public void run() {
StormClusterState clusterState = workerData.getZkCluster();
String topologyId = workerData.getTopologyId();
Map<Integer, HealthCheckRegistry> taskHealthCheckMap = JStormHealthCheck.getTaskhealthcheckmap();
int cnt = 0;
for (Map.Entry<Integer, HealthCheckRegistry> entry : taskHealthCheckMap.entrySet()) {
Integer taskId = entry.getKey();
Map<String, Result> results = entry.getValue().runHealthChecks();
for (Map.Entry<String, Result> result : results.entrySet()) {
if (!result.getValue().isHealthy()) {
try {
clusterState.report_task_error(topologyId, taskId, result.getValue().getMessage(), null);
cnt++;
} catch (Exception e) {
LOG.error("Failed to update health data in ZK for topo-{} task-{}.", topologyId, taskId, e);
}
}
}
}
LOG.info("Successfully updated {} health data to ZK for topology:{}", cnt, topologyId);
}
HealthCheckHandler.java 文件源码
项目:jooby
阅读 26
收藏 0
点赞 0
评论 0
@Override
public void handle(final Request req, final Response rsp) throws Throwable {
HealthCheckRegistry registry = req.require(HealthCheckRegistry.class);
SortedMap<String, Result> checks = req.param("name").toOptional().map(name -> {
SortedMap<String, Result> set = ImmutableSortedMap.of(name, registry.runHealthCheck(name));
return set;
}).orElseGet(() -> registry.runHealthChecks());
final Status status;
if (checks.isEmpty()) {
status = Status.NOT_IMPLEMENTED;
} else {
status = checks.values().stream()
.filter(it -> !it.isHealthy())
.findFirst()
.map(it -> Status.SERVER_ERROR)
.orElse(Status.OK);
}
rsp.status(status)
.header("Cache-Control", "must-revalidate,no-cache,no-store")
.send(checks);
}
DashboardHealthCheck.java 文件源码
项目:SeaCloudsPlatform
阅读 36
收藏 0
点赞 0
评论 0
@Override
protected Result check() throws Exception {
LOG.warn("This is NOT an integration test. The current Healthcheck only checks if all the endpoints are reachable");
if(!portIsOpen(deployer.getHost(), deployer.getPort())){
return Result.unhealthy("The Deployer endpoint is not ready");
}
if(!portIsOpen(grafana.getHost(), grafana.getPort())){
return Result.unhealthy("The Monitor endpoint is not ready");
}
if(!portIsOpen(sla.getHost(), sla.getPort())) {
return Result.unhealthy("The SLA endpoint is not ready");
}
if(!portIsOpen(planner.getHost(), planner.getPort())){
return Result.unhealthy("The Planner endpoint is not ready");
}
return Result.healthy();
}
Overview.java 文件源码
项目:r2cloud
阅读 34
收藏 0
点赞 0
评论 0
@Override
public ModelAndView doGet(IHTTPSession session) {
ModelAndView result = new ModelAndView();
JsonObject entity = Json.object();
for (Entry<String, Result> cur : Metrics.HEALTH_REGISTRY.runHealthChecks().entrySet()) {
JsonObject value = Json.object().add("status", cur.getValue().getDetails().get("status").toString());
if (!cur.getValue().isHealthy()) {
value.add("message", cur.getValue().getMessage());
}
entity.add(cur.getKey(), value);
}
result.setData(entity.toString());
return result;
}
CustomHandlers.java 文件源码
项目:StubbornJava
阅读 29
收藏 0
点赞 0
评论 0
public static void health(HttpServerExchange exchange) {
SortedMap<String, Result> results = HealthChecks.getHealthCheckRegistry().runHealthChecks();
boolean unhealthy = results.values().stream().anyMatch(result -> !result.isHealthy());
if (unhealthy) {
/*
* Set a 500 status code also. A lot of systems / dev ops tools can
* easily test status codes but are not set up to parse JSON.
* Let's keep it simple for everyone.
*/
exchange.setStatusCode(500);
}
Exchange.body().sendJson(exchange, results);
}
HealthCheckTest.java 文件源码
项目:dropwizard-jdbi3
阅读 26
收藏 0
点赞 0
评论 0
@Test
public void shouldReturnNotHealthyBecauseOfErrorOnError() throws Exception {
when(h.execute("select 1")).thenThrow(new MappingException("bad error here"));
Result check = healthCheck.check();
assertThat(check).isNotNull()
.extracting(Result::getMessage)
.containsOnly("bad error here");
}
CassandraHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 50
收藏 0
点赞 0
评论 0
@Test
public void testCheck() throws Exception {
TestCassandraHealthCheck testCassandraHealthCheck = new TestCassandraHealthCheck(TEST_SERVER);
testCassandraHealthCheck.cluster = testCluster;
Result result = testCassandraHealthCheck.check();
Assert.assertTrue(result.isHealthy());
Mockito.verify(session).close();
Mockito.verify(session).execute(Matchers.anyString());
Assert.assertEquals(1, testCluster.nbrTimesCloseCalled);
}
DataSourceHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void checkHappyPath() throws Exception {
mockSetup();
Result result = healthCheck.check();
Assert.assertTrue(result.isHealthy());
Mockito.verify(connectionMock).close();
Mockito.verify(statementMock).close();
Mockito.verify(resultSetMock).close();
}
DataSourceHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void checkQueryExecutionFailure() throws Exception {
Mockito.when(dataSourceMock.getConnection()).thenReturn(connectionMock);
Mockito.when(connectionMock.createStatement()).thenReturn(statementMock);
Mockito.when(statementMock.executeQuery(TEST_QUERY)).thenThrow(TEST_EXCEPTION);
Result result = healthCheck.check();
Assert.assertTrue(!result.isHealthy());
Assert.assertEquals(TEST_EXCEPTION, result.getError().getCause());
Mockito.verify(loggerMock).error(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
Mockito.verify(connectionMock).close();
Mockito.verify(statementMock).close();
}
DataSourceHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void checkCloseFailure() throws Exception {
mockSetup();
Mockito.doThrow(TEST_EXCEPTION).when(connectionMock).close();
Result result = healthCheck.check();
Assert.assertTrue(result.isHealthy());
Mockito.verify(loggerMock).warn(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
}
MongoDbHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void testCheck() throws Exception {
TestMongoDbHealthCheck healthCheck = setTpcheckMocks();
Mockito.when(commandResult.get(Matchers.anyString())).thenReturn(Integer.valueOf(1));
Result result = healthCheck.check();
Mockito.verify(loggerMock).debug("connectionUrl={} databaseList={} stats={}", TEST_CONNECT_URL, "",
"commandResult");
Mockito.verify(mongoClientMock).close();
Assert.assertTrue(result.isHealthy());
}
RabbitMQHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 39
收藏 0
点赞 0
评论 0
@Test
public void checkHappyPath() throws Exception {
mockSetup();
Result result = healthCheck.check();
Assert.assertTrue(result.isHealthy());
Mockito.verify(connectionMock).close();
Mockito.verify(channelMock).close();
Mockito.verify(channelMock).queueDeclarePassive(TEST_QUEUE);
}
RabbitMQHealthCheckTest.java 文件源码
项目:btm-DropwizardHealthChecks
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void checkNonexistentQueue() throws Exception {
mockSetup();
Mockito.when(channelMock.queueDeclarePassive(TEST_QUEUE)).thenThrow(TEST_EXCEPTION);
Result result = healthCheck.check();
Assert.assertFalse(result.isHealthy());
Mockito.verify(loggerMock).error(Matchers.anyString(), Matchers.any(ContextedRuntimeException.class));
}
DiskSpaceCheckerHealthCheckTest.java 文件源码
项目:harahachibu
阅读 51
收藏 0
点赞 0
评论 0
@Test
public void returnsUnhealthyWhenCheckerThrowsException() throws Exception {
when(checker.isSpaceAvailable()).thenThrow(new DiskSpaceCheckerException("Error"));
Result result = healthCheck.check();
assertThat(result.isHealthy()).isFalse();
}
DiskSpaceCheckerHealthCheckTest.java 文件源码
项目:harahachibu
阅读 30
收藏 0
点赞 0
评论 0
@Test
public void returnsUnhealthyWhenCheckerFails() throws Exception {
when(checker.isSpaceAvailable()).thenReturn(false);
Result result = healthCheck.check();
assertThat(result.isHealthy()).isFalse();
}
DiskSpaceCheckerHealthCheckTest.java 文件源码
项目:harahachibu
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void returnsHealthyWhenCheckerPasses() throws Exception {
when(checker.isSpaceAvailable()).thenReturn(true);
Result result = healthCheck.check();
assertThat(result.isHealthy()).isTrue();
}
ConsulHealthCheckTest.java 文件源码
项目:dropwizard-consul
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testCheckUnhealthy() throws Exception {
doThrow(new ConsulException("error")).when(agent).ping();
final Result actual = healthCheck.check();
verify(agent).ping();
assertThat(actual.isHealthy()).isFalse();
}
TestMetrics.java 文件源码
项目:HikariCP
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testHealthChecks() throws Exception
{
MetricRegistry metricRegistry = new MetricRegistry();
HealthCheckRegistry healthRegistry = new HealthCheckRegistry();
HikariConfig config = new HikariConfig();
config.setMaximumPoolSize(10);
config.setMetricRegistry(metricRegistry);
config.setHealthCheckRegistry(healthRegistry);
config.setPoolName("test");
config.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
config.addHealthCheckProperty("connectivityCheckTimeoutMs", "1000");
config.addHealthCheckProperty("expected99thPercentileMs", "10");
HikariDataSource ds = new HikariDataSource(config);
try {
UtilityElf.quietlySleep(TimeUnit.SECONDS.toMillis(2));
Connection connection = ds.getConnection();
connection.close();
connection = ds.getConnection();
connection.close();
SortedMap<String, Result> healthChecks = healthRegistry.runHealthChecks();
Result connectivityResult = healthChecks.get("test.pool.ConnectivityCheck");
Assert.assertTrue(connectivityResult.isHealthy());
Result slaResult = healthChecks.get("test.pool.Connection99Percent");
Assert.assertTrue(slaResult.isHealthy());
}
finally {
ds.close();
}
}
CustomHandlers.java 文件源码
项目:StubbornJava
阅读 25
收藏 0
点赞 0
评论 0
public static void health(HttpServerExchange exchange) {
SortedMap<String, Result> results = HealthChecks.getHealthCheckRegistry().runHealthChecks();
boolean unhealthy = results.values().stream().anyMatch(result -> !result.isHealthy());
if (unhealthy) {
/*
* Set a 500 status code also. A lot of systems / dev ops tools can
* easily test status codes but are not set up to parse JSON.
* Let's keep it simple for everyone.
*/
exchange.setStatusCode(500);
}
Exchange.body().sendJson(exchange, results);
}
TemplateHealthCheck.java 文件源码
项目:karamel
阅读 26
收藏 0
点赞 0
评论 0
@Override
protected Result check() throws Exception {
final String saying = String.format(template, "TEST");
if (!saying.contains("TEST")) {
return Result.unhealthy("template doesn't include a name");
}
return Result.healthy();
}
MesosDriverHealthCheckTest.java 文件源码
项目:incubator-myriad
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testCheckHealthyResult() throws Exception {
HealthCheckTestTuple tuple = getTestStack();
MyriadDriverManager manager = tuple.getManager();
MesosDriverHealthCheck checker = tuple.getChecker();
manager.startDriver();
assertEquals(Result.healthy(), checker.check());
manager.stopDriver(false);
}
MesosDriverHealthCheckTest.java 文件源码
项目:incubator-myriad
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void testCheckStoppedDriverUnhealthyResult() throws Exception {
HealthCheckTestTuple tuple = getTestStack();
MyriadDriverManager manager = tuple.getManager();
MesosDriverHealthCheck checker = tuple.getChecker();
manager.startDriver();
manager.stopDriver(false);
assertEquals(Result.unhealthy("Driver status: DRIVER_STOPPED"), checker.check());
}
MesosDriverHealthCheckTest.java 文件源码
项目:incubator-myriad
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void testCheckAbortedDriverUnhealthyResult() throws Exception {
HealthCheckTestTuple tuple = getTestStack();
MyriadDriverManager manager = tuple.getManager();
MesosDriverHealthCheck checker = tuple.getChecker();
manager.startDriver();
manager.abortDriver();
assertEquals(Result.unhealthy("Driver status: DRIVER_ABORTED"), checker.check());
}
LogProducer.java 文件源码
项目:kafkalog
阅读 36
收藏 0
点赞 0
评论 0
public Result healthCheck() {
if (runnable == null) {
return Result.unhealthy("Producer task not yet started");
}
if (runnable.isCancelled()) {
return Result.unhealthy("Producer task cancelled");
}
if (runnable.isDone()) {
return Result.unhealthy("Producer task not running any more");
}
return Result.healthy();
}
HealthCheckResource.java 文件源码
项目:micro-genie
阅读 29
收藏 0
点赞 0
评论 0
/***
* Application Health Checks
* @return response
*/
@Path(value="/check")
@GET
@Timed
public Response check(){
final SortedMap<String, HealthCheck.Result> results = this.health.runHealthChecks();
for(Entry<String, Result> entryResult : results.entrySet()){
if(!entryResult.getValue().isHealthy()){
return Response.status(Status.INTERNAL_SERVER_ERROR).entity(entryResult.getValue().getMessage()).build();
}
}
return Response.status(Status.OK).entity("Healthy!").build();
}
DashboardTestApplication.java 文件源码
项目:SeaCloudsPlatform
阅读 29
收藏 0
点赞 0
评论 0
@Override
public void run(DashboardTestConfiguration configuration, Environment environment) throws Exception {
// Generating HTTP Clients
Client jerseyClient = new JerseyClientBuilder(environment).using(configuration.getJerseyClientConfiguration())
.build(getName());
// Configuring HealthChecks
environment.healthChecks().register(getName(), new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.healthy();
}
});
}