Skip to content

Commit

Permalink
Add a config property to disable the VertxCurrentContextFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Sep 7, 2022
1 parent 9cd24c4 commit eae9110
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkus.vertx.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = "vertx", phase = ConfigPhase.BUILD_TIME)
public class VertxBuildConfig {

/**
* If set to {@code true} then a customized current context factory (backed by a Vert.x duplicated local context) is used
* for normal scopes in ArC.
*/
@ConfigItem(generateDocumentation = false, defaultValue = "true")
public boolean customizeArcContext;

}
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ VertxBuildItem build(CoreVertxBuildItem vertx, VertxRecorder recorder,

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
CurrentContextFactoryBuildItem currentContextFactory(VertxRecorder recorder) {
return new CurrentContextFactoryBuildItem(recorder.currentContextFactory());
void currentContextFactory(BuildProducer<CurrentContextFactoryBuildItem> currentContextFactory,
VertxBuildConfig buildConfig, VertxRecorder recorder) {
if (buildConfig.customizeArcContext) {
currentContextFactory.produce(new CurrentContextFactoryBuildItem(recorder.currentContextFactory()));
}
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.vertx.deployment.currentcontextfactory;

import static org.junit.jupiter.api.Assertions.assertFalse;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.arc.Arc;
import io.quarkus.test.QuarkusUnitTest;
import io.quarkus.vertx.runtime.VertxCurrentContextFactory;

public class VertxCurrentContextFactoryDisabledTest {

@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.overrideConfigKey("quarkus.vertx.customize-arc-context", "false");

@Test
public void testCustomizedFactoryNotUsed() {
assertFalse(Arc.container().getCurrentContextFactory() instanceof VertxCurrentContextFactory);
}

}

0 comments on commit eae9110

Please sign in to comment.