From b66e50c815b2d6281d232e5dea1fe9c0a1388097 Mon Sep 17 00:00:00 2001 From: Ivo Studensky Date: Mon, 24 Apr 2023 12:22:08 +0200 Subject: [PATCH] [WFLY-17871] added test-case for managed executor service defined via annotation --- testsuite/integration/basic/pom.xml | 2 +- .../ManagedExecutorServiceAnnotationBean.java | 40 +++++++++++++++++ ...agedExecutorServiceAnnotationTestCase.java | 44 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationBean.java create mode 100644 testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationTestCase.java diff --git a/testsuite/integration/basic/pom.xml b/testsuite/integration/basic/pom.xml index ab11dc80af02..bbfae0389760 100644 --- a/testsuite/integration/basic/pom.xml +++ b/testsuite/integration/basic/pom.xml @@ -2798,7 +2798,7 @@ - + ee-concurrency-layers.surefire test diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationBean.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationBean.java new file mode 100644 index 000000000000..ea51ecc7996f --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationBean.java @@ -0,0 +1,40 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.as.test.integration.ee.concurrent; + +import static jakarta.enterprise.concurrent.ContextServiceDefinition.APPLICATION; +import static jakarta.enterprise.concurrent.ContextServiceDefinition.SECURITY; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import jakarta.annotation.Resource; +import jakarta.ejb.LocalBean; +import jakarta.ejb.Stateless; +import jakarta.enterprise.concurrent.ContextServiceDefinition; +import jakarta.enterprise.concurrent.ManagedExecutorDefinition; +import jakarta.enterprise.concurrent.ManagedExecutorService; + +@ManagedExecutorDefinition( + name = "java:module/concurrent/MyExecutor", + context = "java:module/concurrent/MyExecutorContext", + hungTaskThreshold = 120000, + maxAsync = 5) +@ContextServiceDefinition( + name = "java:module/concurrent/MyExecutorContext", + propagated = { SECURITY, APPLICATION }) +@Stateless +@LocalBean +public class ManagedExecutorServiceAnnotationBean { + + @Resource(lookup = "java:module/concurrent/MyExecutor") + ManagedExecutorService executorService; + + public Future testRunnable(Runnable runnable) throws ExecutionException, InterruptedException { + assert executorService != null; + return executorService.submit(runnable); + } +} diff --git a/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationTestCase.java b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationTestCase.java new file mode 100644 index 000000000000..f717f7afd046 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/jboss/as/test/integration/ee/concurrent/ManagedExecutorServiceAnnotationTestCase.java @@ -0,0 +1,44 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.jboss.as.test.integration.ee.concurrent; + +import jakarta.annotation.Resource; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test for ManagedExecutorService defined via @ManagedExecutorDefinition + * + * @author Ivo Studensky + */ +@RunWith(Arquillian.class) +public class ManagedExecutorServiceAnnotationTestCase { + + @Deployment + public static Archive getDeployment() { + return ShrinkWrap.create(JavaArchive.class, ManagedExecutorServiceAnnotationTestCase.class.getSimpleName() + ".jar") + .addClasses(ManagedExecutorServiceAnnotationTestCase.class, ManagedExecutorServiceAnnotationBean.class); + } + + @Resource(lookup = "java:module/ManagedExecutorServiceAnnotationBean") + ManagedExecutorServiceAnnotationBean service; + + private static void testMethod() { + // empty method + } + + @Test + public void testExecutorService() throws Exception { + Assert.assertNotNull(service); + service.testRunnable(ManagedExecutorServiceAnnotationTestCase::testMethod).get(); + } +}