From 0640501d7a4f61f9e2ad65174c580f5cdec5788d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AF=BB=E8=8A=B3?= Date: Tue, 27 Dec 2022 14:58:25 +0800 Subject: [PATCH] fix HealthIndicatorProcessor.doHealthCheck() bug when exception occur --- .../test/HealthIndicatorCheckProcessorTest.java | 12 +++++++++--- .../test/bean/TimeoutHealthIndicator.java | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/HealthIndicatorCheckProcessorTest.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/HealthIndicatorCheckProcessorTest.java index 7df1381f5..f036889d5 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/HealthIndicatorCheckProcessorTest.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/HealthIndicatorCheckProcessorTest.java @@ -16,7 +16,11 @@ */ package com.alipay.sofa.healthcheck.test; -import com.alipay.sofa.healthcheck.*; +import com.alipay.sofa.healthcheck.AfterReadinessCheckCallbackProcessor; +import com.alipay.sofa.healthcheck.HealthCheckProperties; +import com.alipay.sofa.healthcheck.HealthCheckerProcessor; +import com.alipay.sofa.healthcheck.HealthIndicatorProcessor; +import com.alipay.sofa.healthcheck.ReadinessCheckListener; import com.alipay.sofa.healthcheck.core.HealthCheckExecutor; import com.alipay.sofa.healthcheck.test.bean.DiskHealthIndicator; import com.alipay.sofa.healthcheck.test.bean.TimeoutHealthIndicator; @@ -128,7 +132,8 @@ public void testCheckIndicatorFailed() { Health timeoutHealth = hashMap.get("timeout"); Assert.assertNotNull(timeoutHealth); Assert.assertEquals(Status.UNKNOWN, timeoutHealth.getStatus()); - Assert.assertEquals("java.util.concurrent.TimeoutException: null", timeoutHealth.getDetails().get("error")); + Assert.assertEquals("java.util.concurrent.TimeoutException: null", timeoutHealth + .getDetails().get("error")); } private void initApplicationContext(boolean health) { @@ -136,7 +141,8 @@ private void initApplicationContext(boolean health) { properties.put("disk-health-indicator.health", health); properties.put("timeout-health-indicator.health", true); if (!health) { - properties.put("com.alipay.sofa.healthcheck.indicator.timeout.timeoutHealthIndicator", "1"); + properties.put("com.alipay.sofa.healthcheck.indicator.timeout.timeoutHealthIndicator", + "1"); } properties.put("com.alipay.sofa.healthcheck.skip.indicator", "true"); properties.put("spring.application.name", "HealthIndicatorCheckProcessorTest"); diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/bean/TimeoutHealthIndicator.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/bean/TimeoutHealthIndicator.java index ce576892a..fcbcbbe4b 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/bean/TimeoutHealthIndicator.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/test/java/com/alipay/sofa/healthcheck/test/bean/TimeoutHealthIndicator.java @@ -1,6 +1,18 @@ /* - * Ant Group - * Copyright (c) 2004-2022 All Rights Reserved. + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ package com.alipay.sofa.healthcheck.test.bean;