-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration to disable or enable readiness check.
- Loading branch information
1 parent
158e53d
commit e030bb2
Showing
8 changed files
with
176 additions
and
3 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
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
48 changes: 48 additions & 0 deletions
48
...ck-sofa-boot-starter/src/test/java/com/alipay/sofa/healthcheck/base/AbstractTestBase.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,48 @@ | ||
/* | ||
* 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.base; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.context.embedded.LocalServerPort; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
/** | ||
* AbstractTestBase | ||
* | ||
* @author yangguanchao | ||
* @since 2018/07/28 | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest(classes = SpringBootWebApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public abstract class AbstractTestBase { | ||
|
||
/** | ||
* 8080 | ||
*/ | ||
@LocalServerPort | ||
protected int definedPort; | ||
|
||
@Autowired | ||
protected TestRestTemplate testRestTemplate; | ||
|
||
public String getUrlPath(String path) { | ||
return "http://localhost:" + definedPort + path; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...boot-starter/src/test/java/com/alipay/sofa/healthcheck/base/SpringBootWebApplication.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,34 @@ | ||
/* | ||
* 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.base; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
|
||
/** | ||
* SpringBootWebApplication | ||
* | ||
* @author yangguanchao | ||
* @since 2018/07/28 | ||
*/ | ||
@org.springframework.boot.autoconfigure.SpringBootApplication | ||
public class SpringBootWebApplication { | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication springApplication = new SpringApplication(SpringBootWebApplication.class); | ||
springApplication.run(args); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...er/src/test/java/com/alipay/sofa/healthcheck/enable/SofaBootReadinessCheckEnableTest.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,44 @@ | ||
/* | ||
* 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.enable; | ||
|
||
import com.alipay.sofa.healthcheck.base.AbstractTestBase; | ||
import org.junit.Test; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* SofaBootReadinessCheckEnableTest | ||
* | ||
* @author yangguanchao | ||
* @since 2018/07/28 | ||
*/ | ||
public class SofaBootReadinessCheckEnableTest extends AbstractTestBase { | ||
|
||
@Test | ||
public void testEnableReadinessCheck() throws Exception { | ||
String urlHttp = this.getUrlPath("/health/readiness"); | ||
ResponseEntity<Map> response = this.testRestTemplate.getForEntity(urlHttp, Map.class); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
assertEquals(Status.UP.getCode(), response.getBody().get("status").toString()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...er/src/test/java/com/alipay/sofa/healthcheck/enable/SofaBootReadinessCheckUnableTest.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,44 @@ | ||
/* | ||
* 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.enable; | ||
|
||
import com.alipay.sofa.healthcheck.base.AbstractTestBase; | ||
import org.junit.Test; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* SofaBootReadinessCheckEnableTest | ||
* | ||
* @author yangguanchao | ||
* @since 2018/07/28 | ||
*/ | ||
@ActiveProfiles("disable") | ||
public class SofaBootReadinessCheckUnableTest extends AbstractTestBase { | ||
|
||
@Test | ||
public void testUnableReadinessCheck() throws Exception { | ||
String urlHttp = this.getUrlPath("/health/readiness"); | ||
ResponseEntity<Map> response = this.testRestTemplate.getForEntity(urlHttp, Map.class); | ||
assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
healthcheck-sofa-boot-starter/src/test/resources/application-disable.properties
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 @@ | ||
com.alipay.sofa.healthcheck.enabled = false |
1 change: 1 addition & 0 deletions
1
healthcheck-sofa-boot-starter/src/test/resources/application.properties
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 @@ | ||
com.alipay.sofa.healthcheck.enabled = true |