Skip to content

Commit

Permalink
Upgrade to SmallRye-ContextPropagation 1.0.16
Browse files Browse the repository at this point in the history
Can now inject SmallRye variants which have more features
  • Loading branch information
FroMage authored and gsmet committed Aug 31, 2020
1 parent 614b91e commit bf963e3
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 13 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Expand Up @@ -41,7 +41,7 @@
<smallrye-opentracing.version>1.3.4</smallrye-opentracing.version>
<smallrye-fault-tolerance.version>4.3.0</smallrye-fault-tolerance.version>
<smallrye-jwt.version>2.3.0</smallrye-jwt.version>
<smallrye-context-propagation.version>1.0.13</smallrye-context-propagation.version>
<smallrye-context-propagation.version>1.0.16</smallrye-context-propagation.version>
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
<smallrye-converter-api.version>1.1.0</smallrye-converter-api.version>
<smallrye-reactive-messaging.version>2.3.0</smallrye-reactive-messaging.version>
Expand Down
Expand Up @@ -23,6 +23,7 @@
import io.quarkus.deployment.util.ServiceUtil;
import io.quarkus.smallrye.context.runtime.SmallRyeContextPropagationProvider;
import io.quarkus.smallrye.context.runtime.SmallRyeContextPropagationRecorder;
import io.smallrye.context.SmallRyeManagedExecutor;

