Skip to content

Commit f2664d7

Browse files
authored
fix(vertx-client): Make sure to close the Vertx instance in the maven plugin (#5676)
* Fix an issue where migrating from v2 to v3 failed to create the "latest" branch * spotless:apply * Sort versions when importing from a v2 zip * Remove defaultVertx from VertxAuthFactory * spotless:apply
1 parent fb8dc52 commit f2664d7

File tree

49 files changed

+529
-436
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+529
-436
lines changed

app/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@
251251
<artifactId>apicurio-registry-avro-serde-kafka</artifactId>
252252
<scope>test</scope>
253253
</dependency>
254+
<dependency>
255+
<groupId>io.apicurio</groupId>
256+
<artifactId>apicurio-registry-java-sdk</artifactId>
257+
<scope>test</scope>
258+
</dependency>
254259
<dependency>
255260
<groupId>io.apicurio</groupId>
256261
<artifactId>apicurio-registry-protobuf-serde-kafka</artifactId>

app/src/test/java/io/apicurio/registry/AbstractResourceTestBase.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.microsoft.kiota.ApiException;
44
import com.microsoft.kiota.RequestAdapter;
5-
import io.apicurio.registry.client.auth.VertXAuthFactory;
65
import io.apicurio.registry.model.GroupId;
76
import io.apicurio.registry.rest.client.RegistryClient;
87
import io.apicurio.registry.rest.client.models.CreateArtifact;
@@ -26,6 +25,7 @@
2625
import io.restassured.RestAssured;
2726
import io.restassured.parsing.Parser;
2827
import io.restassured.response.ValidatableResponse;
28+
import io.vertx.core.Vertx;
2929
import org.junit.jupiter.api.AfterAll;
3030
import org.junit.jupiter.api.Assertions;
3131
import org.junit.jupiter.api.BeforeAll;
@@ -60,26 +60,29 @@ public abstract class AbstractResourceTestBase extends AbstractRegistryTestBase
6060
protected RegistryClient clientV3;
6161
protected RestService confluentClient;
6262

63+
protected Vertx vertx;
64+
6365
@BeforeAll
6466
protected void beforeAll() throws Exception {
67+
vertx = Vertx.vertx();
6568
String serverUrl = "http://localhost:%s/apis";
6669
registryApiBaseUrl = String.format(serverUrl, testPort);
6770
registryV3ApiUrl = registryApiBaseUrl + "/registry/v3";
68-
clientV3 = createRestClientV3();
71+
clientV3 = createRestClientV3(vertx);
6972
confluentClient = buildConfluentClient();
7073
}
7174

7275
@AfterAll
7376
protected void afterAll() {
77+
vertx.close();
7478
}
7579

7680
protected RestService buildConfluentClient() {
7781
return new RestService("http://localhost:" + testPort + "/apis/ccompat/v7");
7882
}
7983

80-
protected final RequestAdapter anonymousAdapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
81-
82-
protected RegistryClient createRestClientV3() {
84+
protected RegistryClient createRestClientV3(Vertx vertx) {
85+
RequestAdapter anonymousAdapter = new VertXRequestAdapter(vertx);
8386
anonymousAdapter.setBaseUrl(registryV3ApiUrl);
8487
var client = new RegistryClient(anonymousAdapter);
8588
return client;

app/src/test/java/io/apicurio/registry/auth/AuthTestAnonymousCredentials.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.microsoft.kiota.ApiException;
44
import io.apicurio.common.apps.config.Info;
55
import io.apicurio.registry.AbstractResourceTestBase;
6-
import io.apicurio.registry.client.auth.VertXAuthFactory;
76
import io.apicurio.registry.rest.client.RegistryClient;
87
import io.apicurio.registry.rest.client.models.CreateArtifact;
98
import io.apicurio.registry.types.ArtifactType;
@@ -37,7 +36,7 @@ public class AuthTestAnonymousCredentials extends AbstractResourceTestBase {
3736
@Test
3837
public void testWrongCreds() throws Exception {
3938
var adapter = new VertXRequestAdapter(
40-
buildOIDCWebClient(authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
39+
buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
4140
adapter.setBaseUrl(registryV3ApiUrl);
4241
RegistryClient client = new RegistryClient(adapter);
4342

@@ -50,7 +49,7 @@ public void testWrongCreds() throws Exception {
5049

5150
@Test
5251
public void testNoCredentials() throws Exception {
53-
var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
52+
var adapter = new VertXRequestAdapter(vertx);
5453
adapter.setBaseUrl(registryV3ApiUrl);
5554
RegistryClient client = new RegistryClient(adapter);
5655
// Read-only operation should work without any credentials.

app/src/test/java/io/apicurio/registry/auth/AuthTestAuthenticatedReadAccess.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.AbstractResourceTestBase;
5+
import io.apicurio.registry.client.auth.VertXAuthFactory;
56
import io.apicurio.registry.rest.client.RegistryClient;
67
import io.apicurio.registry.rest.client.models.CreateArtifact;
78
import io.apicurio.registry.types.ArtifactType;
@@ -13,13 +14,12 @@
1314
import io.kiota.http.vertx.VertXRequestAdapter;
1415
import io.quarkus.test.junit.QuarkusTest;
1516
import io.quarkus.test.junit.TestProfile;
17+
import io.vertx.core.Vertx;
1618
import org.eclipse.microprofile.config.inject.ConfigProperty;
1719
import org.junit.jupiter.api.Assertions;
1820
import org.junit.jupiter.api.Tag;
1921
import org.junit.jupiter.api.Test;
2022

21-
import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient;
22-
2323
@QuarkusTest
2424
@TestProfile(AuthTestProfileAuthenticatedReadAccess.class)
2525
@Tag(ApicurioTestTags.SLOW)
@@ -32,18 +32,18 @@ public class AuthTestAuthenticatedReadAccess extends AbstractResourceTestBase {
3232
final String groupId = getClass().getSimpleName() + "Group";
3333

3434
@Override
35-
protected RegistryClient createRestClientV3() {
36-
var adapter = new VertXRequestAdapter(
37-
buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
35+
protected RegistryClient createRestClientV3(Vertx vertx) {
36+
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl,
37+
JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
3838
adapter.setBaseUrl(registryV3ApiUrl);
3939
return new RegistryClient(adapter);
4040
}
4141

4242
@Test
4343
public void testReadOperationWithNoRole() throws Exception {
4444
// Read-only operation should work with credentials but no role.
45-
var adapter = new VertXRequestAdapter(
46-
buildOIDCWebClient(authServerUrl, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
45+
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx, authServerUrl,
46+
JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
4747
adapter.setBaseUrl(registryV3ApiUrl);
4848
RegistryClient client = new RegistryClient(adapter);
4949
var results = client.search().artifacts().get(config -> config.queryParameters.groupId = groupId);

app/src/test/java/io/apicurio/registry/auth/AuthTestLocalRoles.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.AbstractResourceTestBase;
5+
import io.apicurio.registry.client.auth.VertXAuthFactory;
56
import io.apicurio.registry.model.GroupId;
67
import io.apicurio.registry.rest.client.RegistryClient;
78
import io.apicurio.registry.rest.client.models.CreateArtifact;
@@ -20,6 +21,7 @@
2021
import io.kiota.http.vertx.VertXRequestAdapter;
2122
import io.quarkus.test.junit.QuarkusTest;
2223
import io.quarkus.test.junit.TestProfile;
24+
import io.vertx.core.Vertx;
2325
import org.eclipse.microprofile.config.inject.ConfigProperty;
2426
import org.junit.jupiter.api.Assertions;
2527
import org.junit.jupiter.api.Tag;
@@ -46,9 +48,9 @@ public class AuthTestLocalRoles extends AbstractResourceTestBase {
4648
String authServerUrlConfigured;
4749

4850
@Override
49-
protected RegistryClient createRestClientV3() {
51+
protected RegistryClient createRestClientV3(Vertx vertx) {
5052
var adapter = new VertXRequestAdapter(
51-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
53+
buildOIDCWebClient(vertx, authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
5254
adapter.setBaseUrl(registryV3ApiUrl);
5355
return new RegistryClient(adapter);
5456
}
@@ -65,13 +67,13 @@ protected RegistryClient createRestClientV3() {
6567

6668
@Test
6769
public void testLocalRoles() throws Exception {
68-
var adapterAdmin = new VertXRequestAdapter(
69-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
70+
var adapterAdmin = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
71+
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
7072
adapterAdmin.setBaseUrl(registryV3ApiUrl);
7173
RegistryClient clientAdmin = new RegistryClient(adapterAdmin);
7274

73-
var adapterAuth = new VertXRequestAdapter(
74-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
75+
var adapterAuth = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
76+
authServerUrlConfigured, JWKSMockServer.NO_ROLE_CLIENT_ID, "test1"));
7577
adapterAuth.setBaseUrl(registryV3ApiUrl);
7678
RegistryClient client = new RegistryClient(adapterAuth);
7779

app/src/test/java/io/apicurio/registry/auth/AuthTestNoRoles.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.AbstractResourceTestBase;
5+
import io.apicurio.registry.client.auth.VertXAuthFactory;
56
import io.apicurio.registry.model.GroupId;
67
import io.apicurio.registry.rest.client.RegistryClient;
78
import io.apicurio.registry.rest.client.models.CreateArtifact;
@@ -19,12 +20,12 @@
1920
import io.kiota.http.vertx.VertXRequestAdapter;
2021
import io.quarkus.test.junit.QuarkusTest;
2122
import io.quarkus.test.junit.TestProfile;
23+
import io.vertx.core.Vertx;
2224
import org.eclipse.microprofile.config.inject.ConfigProperty;
2325
import org.junit.jupiter.api.Assertions;
2426
import org.junit.jupiter.api.Tag;
2527
import org.junit.jupiter.api.Test;
2628

27-
import static io.apicurio.registry.client.auth.VertXAuthFactory.buildOIDCWebClient;
2829
import static org.junit.jupiter.api.Assertions.assertNotNull;
2930
import static org.junit.jupiter.api.Assertions.assertTrue;
3031

@@ -40,17 +41,17 @@ public class AuthTestNoRoles extends AbstractResourceTestBase {
4041
final String groupId = "authTestGroupId";
4142

4243
@Override
43-
protected RegistryClient createRestClientV3() {
44-
var adapter = new VertXRequestAdapter(
45-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
44+
protected RegistryClient createRestClientV3(Vertx vertx) {
45+
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
46+
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
4647
adapter.setBaseUrl(registryV3ApiUrl);
4748
return new RegistryClient(adapter);
4849
}
4950

5051
@Test
5152
public void testWrongCreds() throws Exception {
52-
var adapter = new VertXRequestAdapter(
53-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
53+
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
54+
authServerUrlConfigured, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
5455
adapter.setBaseUrl(registryV3ApiUrl);
5556
RegistryClient client = new RegistryClient(adapter);
5657
var exception = Assertions.assertThrows(Exception.class, () -> {
@@ -61,8 +62,8 @@ public void testWrongCreds() throws Exception {
6162

6263
@Test
6364
public void testAdminRole() throws Exception {
64-
var adapter = new VertXRequestAdapter(
65-
buildOIDCWebClient(authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
65+
var adapter = new VertXRequestAdapter(VertXAuthFactory.buildOIDCWebClient(vertx,
66+
authServerUrlConfigured, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
6667
adapter.setBaseUrl(registryV3ApiUrl);
6768
RegistryClient client = new RegistryClient(adapter);
6869
String artifactId = TestUtils.generateArtifactId();

app/src/test/java/io/apicurio/registry/auth/AuthTestProfileBasicClientCredentials.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import io.apicurio.common.apps.config.Info;
44
import io.apicurio.registry.AbstractResourceTestBase;
5-
import io.apicurio.registry.client.auth.VertXAuthFactory;
65
import io.apicurio.registry.model.GroupId;
76
import io.apicurio.registry.rest.client.RegistryClient;
87
import io.apicurio.registry.rest.client.models.CreateArtifact;
@@ -20,6 +19,7 @@
2019
import io.kiota.http.vertx.VertXRequestAdapter;
2120
import io.quarkus.test.junit.QuarkusTest;
2221
import io.quarkus.test.junit.TestProfile;
22+
import io.vertx.core.Vertx;
2323
import org.eclipse.microprofile.config.inject.ConfigProperty;
2424
import org.junit.jupiter.api.Assertions;
2525
import org.junit.jupiter.api.Tag;
@@ -41,17 +41,17 @@ public class AuthTestProfileBasicClientCredentials extends AbstractResourceTestB
4141
final String groupId = "authTestGroupId";
4242

4343
@Override
44-
protected RegistryClient createRestClientV3() {
44+
protected RegistryClient createRestClientV3(Vertx vertx) {
4545
var adapter = new VertXRequestAdapter(
46-
buildOIDCWebClient(authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
46+
buildOIDCWebClient(vertx, authServerUrl, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
4747
adapter.setBaseUrl(registryV3ApiUrl);
4848
return new RegistryClient(adapter);
4949
}
5050

5151
@Test
5252
public void testWrongCreds() throws Exception {
5353
var adapter = new VertXRequestAdapter(
54-
buildSimpleAuthWebClient(JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
54+
buildSimpleAuthWebClient(vertx, JWKSMockServer.WRONG_CREDS_CLIENT_ID, "test55"));
5555
adapter.setBaseUrl(registryV3ApiUrl);
5656
RegistryClient client = new RegistryClient(adapter);
5757
var exception = Assertions.assertThrows(Exception.class, () -> {
@@ -63,7 +63,7 @@ public void testWrongCreds() throws Exception {
6363
@Test
6464
public void testBasicAuthClientCredentials() throws Exception {
6565
var adapter = new VertXRequestAdapter(
66-
buildSimpleAuthWebClient(JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
66+
buildSimpleAuthWebClient(vertx, JWKSMockServer.ADMIN_CLIENT_ID, "test1"));
6767
adapter.setBaseUrl(registryV3ApiUrl);
6868
RegistryClient client = new RegistryClient(adapter);
6969
String artifactId = TestUtils.generateArtifactId();
@@ -99,7 +99,7 @@ public void testBasicAuthClientCredentials() throws Exception {
9999

100100
@Test
101101
public void testNoCredentials() throws Exception {
102-
var adapter = new VertXRequestAdapter(VertXAuthFactory.defaultVertx);
102+
var adapter = new VertXRequestAdapter(vertx);
103103
adapter.setBaseUrl(registryV3ApiUrl);
104104
RegistryClient client = new RegistryClient(adapter);
105105
var exception = Assertions.assertThrows(Exception.class, () -> {

0 commit comments

Comments
 (0)