Search in sources :

Example 1 with ManagedExecutor

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;
    });
}
Also used : ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 2 with ManagedExecutor

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);
}
Also used : RestClientBuilder(org.eclipse.microprofile.rest.client.RestClientBuilder) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor)

Example 3 with ManagedExecutor

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());
}
Also used : CounterfactualExplainer(org.kie.kogito.explainability.local.counterfactual.CounterfactualExplainer) SmallRyeManagedExecutor(io.smallrye.context.SmallRyeManagedExecutor) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) Test(org.junit.jupiter.api.Test)

Example 4 with ManagedExecutor

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();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CountDownLatch(java.util.concurrent.CountDownLatch) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 5 with ManagedExecutor

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());
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) BeforeEach(org.junit.jupiter.api.BeforeEach) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) CustomResourceList(io.fabric8.kubernetes.client.CustomResourceList) ClusterPodPersistentVolume(io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume) FullTextSearchQuery(io.stackgres.apiweb.distributedlogs.FullTextSearchQuery) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) Assertions.assertIterableEquals(org.junit.jupiter.api.Assertions.assertIterableEquals) ClusterPodScheduling(io.stackgres.apiweb.dto.cluster.ClusterPodScheduling) Mockito.doNothing(org.mockito.Mockito.doNothing) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterPodTransformer(io.stackgres.apiweb.transformer.ClusterPodTransformer) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) ClusterSpecMetadata(io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata) ManagedExecutor(org.eclipse.microprofile.context.ManagedExecutor) ClusterSpecLabels(io.stackgres.apiweb.dto.cluster.ClusterSpecLabels) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) ConfigMapKeySelector(io.stackgres.common.crd.ConfigMapKeySelector) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Mock(org.mockito.Mock) DistributedLogsFetcher(io.stackgres.apiweb.distributedlogs.DistributedLogsFetcher) ClusterDtoFinder(io.stackgres.apiweb.resource.ClusterDtoFinder) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Seq(org.jooq.lambda.Seq) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) ClusterTransformer(io.stackgres.apiweb.transformer.ClusterTransformer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ClusterLabelMapper(io.stackgres.common.ClusterLabelMapper) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterDto(io.stackgres.apiweb.dto.cluster.ClusterDto) JsonUtil(io.stackgres.testutil.JsonUtil) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) ClusterStatsDto(io.stackgres.apiweb.dto.cluster.ClusterStatsDto) AfterEach(org.junit.jupiter.api.AfterEach) PodList(io.fabric8.kubernetes.api.model.PodList) PersistentVolumeClaimFinder(io.stackgres.common.resource.PersistentVolumeClaimFinder) StackGresPodPersistentVolume(io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume) PatroniUtil(io.stackgres.common.PatroniUtil) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PodExecutor(io.stackgres.common.resource.PodExecutor) ClusterDtoScanner(io.stackgres.apiweb.resource.ClusterDtoScanner) StringUtil(io.stackgres.common.StringUtil) ClusterStatsDtoFinder(io.stackgres.apiweb.resource.ClusterStatsDtoFinder) ClusterLogEntryDto(io.stackgres.apiweb.dto.cluster.ClusterLogEntryDto) ClusterLabelFactory(io.stackgres.common.ClusterLabelFactory) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) BadRequestException(javax.ws.rs.BadRequestException) ClusterStatsTransformer(io.stackgres.apiweb.transformer.ClusterStatsTransformer) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ImmutableMap(com.google.common.collect.ImmutableMap) Instant(java.time.Instant) PodFinder(io.stackgres.common.resource.PodFinder) Test(org.junit.jupiter.api.Test) Base64(java.util.Base64) List(java.util.List) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) Tuple(org.jooq.lambda.tuple.Tuple) StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) Optional(java.util.Optional) Secret(io.fabric8.kubernetes.api.model.Secret) ResourceFinder(io.stackgres.common.resource.ResourceFinder) Metadata(io.stackgres.apiweb.dto.Metadata) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) ClusterPod(io.stackgres.apiweb.dto.cluster.ClusterPod) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ResourceTransactionHandler(io.stackgres.apiweb.resource.ResourceTransactionHandler) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) SecretKeySelector(io.stackgres.common.crd.SecretKeySelector) StackGresPropertyContext(io.stackgres.common.StackGresPropertyContext) WebApiProperty(io.stackgres.apiweb.config.WebApiProperty) Service(io.fabric8.kubernetes.api.model.Service) ExecutorService(java.util.concurrent.ExecutorService) ClusterSpec(io.stackgres.apiweb.dto.cluster.ClusterSpec) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) ClusterRestore(io.stackgres.apiweb.dto.cluster.ClusterRestore) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) DistributedLogsQueryParameters(io.stackgres.apiweb.distributedlogs.DistributedLogsQueryParameters) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) Collections(java.util.Collections) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) PodList(io.fabric8.kubernetes.api.model.PodList) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ManagedExecutor (org.eclipse.microprofile.context.ManagedExecutor)13 Path (javax.ws.rs.Path)4 SystemException (javax.transaction.SystemException)3 Transaction (javax.transaction.Transaction)3 Transactional (javax.transaction.Transactional)3 POST (javax.ws.rs.POST)3 Produces (javax.ws.rs.Produces)3 Test (org.junit.jupiter.api.Test)3 SmallRyeManagedExecutor (io.smallrye.context.SmallRyeManagedExecutor)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 ContextManagerProvider (org.eclipse.microprofile.context.spi.ContextManagerProvider)2 Employee (com.gepardec.mega.domain.model.Employee)1 EmployeeService (com.gepardec.mega.service.api.EmployeeService)1 ZepService (com.gepardec.mega.zep.ZepService)1 ZepServiceException (com.gepardec.mega.zep.ZepServiceException)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1