Skip to content

Commit f77f3f1

Browse files
committed
Improve tests
1 parent f43d271 commit f77f3f1

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

stork-programmatic-custom-registration-quickstart/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
<groupId>io.smallrye.stork</groupId>
4848
<artifactId>stork-configuration-generator</artifactId>
4949
</dependency>
50+
<dependency>
51+
<groupId>io.smallrye.stork</groupId>
52+
<artifactId>stork-service-discovery-static-list</artifactId>
53+
</dependency>
5054
<dependency>
5155
<groupId>io.quarkus</groupId>
5256
<artifactId>quarkus-arc</artifactId>

stork-programmatic-custom-registration-quickstart/src/main/java/org/acme/services/CustomServiceRegistrar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.smallrye.mutiny.Uni;
44
import io.smallrye.stork.api.Metadata;
55
import io.smallrye.stork.api.ServiceRegistrar;
6+
import io.smallrye.stork.utils.InMemoryAddressesBackend;
67

78
import org.jboss.logging.Logger;
89

@@ -28,6 +29,7 @@ public Uni<Void> registerServiceInstance(String serviceName, Metadata metadata,
2829
String address = ipAddress + ":" + defaultPort;
2930
LOGGER.info("Registering service: " + serviceName + " with ipAddress: " + ipAddress + " and port: " + defaultPort);
3031
registeredInstances.put(serviceName, address);
32+
InMemoryAddressesBackend.add(serviceName, address);
3133
return Uni.createFrom().voidItem();
3234
}
3335

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Registration {
1515
*
1616
* Note: this method is called on a worker thread, and so it is allowed to block.
1717
*/
18-
public void init(@Observes StartupEvent ev, Vertx vertx) {
18+
public void init(@Observes StartupEvent ev) {
1919
Stork.getInstance().getService("my-service").registerInstance("my-service", "localhost",
2020
9000);
2121
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
quarkus.stork.my-service.service-registrar.type=custom
22
quarkus.stork.my-service.service-registrar.host=localhost
3+
quarkus.stork.my-service.service-discovery.type=static
Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
package org.acme;
22

3-
import jakarta.inject.Inject;
3+
import java.util.List;
44

5-
import org.acme.services.Registration;
65
import org.junit.jupiter.api.Assertions;
76
import org.junit.jupiter.api.Test;
87

98
import io.quarkus.test.junit.QuarkusTest;
9+
import io.smallrye.stork.Stork;
10+
import io.smallrye.stork.api.Service;
11+
import io.smallrye.stork.api.ServiceInstance;
1012

1113
@QuarkusTest
1214
public class ClientCallingResourceTest {
1315

14-
@Inject
15-
Registration registration;
16-
1716
@Test
18-
public void test() {
19-
Assertions.assertNotNull(registration);
17+
public void testDiscoverRegisteredInstances() {
18+
Stork stork = Stork.getInstance();
19+
Service service = stork.getService("my-service");
20+
21+
// Use Stork service discovery to resolve instances registered at startup
22+
List<ServiceInstance> instances = service.getInstances().await().indefinitely();
23+
24+
Assertions.assertFalse(instances.isEmpty(),
25+
"Service discovery should resolve at least one registered instance");
26+
27+
ServiceInstance instance = instances.get(0);
28+
Assertions.assertEquals("localhost", instance.getHost());
29+
Assertions.assertEquals(9000, instance.getPort());
2030
}
2131

2232
}

0 commit comments

Comments
 (0)