-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC - make it possible to disable context propagation
- Loading branch information
Showing
10 changed files
with
187 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...s/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcContextPropagationConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.arc.deployment; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class ArcContextPropagationConfig { | ||
|
||
/** | ||
* If set to true and SmallRye Context Propagation extension is present then enable the context propagation for CDI | ||
* contexts. | ||
*/ | ||
@ConfigItem(defaultValue = "true") | ||
public boolean enabled; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ions/arc/deployment/src/test/java/io/quarkus/arc/test/cp/ContextProviderDisabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.quarkus.arc.test.cp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ContextNotActiveException; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.context.ManagedExecutor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ManagedContext; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ContextProviderDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().overrideConfigKey("quarkus.arc.context-propagation.enabled", | ||
"false"); | ||
|
||
@Inject | ||
ManagedExecutor all; | ||
|
||
@Inject | ||
MyRequestBean bean; | ||
|
||
@Test | ||
public void testPropagationDisabled() throws InterruptedException, ExecutionException, TimeoutException { | ||
ManagedContext requestContext = Arc.container().requestContext(); | ||
|
||
requestContext.activate(); | ||
assertEquals("FOO", bean.getId()); | ||
try { | ||
assertEquals("OK", | ||
all.completedFuture("OK").thenApplyAsync(text -> { | ||
assertFalse(requestContext.isActive()); | ||
try { | ||
bean.getId(); | ||
fail(); | ||
} catch (ContextNotActiveException expected) { | ||
} | ||
return text; | ||
}).toCompletableFuture().get(5, TimeUnit.SECONDS)); | ||
} finally { | ||
requestContext.terminate(); | ||
} | ||
} | ||
|
||
@RequestScoped | ||
public static class MyRequestBean { | ||
|
||
String id; | ||
|
||
@PostConstruct | ||
void init() { | ||
id = "FOO"; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
...sions/arc/deployment/src/test/java/io/quarkus/arc/test/cp/ContextProviderEnabledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package io.quarkus.arc.test.cp; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.RequestScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.context.ManagedExecutor; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ManagedContext; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class ContextProviderEnabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().overrideConfigKey("quarkus.arc.context-propagation.enabled", | ||
"true"); | ||
|
||
@Inject | ||
ManagedExecutor all; | ||
|
||
@Inject | ||
MyRequestBean bean; | ||
|
||
@Test | ||
public void testPropagationDisabled() throws InterruptedException, ExecutionException, TimeoutException { | ||
ManagedContext requestContext = Arc.container().requestContext(); | ||
|
||
requestContext.activate(); | ||
assertEquals("FOO", bean.getId()); | ||
try { | ||
assertEquals("OK", | ||
all.completedFuture("OK").thenApplyAsync(text -> { | ||
assertTrue(requestContext.isActive()); | ||
assertEquals("FOO", bean.getId()); | ||
return text; | ||
}).toCompletableFuture().get(5, TimeUnit.SECONDS)); | ||
; | ||
} finally { | ||
requestContext.terminate(); | ||
} | ||
} | ||
|
||
@RequestScoped | ||
public static class MyRequestBean { | ||
|
||
String id; | ||
|
||
@PostConstruct | ||
void init() { | ||
id = "FOO"; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
} | ||
|
||
} |
1 change: 0 additions & 1 deletion
1
...in/resources/META-INF/services/org.eclipse.microprofile.context.spi.ThreadContextProvider
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters