Skip to content

Commit

Permalink
Adjust logging, make tests more uniform
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Mar 4, 2024
1 parent 5414cdd commit 99461fc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public class ActuatorTest {

public void waitForHealth() throws Exception {
// make sure health is ready before visiting
healthIndicator.getHealth(false);

long deadline = System.currentTimeMillis() + 1000;
while (System.currentTimeMillis() < deadline && !healthIndicator.isIdle()) {
Thread.sleep(10);
Expand All @@ -36,6 +34,7 @@ public void waitForHealth() throws Exception {

@Test
public void actuatorHealth() throws Exception {
given().port(port).log().all().when().get("/actuator/health/readiness").then().log().all().assertThat().statusCode(HttpStatus.SERVICE_UNAVAILABLE.value());
waitForHealth();

given().port(port).log().all().when().get("/actuator/health/readiness").then().log().all().assertThat().statusCode(HttpStatus.OK.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.*;
import java.util.stream.Collectors;

public class JwtClientAutoConfiguration {
Expand Down Expand Up @@ -148,11 +146,7 @@ public AccessTokenProviderHealthIndicator jwtsHealthIndicator(Map<String, Access
log.info("Add health-indicator for {}/{} access-token provider(s) {}", statusProviders.size(), providers.size(), statusProviders.stream().collect(Collectors.joining("', '", "'", "'")));
}

ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
60L, TimeUnit.SECONDS,
new SynchronousQueue<>());

AccessTokenProviderHealthIndicator list = new AccessTokenProviderHealthIndicator(executor, "List");
AccessTokenProviderHealthIndicator list = new AccessTokenProviderHealthIndicator(Executors.newCachedThreadPool(), "List");

for (String key : statusProviders) {
AccessTokenProvider accessTokenProvider = providers.get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public String getName() {

private volatile CountDownLatch countDownLatch = new CountDownLatch(0);

public AccessTokenProviderHealthIndicator(ThreadPoolExecutor executor, String name) {
public AccessTokenProviderHealthIndicator(ExecutorService executor, String name) {
super(name);
this.executor = executor;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public class AbstractActuatorTest {

public void waitForHealth() throws Exception {
// make sure health is ready before visiting
healthIndicator.getHealth(false);

long deadline = System.currentTimeMillis() + 1000;
while (System.currentTimeMillis() < deadline && !healthIndicator.isIdle()) {
Thread.sleep(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ public void testReadinessDownWithTransistionToUp() throws Exception {

assertTrue(jwkFile.renameTo(jwkRenameFile));

waitForHealth();

ResponseEntity<String> down = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
assertThat(down.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);

waitForHealth();

assertTrue(jwkRenameFile.renameTo(jwkFile));

down = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
assertThat(down.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);

waitForHealth();

ResponseEntity<String> up = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ public class ReadinessEndpointUpTest extends AbstractActuatorTest {
@Autowired
private TestRestTemplate restTemplate;

@Autowired
private ListJwksHealthIndicator healthIndicator;
@Test
public void testReadiness() throws Exception {
waitForHealth();

HttpHeaders headers = new HttpHeaders();
HttpEntity<String> entity = new HttpEntity<String>(headers);

String url = "http://localhost:" + randomServerPort + "/actuator/health/readiness";

ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);

waitForHealth();
response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public void testProtectedResource() {

@Test
public void testActuatorOnWhitelist() throws Exception {
webTestClient
.get()
.uri("/actuator/health")
.exchange()
.expectStatus().is5xxServerError();

waitForHealth();
webTestClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public void testUnprotectedResourceWithPathVariableOnWhitelist() {

@Test
public void testActuatorOnWhitelist() throws Exception {
webTestClient
.get()
.uri("/actuator/health")
.exchange()
.expectStatus().is5xxServerError();

waitForHealth();

webTestClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ public void testUnprotectedResourceWithPathVariableOnWhitelist() {

@Test
public void testActuatorOnWhitelist() throws Exception {
webTestClient
.get()
.uri("/actuator/health")
.exchange()
.expectStatus().is5xxServerError();

waitForHealth();

webTestClient
Expand Down

0 comments on commit 99461fc

Please sign in to comment.