/**
* The deployment processor for MP-CP applications
Expand Down Expand Up @@ -76,8 +77,9 @@ void build(SmallRyeContextPropagationRecorder recorder,

// Synthetic bean for ManagedExecutor
syntheticBeans.produce(
SyntheticBeanBuildItem.configure(ManagedExecutor.class)
SyntheticBeanBuildItem.configure(SmallRyeManagedExecutor.class)
.scope(ApplicationScoped.class)
.addType(ManagedExecutor.class)
.defaultBean()
.unremovable()
.supplier(recorder.initializeManagedExecutor(executorBuildItem.getExecutorProxy()))
Expand Down
Expand Up @@ -7,15 +7,17 @@
import org.eclipse.microprofile.context.ThreadContext;

import io.quarkus.arc.DefaultBean;
import io.smallrye.context.SmallRyeThreadContext;

@Dependent
public class SmallRyeContextPropagationProvider {

@Produces
@Singleton
@DefaultBean
public ThreadContext getAllThreadContext() {
return ThreadContext.builder().propagated(ThreadContext.ALL_REMAINING).cleared().unchanged().build();
public SmallRyeThreadContext getAllThreadContext() {
return (SmallRyeThreadContext) ThreadContext.builder().propagated(ThreadContext.ALL_REMAINING).cleared().unchanged()
.build();
}

}
Expand Up @@ -14,25 +14,54 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.context.ThreadContext;
import org.wildfly.common.Assert;

import io.quarkus.arc.Arc;
import io.smallrye.context.SmallRyeManagedExecutor;

@Path("context-propagation")
public class ContextPropagationResource {

@Inject
RequestBean doNotRemove;
@Inject
ManagedExecutor allExec;
SmallRyeManagedExecutor smallRyeAllExec;
@Inject
SmallRyeManagedExecutor allExec;
@Inject
ThreadContext context;
@Inject
ThreadContext smallRyeContext;
@Inject
TransactionManager transactionManager;

@Path("managed-executor/created")
@Transactional
@GET
public CompletionStage<String> testManagedExecutorCreated(@Context UriInfo uriInfo) throws SystemException {
return testCompletionStage(allExec.completedFuture("OK"), uriInfo);
}

@Path("managed-executor/obtained")
@Transactional
@GET
public CompletionStage<String> test(@Context UriInfo uriInfo) throws SystemException {
CompletableFuture<String> ret = allExec.completedFuture("OK");
public CompletionStage<String> testManagedExecutorObtained(@Context UriInfo uriInfo) throws SystemException {
// make sure we can also do that with CF we obtained from other sources, via ManagedExecutor
CompletableFuture<String> completedFuture = CompletableFuture.completedFuture("OK");
return testCompletionStage(allExec.copy(completedFuture), uriInfo);
}

@Path("thread-context")
@Transactional
@GET
public CompletionStage<String> testThreadContext(@Context UriInfo uriInfo) throws SystemException {
// make sure we can also do that with CF we obtained from other sources, via ThreadContext
CompletableFuture<String> completedFuture = CompletableFuture.completedFuture("OK");
return testCompletionStage(context.withContextCapture(completedFuture), uriInfo);
}

private CompletionStage<String> testCompletionStage(CompletionStage<String> stage, UriInfo uriInfo) throws SystemException {
// Transaction
Transaction t1 = transactionManager.getTransaction();
Assert.assertTrue(t1 != null);
Expand All @@ -43,7 +72,7 @@ public CompletionStage<String> test(@Context UriInfo uriInfo) throws SystemExcep
Assert.assertTrue(rb1 != null);
String rbValue = rb1.callMe();

return ret.thenApplyAsync(text -> {
return stage.thenApplyAsync(text -> {
// RESTEasy
uriInfo.getAbsolutePath();
// ArC
Expand Down
Expand Up @@ -11,7 +11,6 @@
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

import org.eclipse.microprofile.context.ManagedExecutor;
import org.wildfly.common.Assert;

import io.quarkus.arc.Arc;
Expand All @@ -24,8 +23,6 @@ public class MutinyContextPropagationResource {
@Inject
RequestBean doNotRemove;
@Inject
ManagedExecutor allExec;
@Inject
TransactionManager transactionManager;

@Transactional
Expand Down
Expand Up @@ -21,6 +21,9 @@ public void testContextPropagation(String endpoint) throws Exception {
}

private static List<String> endpoints() {
return Arrays.asList("/context-propagation", "/context-propagation-mutiny");
return Arrays.asList("/context-propagation/managed-executor/created",
"/context-propagation/managed-executor/obtained",
"/context-propagation/thread-context",
"/context-propagation-mutiny");
}
}
4 changes: 4 additions & 0 deletions tcks/microprofile-context-propagation/pom.xml
Expand Up @@ -29,6 +29,10 @@
<dependenciesToScan>
<dependency>org.eclipse.microprofile.context-propagation:microprofile-context-propagation-tck</dependency>
</dependenciesToScan>
<!-- We need this file to be able to skip two tests that will be fixed in the next MP-CP release -->
<suiteXmlFiles>
<suiteXmlFile>tck-tests.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
Expand Down
29 changes: 29 additions & 0 deletions tcks/microprofile-context-propagation/tck-tests.xml
@@ -0,0 +1,29 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="MP-CP TCK" verbose="0" configfailurepolicy="continue">

<test name="MP-CP TCK">
<classes>
<!--
If I use packages to scan for classes, they run in parallel which our arquillian integration
does not support so I end up with NPEs in MPConfigTest in our arquillian integration.
The only alternative is to list them all just to be able to exclude two methods.
-->
<class name="org.eclipse.microprofile.context.tck.cdi.BasicCDITest"/>
<class name="org.eclipse.microprofile.context.tck.cdi.CDIContextTest"/>
<class name="org.eclipse.microprofile.context.tck.cdi.JTACDITest"/>
<class name="org.eclipse.microprofile.context.tck.ContextManagerTest"/>
<class name="org.eclipse.microprofile.context.tck.ManagedExecutorTest"/>
<class name="org.eclipse.microprofile.context.tck.MPConfigTest"/>
<class name="org.eclipse.microprofile.context.tck.TckTest"/>
<class name="org.eclipse.microprofile.context.tck.ThreadContextTest">
<methods>
<exclude name="withContextCaptureDependentCompletableFuturesRunWithContext"/>
<exclude name="withContextCaptureDependentCompletionStagesRunWithContext"/>
</methods>
</class>

</classes>

</test>

</suite>

0 comments on commit bf963e3

Please sign in to comment.