-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add smallrye coverage to integrations tests
- Loading branch information
Showing
22 changed files
with
204 additions
and
361 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
30 changes: 30 additions & 0 deletions
30
...ient-smallrye/src/main/java/io/quarkiverse/hivemqclient/test/smallrye/PriceConverter.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,30 @@ | ||
package io.quarkiverse.hivemqclient.test.smallrye; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Incoming; | ||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.smallrye.reactive.messaging.annotations.Broadcast; | ||
|
||
/** | ||
* A bean consuming data from the "prices" MQTT topic and applying some conversion. | ||
* The result is pushed to the "my-data-stream" stream which is an in-memory stream. | ||
*/ | ||
@ApplicationScoped | ||
public class PriceConverter { | ||
|
||
private static final Logger LOG = Logger.getLogger(PriceConverter.class); | ||
private static final double CONVERSION_RATE = 0.88; | ||
|
||
@Incoming("prices") | ||
@Outgoing("my-data-stream") | ||
@Broadcast | ||
public double process(byte[] priceRaw) { | ||
int priceInUsd = Integer.parseInt(new String(priceRaw)); | ||
LOG.infof("Receiving price: %d ", priceInUsd); | ||
return priceInUsd * CONVERSION_RATE; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...ient-smallrye/src/main/java/io/quarkiverse/hivemqclient/test/smallrye/PriceGenerator.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,35 @@ | ||
package io.quarkiverse.hivemqclient.test.smallrye; | ||
|
||
import java.time.Duration; | ||
import java.util.Random; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Outgoing; | ||
import org.jboss.logging.Logger; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
|
||
/** | ||
* A bean producing random prices every second. | ||
* The prices are written to a MQTT topic (prices). The MQTT configuration is specified in the application configuration. | ||
*/ | ||
@ApplicationScoped | ||
public class PriceGenerator { | ||
|
||
private static final Logger LOG = Logger.getLogger(PriceGenerator.class); | ||
|
||
private Random random = new Random(); | ||
|
||
@Outgoing("topic-price") | ||
public Multi<Integer> generate() { | ||
return Multi.createFrom().ticks().every(Duration.ofSeconds(1)) | ||
.onOverflow().drop() | ||
.map(tick -> { | ||
int price = random.nextInt(100); | ||
LOG.infof("Sending price: %d", price); | ||
return price; | ||
}); | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...lient-smallrye/src/main/java/io/quarkiverse/hivemqclient/test/smallrye/PriceResource.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,35 @@ | ||
package io.quarkiverse.hivemqclient.test.smallrye; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
import org.eclipse.microprofile.reactive.messaging.Channel; | ||
|
||
import io.smallrye.mutiny.Multi; | ||
|
||
/** | ||
* A simple resource retrieving the "in-memory" "my-data-stream" and sending the items to a server sent event. | ||
*/ | ||
@Path("/prices") | ||
public class PriceResource { | ||
|
||
@Inject | ||
@Channel("my-data-stream") | ||
Multi<Double> prices; | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "hello"; | ||
} | ||
|
||
@GET | ||
@Path("/stream") | ||
@Produces(MediaType.SERVER_SENT_EVENTS) | ||
public Multi<Double> stream() { | ||
return prices; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
integration-tests/hivemq-client-smallrye/src/main/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,13 @@ | ||
# Configure the MQTT sink (we write to it) | ||
mp.messaging.outgoing.topic-price.type=smallrye-mqtt-hivemq | ||
mp.messaging.outgoing.topic-price.topic=prices | ||
mp.messaging.outgoing.topic-price.host=localhost | ||
mp.messaging.outgoing.topic-price.port=1883 | ||
mp.messaging.outgoing.topic-price.auto-generated-client-id=true | ||
|
||
# Configure the MQTT source (we read from it) | ||
mp.messaging.incoming.prices.type=smallrye-mqtt-hivemq | ||
mp.messaging.incoming.prices.topic=prices | ||
mp.messaging.incoming.prices.host=localhost | ||
mp.messaging.incoming.prices.port=1883 | ||
mp.messaging.incoming.prices.auto-generated-client-id=true |
2 changes: 1 addition & 1 deletion
2
...nt/test/vanilla/HivemqDefaultProfile.java → ...t/test/smallrye/HivemqDefaultProfile.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
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
7 changes: 7 additions & 0 deletions
7
...ent-smallrye/src/test/java/io/quarkiverse/hivemqclient/test/smallrye/PriceResourceIT.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,7 @@ | ||
package io.quarkiverse.hivemqclient.test.smallrye; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
public class PriceResourceIT extends PriceResourceTest { | ||
} |
62 changes: 62 additions & 0 deletions
62
...t-smallrye/src/test/java/io/quarkiverse/hivemqclient/test/smallrye/PriceResourceTest.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,62 @@ | ||
package io.quarkiverse.hivemqclient.test.smallrye; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.net.URI; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.client.WebTarget; | ||
import javax.ws.rs.sse.SseEventSource; | ||
|
||
import org.jboss.logging.Logger; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.common.http.TestHTTPResource; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.TestProfile; | ||
|
||
@TestProfile(HivemqDefaultProfile.class) | ||
@QuarkusTest | ||
public class PriceResourceTest { | ||
|
||
private static final Logger LOG = Logger.getLogger(PriceResourceTest.class); | ||
|
||
@TestHTTPResource("prices/stream") | ||
URI pricesUrl; | ||
|
||
@Test | ||
public void shouldGetHello() { | ||
given() | ||
.when().get("/prices") | ||
.then() | ||
.statusCode(200) | ||
.body(is("hello")); | ||
} | ||
|
||
@Test | ||
public void shouldGetStreamOfPrices() { | ||
Client client = ClientBuilder.newClient(); | ||
WebTarget target = client.target(pricesUrl); | ||
|
||
AtomicInteger priceCount = new AtomicInteger(); | ||
|
||
try (SseEventSource source = SseEventSource.target(target).build()) { | ||
source.register(event -> { | ||
Double value = event.readData(Double.class); | ||
LOG.infof("Received price: %f", value); | ||
priceCount.incrementAndGet(); | ||
}); | ||
source.open(); | ||
Thread.sleep(15 * 1000L); | ||
} catch (InterruptedException ignored) { | ||
} | ||
|
||
int count = priceCount.get(); | ||
assertTrue(count > 1, "Expected more than 2 prices read from the source, got " + count); | ||
} | ||
|
||
} |
12 changes: 0 additions & 12 deletions
12
...vanilla/src/main/java/io/quarkiverse/hivemqclient/test/vanilla/HttpBridgeApplication.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...client-vanilla/src/main/java/io/quarkiverse/hivemqclient/test/vanilla/dto/MessageDto.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...vanilla/src/main/java/io/quarkiverse/hivemqclient/test/vanilla/dto/PublishMsgRespDto.java
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
...n/java/io/quarkiverse/hivemqclient/test/vanilla/resources/BrokerPushToTopicResources.java
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
...a/io/quarkiverse/hivemqclient/test/vanilla/resources/BrokerSubscribeToTopicResources.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.