use of org.eclipse.microprofile.context.ManagedExecutor in project quarkus by quarkusio.
the class ContextEndpoint method noarcTest.
@GET
@Path("/noarc")
public CompletionStage<String> noarcTest() {
ManagedExecutor me = ManagedExecutor.builder().cleared(ThreadContext.CDI).build();
Assert.assertTrue(Arc.container().instance(RequestBean.class).isAvailable());
RequestBean instance = Arc.container().instance(RequestBean.class).get();
String previousValue = instance.callMe();
CompletableFuture<String> ret = me.completedFuture("OK");
return ret.thenApplyAsync(text -> {
RequestBean instance2 = Arc.container().instance(RequestBean.class).get();
Assertions.assertNotEquals(previousValue, instance2.callMe());
return text;
});
}
use of org.eclipse.microprofile.context.ManagedExecutor in project quarkus by quarkusio.
the class RestClientBase method create.
public Object create() {
RestClientBuilder builder = RestClientBuilder.newBuilder();
configureBaseUrl(builder);
configureTimeouts(builder);
configureProviders(builder);
configureSsl(builder);
configureProxy(builder);
configureRedirects(builder);
configureQueryParamStyle(builder);
configureCustomProperties(builder);
// If we have context propagation, then propagate context to the async client threads
InstanceHandle<ManagedExecutor> managedExecutor = Arc.container().instance(ManagedExecutor.class);
if (managedExecutor.isAvailable()) {
builder.executorService(managedExecutor.get());
}
return builder.build(proxyType);
}
use of org.eclipse.microprofile.context.ManagedExecutor in project kogito-apps by kiegroup.
the class CounterfactualExplainerProducerTest method produce.
@Test
void produce() {
final ManagedExecutor executor = SmallRyeManagedExecutor.builder().build();
CounterfactualExplainerProducer producer = new CounterfactualExplainerProducer(0.01, executor);
CounterfactualExplainer counterfactualExplainer = producer.produce();
assertNotNull(counterfactualExplainer);
assertEquals(0.01, counterfactualExplainer.getCounterfactualConfig().getGoalThreshold());
assertEquals(executor, counterfactualExplainer.getCounterfactualConfig().getExecutor());
}
use of org.eclipse.microprofile.context.ManagedExecutor in project kogito-apps by kiegroup.
the class UserServiceAdapterTest method scheduleExecution.
@Test
@Timeout(2)
void scheduleExecution() throws Exception {
final CountDownLatch countDownLatch = new CountDownLatch(1);
final AtomicBoolean wasExecuted = new AtomicBoolean();
ManagedExecutor realManagedExecutor = ManagedExecutor.builder().maxAsync(1).maxQueued(1).build();
UserServiceAdapter realAdapter = new UserServiceAdapter(config, taskAssigningServiceEventConsumer, realManagedExecutor, userServiceConnector, startExecutionEvent, failFastRequestEvent);
realAdapter.scheduleExecution(Duration.parse("PT1S"), () -> {
wasExecuted.set(true);
countDownLatch.countDown();
});
countDownLatch.await();
assertThat(wasExecuted).isTrue();
realManagedExecutor.shutdown();
}
use of org.eclipse.microprofile.context.ManagedExecutor in project stackgres by ongres.
the class ClusterResourceMockedTest method setUp.
@Override
@BeforeEach
void setUp() {
super.setUp();
servicePrimary = new ServiceBuilder().withNewMetadata().withNamespace(getResourceNamespace()).withName(PatroniUtil.readWriteName(getResourceName())).endMetadata().withNewSpec().withType("ClusterIP").endSpec().build();
serviceReplicas = new ServiceBuilder(servicePrimary).editMetadata().withName(PatroniUtil.readOnlyName(getResourceName())).endMetadata().withNewSpec().withType("LoadBalancer").endSpec().withNewStatus().withNewLoadBalancer().addNewIngress().withHostname("f4611c56942064ed5a468d8ce0a894ec.us-east-1.elb.amazonaws.com").endIngress().endLoadBalancer().endStatus().build();
configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(getResourceNamespace()).withName("script").endMetadata().withData(ImmutableMap.of("script", "CREATE DATABASE test WITH OWNER test")).build();
podList = JsonUtil.readFromJson("stackgres_cluster/pods.json", PodList.class);
logList = new ArrayList<>();
clusterWithoutDistributedLogs = JsonUtil.readFromJson("stackgres_cluster/without_distributed_logs.json", StackGresCluster.class);
executorService = Executors.newWorkStealingPool();
doAnswer((Answer<Void>) invocation -> {
executorService.execute(Runnable.class.cast(invocation.getArgument(0)));
return null;
}).when(managedExecutor).execute(any());
}
Aggregations