Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn -B package --file pom.xml
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Build with maven
run: mvn -B package --file pom.xml
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.teketik</groupId>
<artifactId>async-health-indicator</artifactId>
<version>boot2-v1.2</version>
<version>boot3-v1.3</version>
<name>Spring Boot Async Health Indicator</name>
<description>Asynchronous Health Indicator for Spring Boot</description>
<url>https://github.com/antoinemeyer/spring-boot-async-health-indicator</url>
Expand All @@ -29,14 +29,15 @@
</developers>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
</properties>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.RELEASE</version>
<version>3.0.13</version>
</parent>

<dependencies>
Expand Down Expand Up @@ -121,7 +122,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<version>0.8.11</version>
<executions>
<execution>
<goals>
Expand All @@ -148,7 +149,7 @@
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>1.00</minimum>
<minimum>0.90</minimum>
</limit>
</limits>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/teketik/spring/health/AsyncHealth.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* }
* </pre>
* <hr>
* <h3>Regarding Timeout</h3>
* <strong>Regarding Timeout</strong>
* <p>
* When a {@link HealthIndicator#health() health method} duration exceeds the configured {@link #timeout()}, the thread running it is <strong>interrupted</strong> if {@link #interruptOnTimeout()} is {@code true}
* with the hope that the method will fail with an exception (causing it to be {@link Status#DOWN}) and free up the thread.<br>
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/META-INF/spring.factories

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.teketik.spring.health.AsyncHealthIndicatorAutoConfiguration
3 changes: 0 additions & 3 deletions src/test/java/com/teketik/spring/health/BaseITest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package com.teketik.spring.health;

import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.HealthContributorRegistry;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
abstract class BaseITest {
Expand Down
13 changes: 6 additions & 7 deletions src/test/java/com/teketik/spring/health/ConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@

import com.teketik.utils.SchedulingThreadPoolExecutor;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

@TestPropertySource(properties = {
"management.health.async.pool.max-size=7",
"management.health.async.pool.keep-alive=8",
})
public class ConfigurationTest extends BaseITest {

@Resource
@Autowired
private AsyncHealthIndicatorAutoConfiguration asyncHealthIndicatorAutoConfiguration;

@Test
public void test() {
final SchedulingThreadPoolExecutor schedulingThreadPoolExecutor = (SchedulingThreadPoolExecutor) ReflectionTestUtils
.getField(asyncHealthIndicatorAutoConfiguration, "schedulingThreadPoolExecutor");
Assert.assertEquals(7, schedulingThreadPoolExecutor.getMaximumPoolSize());
Assert.assertEquals(8, schedulingThreadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS));
Assertions.assertEquals(7, schedulingThreadPoolExecutor.getMaximumPoolSize());
Assertions.assertEquals(8, schedulingThreadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS));
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.teketik.spring.health;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import org.assertj.core.matcher.AssertionMatcher;
import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand All @@ -31,8 +31,8 @@ public void testDown() throws Exception {
new AssertionMatcher<String>() {
@Override
public void assertion(String actual) throws AssertionError {
Assert.assertTrue(actual.length() < 4);
Assert.assertTrue(actual.endsWith("ms"));
Assertions.assertTrue(actual.length() < 4);
Assertions.assertTrue(actual.endsWith("ms"));
}
}
));
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/com/teketik/spring/health/LastCheckedITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import org.assertj.core.matcher.AssertionMatcher;
import org.awaitility.Awaitility;
import org.hamcrest.CoreMatchers;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand All @@ -19,9 +20,9 @@ public class LastCheckedITest extends BaseITest {

@Test
public void testInstanceOf() {
Assert.assertTrue(healthContributorRegistry.getContributor("defaultIndicator") instanceof HealthIndicator);
Assert.assertTrue(healthContributorRegistry.getContributor("upIndicator1") instanceof AsyncHealthIndicator);
Assert.assertTrue(healthContributorRegistry.getContributor("upIndicator2") instanceof AsyncHealthIndicator);
Assertions.assertTrue(healthContributorRegistry.getContributor("defaultIndicator") instanceof HealthIndicator);
Assertions.assertTrue(healthContributorRegistry.getContributor("upIndicator1") instanceof AsyncHealthIndicator);
Assertions.assertTrue(healthContributorRegistry.getContributor("upIndicator2") instanceof AsyncHealthIndicator);
}

@Test
Expand All @@ -32,7 +33,7 @@ public void testUnknown() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("components.upIndicator1.status").value("UNKNOWN"))
.andExpect(MockMvcResultMatchers.jsonPath("components.upIndicator1.details").doesNotExist());
}

@Test
public void testUpIndicator1Statuses() throws Exception {
// wait until health computed
Expand All @@ -52,7 +53,7 @@ public void testUpIndicator1Statuses() throws Exception {
public void assertion(String actual) throws AssertionError {
firstLastChecked[0] = LocalDateTime.parse(actual);
final int difference = (int) Duration.between(firstLastChecked[0], now).toMillis();
Assert.assertThat(difference, CoreMatchers.allOf(
MatcherAssert.assertThat(difference, CoreMatchers.allOf(
Matchers.greaterThanOrEqualTo(0),
Matchers.lessThan(1000)
));
Expand All @@ -69,7 +70,7 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
final LocalDateTime secondHit = LocalDateTime.parse(actual);
Assert.assertEquals(firstLastChecked[0], secondHit);
Assertions.assertEquals(firstLastChecked[0], secondHit);
}
}
));
Expand All @@ -85,7 +86,7 @@ public void assertion(String actual) throws AssertionError {
public void assertion(String actual) throws AssertionError {
final LocalDateTime thirdHit = LocalDateTime.parse(actual);
final int difference = (int) Duration.between(firstLastChecked[0], thirdHit).toMillis();
Assert.assertThat(difference, Matchers.greaterThan(0));
MatcherAssert.assertThat(difference, Matchers.greaterThan(0));
}
}
));
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/com/teketik/spring/health/LastDurationITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.teketik.spring.health.indicators.UpIndicator1;

import org.assertj.core.matcher.AssertionMatcher;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand Down Expand Up @@ -35,9 +35,9 @@ public void testLastDuration() throws Exception {
new AssertionMatcher<String>() {
@Override
public void assertion(String actual) throws AssertionError {
Assert.assertEquals(6, actual.length());
Assert.assertTrue(actual.endsWith("ms"));
Assert.assertTrue(actual.startsWith("1"));
Assertions.assertEquals(6, actual.length());
Assertions.assertTrue(actual.endsWith("ms"));
Assertions.assertTrue(actual.startsWith("1"));
}
}
));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.teketik.spring.health;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.teketik.spring.health;

