Skip to content

Commit

Permalink
[WFLY-17871] added test-case for managed executor service defined via…
Browse files Browse the repository at this point in the history
… annotation
  • Loading branch information
istudens committed Apr 25, 2023
1 parent 7f59c71 commit 8cb9de9
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testsuite/integration/basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@
</configuration>
</execution>

<!-- Tests against the install with ejb-lite -->
<!-- Tests against the install with ee-concurrency -->
<execution>
<id>ee-concurrency-layers.surefire</id>
<phase>test</phase>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.test.integration.ee.concurrent;

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;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static jakarta.enterprise.concurrent.ContextServiceDefinition.APPLICATION;
import static jakarta.enterprise.concurrent.ContextServiceDefinition.SECURITY;

@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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2023, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

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();
}
}

0 comments on commit 8cb9de9

Please sign in to comment.