Skip to content

Commit 8208631

Browse files
authored
Merge pull request #36537 from ozangunalp/apicurio_continuous_testing_fix
Reset the Apicurio registry client in dev mode and tests
2 parents 7072955 + de440ad commit 8208631

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

extensions/schema-registry/apicurio/common/deployment/src/main/java/io/quarkus/apicurio/registry/common/ApicurioRegistryClientProcessor.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.quarkus.deployment.annotations.ExecutionTime;
99
import io.quarkus.deployment.annotations.Record;
1010
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
11+
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
1112
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
1213
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
1314
import io.quarkus.smallrye.openapi.deployment.spi.IgnoreStaticDocumentBuildItem;
@@ -48,7 +49,10 @@ void ignoreIncludedOpenAPIDocument(BuildProducer<IgnoreStaticDocumentBuildItem>
4849

4950
@BuildStep
5051
@Record(ExecutionTime.RUNTIME_INIT)
51-
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client) {
52+
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client, LaunchModeBuildItem launchMode) {
53+
if (launchMode.getLaunchMode().isDevOrTest()) {
54+
client.clearHttpClient();
55+
}
5256
client.setup(vertx.getVertx());
5357
}
5458

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.quarkus.apicurio.registry.common;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
6+
7+
public class ApicurioRegistryInternalsExpectationTest {
8+
@Test
9+
public void test() throws NoSuchFieldException {
10+
// we need this to reset the client in continuous testing
11+
ApicurioHttpClientFactory.class.getDeclaredField("providerReference");
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,34 @@
11
package io.quarkus.apicurio.registry.common;
22

3+
import java.lang.reflect.Field;
4+
import java.util.concurrent.atomic.AtomicReference;
5+
6+
import org.jboss.logging.Logger;
7+
38
import io.apicurio.registry.rest.client.RegistryClientFactory;
49
import io.apicurio.rest.client.VertxHttpClientProvider;
10+
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
511
import io.quarkus.runtime.RuntimeValue;
612
import io.quarkus.runtime.annotations.Recorder;
713
import io.vertx.core.Vertx;
814

915
@Recorder
1016
public class ApicurioRegistryClient {
17+
18+
private static final Logger log = Logger.getLogger(ApicurioRegistryClient.class);
19+
1120
public void setup(RuntimeValue<Vertx> vertx) {
1221
RegistryClientFactory.setProvider(new VertxHttpClientProvider(vertx.getValue()));
1322
}
14-
}
23+
24+
public void clearHttpClient() {
25+
try {
26+
Field providerReference = ApicurioHttpClientFactory.class.getDeclaredField("providerReference");
27+
providerReference.setAccessible(true);
28+
AtomicReference ref = (AtomicReference) providerReference.get(null);
29+
ref.set(null);
30+
} catch (NoSuchFieldException | IllegalAccessException t) {
31+
log.error("Failed to clear Apicurio Http Client provider", t);
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)