-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from pagopa/release-uat
fix: promote to Main
- Loading branch information
Showing
5 changed files
with
92 additions
and
99 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/it/gov/pagopa/common/config/CustomReactiveMongoHealthIndicator.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,27 @@ | ||
package it.gov.pagopa.common.config; | ||
|
||
import org.bson.Document; | ||
import org.springframework.boot.actuate.health.AbstractReactiveHealthIndicator; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
import org.springframework.util.Assert; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class CustomReactiveMongoHealthIndicator extends AbstractReactiveHealthIndicator { | ||
private final ReactiveMongoTemplate reactiveMongoTemplate; | ||
public CustomReactiveMongoHealthIndicator(ReactiveMongoTemplate reactiveMongoTemplate) { | ||
super("Mongo health check failed"); | ||
Assert.notNull(reactiveMongoTemplate, "ReactiveMongoTemplate must not be null"); | ||
this.reactiveMongoTemplate = reactiveMongoTemplate; | ||
} | ||
|
||
@Override | ||
protected Mono<Health> doHealthCheck(Health.Builder builder) { | ||
Mono<Document> buildInfo = this.reactiveMongoTemplate.executeCommand("{ isMaster: 1 }"); | ||
return buildInfo.map(document -> up(builder, document)); | ||
} | ||
|
||
private Health up(Health.Builder builder, Document document) { | ||
return builder.up().withDetail("maxWireVersion", document.getInteger("maxWireVersion")).build(); | ||
} | ||
} |
33 changes: 0 additions & 33 deletions
33
src/main/java/it/gov/pagopa/common/config/HealthIndicatorLogger.java
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
src/main/java/it/gov/pagopa/common/mongo/config/MongoHealthConfig.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,15 @@ | ||
package it.gov.pagopa.common.mongo.config; | ||
|
||
import it.gov.pagopa.common.config.CustomReactiveMongoHealthIndicator; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
|
||
@Configuration | ||
public class MongoHealthConfig { | ||
@Bean | ||
public CustomReactiveMongoHealthIndicator customMongoHealthIndicator(ReactiveMongoTemplate mongoTemplate) { | ||
return new CustomReactiveMongoHealthIndicator(mongoTemplate); | ||
} | ||
} | ||
|
50 changes: 50 additions & 0 deletions
50
src/test/java/it/gov/pagopa/common/config/CustomReactiveMongoHealthIndicatorTest.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,50 @@ | ||
package it.gov.pagopa.common.config; | ||
|
||
import com.mongodb.MongoException; | ||
import org.bson.Document; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.actuate.health.Health; | ||
import org.springframework.boot.actuate.health.Status; | ||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate; | ||
import reactor.core.publisher.Mono; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.time.Duration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.BDDMockito.given; | ||
import static org.mockito.Mockito.mock; | ||
|
||
|
||
class CustomReactiveMongoHealthIndicatorTest { | ||
@Test | ||
void testMongoIsUp() { | ||
Document buildInfo = mock(Document.class); | ||
given(buildInfo.getInteger("maxWireVersion")).willReturn(10); | ||
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class); | ||
given(reactiveMongoTemplate.executeCommand("{ isMaster: 1 }")).willReturn(Mono.just(buildInfo)); | ||
CustomReactiveMongoHealthIndicator mongoReactiveHealthIndicator = new CustomReactiveMongoHealthIndicator( | ||
reactiveMongoTemplate); | ||
Mono<Health> health = mongoReactiveHealthIndicator.health(); | ||
StepVerifier.create(health).consumeNextWith(h -> { | ||
assertThat(h.getStatus()).isEqualTo(Status.UP); | ||
assertThat(h.getDetails()).containsOnlyKeys("maxWireVersion"); | ||
assertThat(h.getDetails()).containsEntry("maxWireVersion", 10); | ||
}).expectComplete().verify(Duration.ofSeconds(30)); | ||
} | ||
|
||
@Test | ||
void testMongoIsDown() { | ||
ReactiveMongoTemplate reactiveMongoTemplate = mock(ReactiveMongoTemplate.class); | ||
given(reactiveMongoTemplate.executeCommand("{ isMaster: 1 }")).willThrow(new MongoException("Connection failed")); | ||
CustomReactiveMongoHealthIndicator mongoReactiveHealthIndicator = new CustomReactiveMongoHealthIndicator( | ||
reactiveMongoTemplate); | ||
Mono<Health> health = mongoReactiveHealthIndicator.health(); | ||
StepVerifier.create(health).consumeNextWith(h -> { | ||
assertThat(h.getStatus()).isEqualTo(Status.DOWN); | ||
assertThat(h.getDetails()).containsOnlyKeys("error"); | ||
assertThat(h.getDetails()).containsEntry("error", MongoException.class.getName() + ": Connection failed"); | ||
}).expectComplete().verify(Duration.ofSeconds(30)); | ||
} | ||
|
||
} |
66 changes: 0 additions & 66 deletions
66
src/test/java/it/gov/pagopa/common/config/HealthIndicatorLoggerTest.java
This file was deleted.
Oops, something went wrong.