-
Notifications
You must be signed in to change notification settings - Fork 4
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 #26 from SolaceCoEExt/fix-issues
Added health status - started, ready, alive
- Loading branch information
Showing
5 changed files
with
320 additions
and
11 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
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
141 changes: 141 additions & 0 deletions
141
...b-plus-connector/src/test/java/io/quarkiverse/solace/health/SolaceConsumerHealthTest.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,141 @@ | ||
package io.quarkiverse.solace.health; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.awaitility.Awaitility.await; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.List; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.solace.messaging.publisher.PersistentMessagePublisher; | ||
import com.solace.messaging.receiver.InboundMessage; | ||
import com.solace.messaging.resources.Topic; | ||
|
||
import io.quarkiverse.solace.base.WeldTestBase; | ||
import io.quarkiverse.solace.incoming.SolaceInboundMessage; | ||
import io.smallrye.reactive.messaging.health.HealthReport; | ||
import io.smallrye.reactive.messaging.test.common.config.MapBasedConfig; | ||
|
||
public class SolaceConsumerHealthTest extends WeldTestBase { | ||
|
||
@Test | ||
void solaceConsumerHealthCheck() { | ||
MapBasedConfig config = new MapBasedConfig() | ||
.with("mp.messaging.incoming.in.connector", "quarkus-solace") | ||
.with("mp.messaging.incoming.in.consumer.queue.name", queue) | ||
.with("mp.messaging.incoming.in.consumer.queue.add-additional-subscriptions", "true") | ||
.with("mp.messaging.incoming.in.consumer.queue.missing-resource-creation-strategy", "create-on-start") | ||
.with("mp.messaging.incoming.in.consumer.queue.subscriptions", topic); | ||
|
||
// Run app that consumes messages | ||
MyConsumer app = runApplication(config, MyConsumer.class); | ||
|
||
await().until(() -> isStarted() && isReady()); | ||
|
||
// Produce messages | ||
PersistentMessagePublisher publisher = messagingService.createPersistentMessagePublisherBuilder() | ||
.build() | ||
.start(); | ||
Topic tp = Topic.of(topic); | ||
publisher.publish("1", tp); | ||
publisher.publish("2", tp); | ||
publisher.publish("3", tp); | ||
publisher.publish("4", tp); | ||
publisher.publish("5", tp); | ||
|
||
await().until(() -> isAlive()); | ||
|
||
HealthReport startup = getHealth().getStartup(); | ||
HealthReport liveness = getHealth().getLiveness(); | ||
HealthReport readiness = getHealth().getReadiness(); | ||
|
||
assertThat(startup.isOk()).isTrue(); | ||
assertThat(liveness.isOk()).isTrue(); | ||
assertThat(readiness.isOk()).isTrue(); | ||
assertThat(startup.getChannels()).hasSize(1); | ||
assertThat(liveness.getChannels()).hasSize(1); | ||
assertThat(readiness.getChannels()).hasSize(1); | ||
|
||
} | ||
|
||
@Test | ||
void solaceConsumerLivenessCheck() { | ||
MapBasedConfig config = new MapBasedConfig() | ||
.with("mp.messaging.incoming.in.connector", "quarkus-solace") | ||
.with("mp.messaging.incoming.in.consumer.queue.name", queue) | ||
.with("mp.messaging.incoming.in.consumer.queue.add-additional-subscriptions", "true") | ||
.with("mp.messaging.incoming.in.consumer.queue.missing-resource-creation-strategy", "create-on-start") | ||
.with("mp.messaging.incoming.in.consumer.queue.subscriptions", topic); | ||
|
||
// Run app that consumes messages | ||
MyErrorConsumer app = runApplication(config, MyErrorConsumer.class); | ||
|
||
await().until(() -> isStarted() && isReady()); | ||
|
||
// Produce messages | ||
PersistentMessagePublisher publisher = messagingService.createPersistentMessagePublisherBuilder() | ||
.build() | ||
.start(); | ||
Topic tp = Topic.of(topic); | ||
publisher.publish("1", tp); | ||
publisher.publish("2", tp); | ||
|
||
await().until(() -> isAlive()); | ||
|
||
HealthReport startup = getHealth().getStartup(); | ||
HealthReport liveness = getHealth().getLiveness(); | ||
HealthReport readiness = getHealth().getReadiness(); | ||
|
||
assertThat(startup.isOk()).isTrue(); | ||
assertThat(liveness.isOk()).isTrue(); | ||
assertThat(readiness.isOk()).isTrue(); | ||
assertThat(startup.getChannels()).hasSize(1); | ||
assertThat(liveness.getChannels()).hasSize(1); | ||
assertThat(readiness.getChannels()).hasSize(1); | ||
|
||
publisher.publish("3", tp); | ||
await().until(() -> { | ||
HealthReport healthReport = getHealth().getLiveness(); | ||
return (healthReport.isOk() == false && !healthReport.getChannels().get(0).getMessage().isEmpty()); | ||
}); | ||
|
||
publisher.publish("4", tp); | ||
publisher.publish("5", tp); | ||
await().until(() -> getHealth().getLiveness().isOk() == true); | ||
} | ||
|
||
@ApplicationScoped | ||
static class MyConsumer { | ||
private final List<String> received = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("in") | ||
void in(InboundMessage msg) { | ||
received.add(msg.getPayloadAsString()); | ||
} | ||
|
||
public List<String> getReceived() { | ||
return received; | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
static class MyErrorConsumer { | ||
private final List<String> received = new CopyOnWriteArrayList<>(); | ||
|
||
@Incoming("in") | ||
CompletionStage<Void> in(SolaceInboundMessage<byte[]> msg) { | ||
String payload = new String(msg.getPayload(), StandardCharsets.UTF_8); | ||
if (payload.equals("3")) { | ||
return msg.nack(new IllegalArgumentException("Nacking message with payload 3")); | ||
} | ||
|
||
return msg.ack(); | ||
} | ||
} | ||
} |
Oops, something went wrong.