Skip to content

Commit

Permalink
Merge pull request quarkusio#36537 from ozangunalp/apicurio_continuou…
Browse files Browse the repository at this point in the history
…s_testing_fix

Reset the Apicurio registry client in dev mode and tests
  • Loading branch information
gsmet authored Oct 18, 2023
2 parents 7072955 + de440ad commit 8208631
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.smallrye.openapi.deployment.spi.IgnoreStaticDocumentBuildItem;
Expand Down Expand Up @@ -48,7 +49,10 @@ void ignoreIncludedOpenAPIDocument(BuildProducer<IgnoreStaticDocumentBuildItem>

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client) {
public void apicurioRegistryClient(VertxBuildItem vertx, ApicurioRegistryClient client, LaunchModeBuildItem launchMode) {
if (launchMode.getLaunchMode().isDevOrTest()) {
client.clearHttpClient();
}
client.setup(vertx.getVertx());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.apicurio.registry.common;

import org.junit.jupiter.api.Test;

import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;

public class ApicurioRegistryInternalsExpectationTest {
@Test
public void test() throws NoSuchFieldException {
// we need this to reset the client in continuous testing
ApicurioHttpClientFactory.class.getDeclaredField("providerReference");
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
package io.quarkus.apicurio.registry.common;

import java.lang.reflect.Field;
import java.util.concurrent.atomic.AtomicReference;

import org.jboss.logging.Logger;

import io.apicurio.registry.rest.client.RegistryClientFactory;
import io.apicurio.rest.client.VertxHttpClientProvider;
import io.apicurio.rest.client.spi.ApicurioHttpClientFactory;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Vertx;

@Recorder
public class ApicurioRegistryClient {

private static final Logger log = Logger.getLogger(ApicurioRegistryClient.class);

public void setup(RuntimeValue<Vertx> vertx) {
RegistryClientFactory.setProvider(new VertxHttpClientProvider(vertx.getValue()));
}
}

public void clearHttpClient() {
try {
Field providerReference = ApicurioHttpClientFactory.class.getDeclaredField("providerReference");
providerReference.setAccessible(true);
AtomicReference ref = (AtomicReference) providerReference.get(null);
ref.set(null);
} catch (NoSuchFieldException | IllegalAccessException t) {
log.error("Failed to clear Apicurio Http Client provider", t);
}
}
}

0 comments on commit 8208631

Please sign in to comment.