import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import org.assertj.core.matcher.AssertionMatcher;
import org.awaitility.Awaitility;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -30,9 +31,9 @@ public void test() throws InterruptedException {
new AssertionMatcher<String>() {
@Override
public void assertion(String actual) throws AssertionError {
Assert.assertEquals(6, actual.length());
Assert.assertTrue(actual.endsWith("ms"));
Assert.assertTrue(actual.startsWith("1"));
Assertions.assertEquals(6, actual.length());
Assertions.assertTrue(actual.endsWith("ms"));
Assertions.assertTrue(actual.startsWith("1"));
}
}
))
Expand Down Expand Up @@ -63,9 +64,9 @@ public void assertion(String actual) throws AssertionError {
new AssertionMatcher<String>() {
@Override
public void assertion(String actual) throws AssertionError {
Assert.assertEquals(6, actual.length());
Assert.assertTrue(actual.endsWith("ms"));
Assert.assertTrue(actual.startsWith("1"));
Assertions.assertEquals(6, actual.length());
Assertions.assertTrue(actual.endsWith("ms"));
Assertions.assertTrue(actual.startsWith("1"));
}
}
))
Expand All @@ -74,7 +75,7 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
final int difference = (int) Duration.between(upIndicator1FirstLastChecked[0], LocalDateTime.parse(actual)).toMillis();
Assert.assertThat(difference, Matchers.greaterThan(0));
MatcherAssert.assertThat(difference, Matchers.greaterThan(0));

}
}
Expand All @@ -84,7 +85,7 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
final int difference = (int) Duration.between(timingOutSleepingIndicatorFirstLastChecked[0], LocalDateTime.parse(actual)).toMillis();
Assert.assertThat(difference, Matchers.greaterThan(0));
MatcherAssert.assertThat(difference, Matchers.greaterThan(0));
}
}
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import org.assertj.core.matcher.AssertionMatcher;
import org.awaitility.Awaitility;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Expand All @@ -31,9 +32,9 @@ public void test() throws InterruptedException {
@Override
public void assertion(String actual) throws AssertionError {
timingOutIndicatorDurations[0] = Integer.parseInt(actual.substring(0, 4));
Assert.assertEquals(6, actual.length());
Assert.assertTrue(actual.endsWith("ms"));
Assert.assertTrue(actual.startsWith("1"));
Assertions.assertEquals(6, actual.length());
Assertions.assertTrue(actual.endsWith("ms"));
Assertions.assertTrue(actual.startsWith("1"));
}
}
))
Expand Down Expand Up @@ -66,8 +67,8 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
timingOutIndicatorDurations[1] = Integer.parseInt(actual.substring(0, 4));
Assert.assertTrue(timingOutIndicatorDurations[1] > timingOutIndicatorDurations[0]);
Assert.assertEquals(6, actual.length());
Assertions.assertTrue(timingOutIndicatorDurations[1] > timingOutIndicatorDurations[0]);
Assertions.assertEquals(6, actual.length());
}
}
))
Expand All @@ -76,7 +77,7 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
final int difference = (int) Duration.between(upIndicator1FirstLastChecked[0], LocalDateTime.parse(actual)).toMillis();
Assert.assertThat(difference, Matchers.greaterThan(0));
MatcherAssert.assertThat(difference, Matchers.greaterThan(0));

}
}
Expand All @@ -87,7 +88,7 @@ public void assertion(String actual) throws AssertionError {
public void assertion(String actual) throws AssertionError {
timingOutIndicatorLastChecked[1] = LocalDateTime.parse(actual);
final int difference = (int) Duration.between(timingOutIndicatorLastChecked[0], timingOutIndicatorLastChecked[1]).toMillis();
Assert.assertEquals(0, difference);
Assertions.assertEquals(0, difference);
}
}
));
Expand All @@ -103,7 +104,7 @@ public void assertion(String actual) throws AssertionError {
new AssertionMatcher<String>() {
@Override
public void assertion(String actual) throws AssertionError {
Assert.assertTrue(Integer.parseInt(actual.substring(0, 4)) < timingOutIndicatorDurations[1]);
Assertions.assertTrue(Integer.parseInt(actual.substring(0, 4)) < timingOutIndicatorDurations[1]);
}
}
))
Expand All @@ -112,7 +113,7 @@ public void assertion(String actual) throws AssertionError {
@Override
public void assertion(String actual) throws AssertionError {
final int difference = (int) Duration.between(timingOutIndicatorLastChecked[1], LocalDateTime.parse(actual)).toMillis();
Assert.assertThat(difference, Matchers.greaterThan(0));
MatcherAssert.assertThat(difference, Matchers.greaterThan(0));
}
}
));
Expand Down
Loading