Skip to content

Commit fde2891

Browse files
committed
refactor
1 parent 31859e4 commit fde2891

File tree

3 files changed

+21
-30
lines changed

3 files changed

+21
-30
lines changed

stork-registration-quickstart/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@
4747
<groupId>io.smallrye.stork</groupId>
4848
<artifactId>stork-service-registration-consul</artifactId>
4949
</dependency>
50-
<!-- -&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;-->
51-
52-
<!-- <dependency>-->
53-
<!-- <groupId>io.quarkus</groupId>-->
54-
<!-- <artifactId>quarkus-smallrye-stork</artifactId>-->
55-
<!-- </dependency>-->
56-
<!-- <dependency>-->
57-
<!-- <groupId>io.smallrye.stork</groupId>-->
58-
<!-- <artifactId>stork-service-discovery-consul</artifactId>-->
59-
<!-- </dependency>-->
60-
<!-- <dependency>-->
61-
<!-- <groupId>io.smallrye.reactive</groupId>-->
62-
<!-- <artifactId>smallrye-mutiny-vertx-consul-client</artifactId>-->
63-
<!-- </dependency>-->
6450
<dependency>
6551
<groupId>io.quarkus</groupId>
6652
<artifactId>quarkus-arc</artifactId>

stork-registration-quickstart/src/main/java/org/acme/services/Registration.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
import jakarta.enterprise.event.Observes;
88
import org.eclipse.microprofile.config.inject.ConfigProperty;
99

10+
import java.util.concurrent.CountDownLatch;
11+
12+
import static io.smallrye.mutiny.helpers.Subscriptions.fail;
13+
1014
@ApplicationScoped
1115
public class Registration {
1216

@@ -19,7 +23,9 @@ public class Registration {
1923
* Note: this method is called on a worker thread, and so it is allowed to block.
2024
*/
2125
public void init(@Observes StartupEvent ev, Vertx vertx) {
22-
Stork.getInstance().getService("my-service").getServiceRegistrar().registerServiceInstance("my-service", "localhost",
23-
red);
26+
CountDownLatch registrationLatch = new CountDownLatch(1);
27+
Stork.getInstance().getService("my-service").getServiceRegistrar().registerServiceInstance("red", "localhost",
28+
red).subscribe()
29+
.with(success -> registrationLatch.countDown(), failure -> System.out.println("Registration failed"));;
2430
}
2531
}

stork-registration-quickstart/src/test/java/org/acme/RegistrationTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@
33
import io.quarkus.test.common.WithTestResource;
44
import io.quarkus.test.junit.QuarkusTest;
55
import io.restassured.RestAssured;
6-
import io.restassured.http.ContentType;
7-
import io.smallrye.stork.Stork;
8-
import io.vertx.core.Vertx;
9-
import io.vertx.ext.consul.ConsulClient;
10-
import io.vertx.ext.consul.ConsulClientOptions;
11-
import org.junit.jupiter.api.Assertions;
12-
import org.junit.jupiter.api.BeforeEach;
6+
import jakarta.inject.Inject;
7+
import org.eclipse.microprofile.config.inject.ConfigProperty;
138
import org.junit.jupiter.api.Test;
14-
import org.testcontainers.containers.GenericContainer;
15-
import org.testcontainers.utility.DockerImageName;
16-
17-
import java.util.HashSet;
18-
import java.util.Set;
199

2010
import static io.restassured.RestAssured.given;
2111
import static org.hamcrest.CoreMatchers.containsString;
@@ -25,11 +15,20 @@
2515
@WithTestResource(ConsulTestResource.class)
2616
public class RegistrationTest {
2717

18+
@Inject
19+
@ConfigProperty(name = "consul.host")
20+
String consulHost;
21+
22+
@Inject
23+
@ConfigProperty(name = "consul.port")
24+
String consulPort;
25+
2826

29-
@Test
27+
@Test
3028
public void test() {
29+
String consulUrl = "http://" + consulHost + ":" + consulPort;
3130
// curl -X GET http://127.0.0.1:8500/v1/agent/service/red
32-
RestAssured.get("http://127.0.0.1:8500/v1/agent/service/red").then().statusCode(200).body(containsString("red"), containsString("my-service"));
31+
RestAssured.get(consulUrl+"/v1/agent/service/red").then().statusCode(200).body(containsString("red"), containsString("\"Service\": \"red\""));
3332

3433
}
3534

0 commit comments

Comments
 (0)