Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for ManagedThreadFactory Injected to Servlet #423

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -13,7 +13,6 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package ee.jakarta.tck.concurrent.spec.ManagedExecutorService.tx;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -38,7 +37,7 @@
import ee.jakarta.tck.concurrent.framework.junit.extensions.Wait;
import jakarta.annotation.Resource;
import jakarta.annotation.sql.DataSourceDefinition;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import jakarta.enterprise.concurrent.ManagedExecutorService;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
Expand All @@ -59,8 +58,8 @@ public class TransactionServlet extends TestServlet {
@Resource(lookup = "java:comp/env/jdbc/ManagedExecutorServiceDB")
private DataSource ds;

@Resource(lookup = TestConstants.defaultManagedScheduledExecutorService)
private ManagedScheduledExecutorService scheduledExecutor;
@Resource(lookup = TestConstants.defaultManagedExecutorService)
private ManagedExecutorService executor;

@Override
protected void beforeClass() throws RemoteException {
Expand All @@ -84,7 +83,7 @@ protected void beforeClass() throws RemoteException {
public void transactionTest(final HttpServletRequest req, final HttpServletResponse res) throws Exception {
boolean isCommit = Boolean.parseBoolean(req.getParameter(Constants.PARAM_COMMIT));

Future<?> taskResult = scheduledExecutor.submit(new TransactedTask(isCommit, Constants.SQL_TEMPLATE_INSERT));
Future<?> taskResult = executor.submit(new TransactedTask(isCommit, Constants.SQL_TEMPLATE_INSERT));

Wait.waitForTaskComplete(taskResult);
}
Expand All @@ -93,7 +92,7 @@ public void cancelTest() {
int originTableCount = Counter.getCount();

CancelledTransactedTask cancelledTask = new CancelledTransactedTask(Constants.SQL_TEMPLATE_INSERT);
Future<?> future = scheduledExecutor.submit(cancelledTask);
Future<?> future = executor.submit(cancelledTask);

// wait for transaction to begin
Wait.waitForTransactionBegan(cancelledTask);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2023 Contributors to the Eclipse Foundation
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.concurrent.spec.ManagedThreadFactory.injected;

import ee.jakarta.tck.concurrent.spec.ContextService.contextPropagate.ContextServiceDefinitionServlet;
import jakarta.ejb.Stateless;
import jakarta.enterprise.concurrent.ManagedThreadFactoryDefinition;

/**
* @ContextServiceDefinitions are defined under
* {@link ContextServiceDefinitionServlet}
*/
@ManagedThreadFactoryDefinition(name = "java:app/concurrent/EJBThreadFactoryInjA", context = "java:app/concurrent/EJBContextA", priority = 4)
@ManagedThreadFactoryDefinition(name = "java:comp/concurrent/EJBThreadFactoryInjB")
@Stateless
public class ManagedThreadFactoryDefinitionInjectedBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package ee.jakarta.tck.concurrent.spec.ManagedThreadFactory.injected;

import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import ee.jakarta.tck.concurrent.common.context.providers.IntContextProvider;
import ee.jakarta.tck.concurrent.common.context.providers.StringContextProvider;
import ee.jakarta.tck.concurrent.framework.TestClient;
import ee.jakarta.tck.concurrent.framework.URLBuilder;
import ee.jakarta.tck.concurrent.framework.junit.anno.Assertion;
import ee.jakarta.tck.concurrent.framework.junit.anno.Challenge;
import ee.jakarta.tck.concurrent.framework.junit.anno.Common.PACKAGE;
import ee.jakarta.tck.concurrent.framework.junit.anno.Full;
import ee.jakarta.tck.concurrent.framework.junit.anno.TestName;
import ee.jakarta.tck.concurrent.spec.ContextService.contextPropagate.ContextServiceDefinitionBean;
import ee.jakarta.tck.concurrent.spec.ContextService.contextPropagate.ContextServiceDefinitionInterface;
import ee.jakarta.tck.concurrent.spec.ContextService.contextPropagate.ContextServiceDefinitionServlet;
import ee.jakarta.tck.concurrent.spec.ManagedThreadFactory.resourcedef.ManagedThreadFactoryDefinitionFullTests;
import jakarta.enterprise.concurrent.spi.ThreadContextProvider;

@Full
@RunAsClient // Requires client testing due to multiple servlets and annotation configuration
public class ManagedThreadFactoryDefinitionInjectedFullTests extends TestClient {

@ArquillianResource(ManagedThreadFactoryDefinitionInjectedServlet.class)
private URL baseURL;

@ArquillianResource(ManagedThreadFactoryDefinitionOnEJBInjectedServlet.class)
private URL ejbContextURL;

@Deployment(name = "ManagedThreadFactoryDefinitionTests")
public static EnterpriseArchive createDeployment() {

WebArchive war = ShrinkWrap.create(WebArchive.class, "ManagedThreadFactoryDefinitionTests_web.war")
.addPackages(false, PACKAGE.CONTEXT.getPackageName(), PACKAGE.CONTEXT_PROVIDERS.getPackageName())
.addClasses(ManagedThreadFactoryDefinitionOnEJBInjectedServlet.class,
ManagedThreadFactoryDefinitionInjectedServlet.class, ContextServiceDefinitionServlet.class)
.addAsWebInfResource(ManagedThreadFactoryDefinitionFullTests.class.getPackage(), "web.xml", "web.xml")
.addAsServiceProvider(ThreadContextProvider.class.getName(), IntContextProvider.class.getName(),
StringContextProvider.class.getName());

JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ManagedThreadFactoryDefinitionInjectedTests_ejb.jar")
.addPackages(false, ManagedThreadFactoryDefinitionInjectedFullTests.class.getPackage())
.deleteClasses(ManagedThreadFactoryDefinitionOnEJBInjectedServlet.class,
ManagedThreadFactoryDefinitionInjectedServlet.class)
.addClasses(ContextServiceDefinitionInterface.class, ContextServiceDefinitionBean.class)
.addAsManifestResource(ManagedThreadFactoryDefinitionFullTests.class.getPackage(), "ejb-jar.xml",
"ejb-jar.xml");

EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "ManagedThreadFactoryDefinitionInjectedTests.ear")
.addAsModules(war, jar);

return ear;
}

@TestName
private String testname;

@Override
protected String getServletPath() {
return "ManagedThreadFactoryDefinitionInjectedServlet";
}

@Challenge(link = "https://github.com/jakartaee/concurrency/issues/226", version = "3.0.0")
@Assertion(id = "GIT:156", strategy = "ManagedThreadFactoryDefinition with all attributes configured")
public void testManagedThreadFactoryDefinitionAllAttributes() throws Throwable {
runTest(baseURL, testname);
}

@Challenge(link = "https://github.com/jakartaee/concurrency/issues/226", version = "3.0.0")
@Assertion(id = "GIT:156",
strategy = "A ManagedThreadFactoryDefinition defined on an EJB with all attributes configured enforces priority and propagates context.")
public void testManagedThreadFactoryDefinitionAllAttributesEJB() throws Throwable {
URLBuilder requestURL = URLBuilder.get().withBaseURL(ejbContextURL)
.withPaths("ManagedThreadFactoryDefinitionOnEJBInjectedServlet").withTestName(testname);
runTest(requestURL);
}

@Assertion(id = "GIT:156", strategy = "ManagedThreadFactoryDefinition with minimal attributes configured")
public void testManagedThreadFactoryDefinitionDefaults() throws Throwable {
runTest(baseURL, testname);
}

@Assertion(id = "GIT:156",
strategy = "ManagedThreadFactoryDefinition defined on an EJB with minimal attributes creates threads with normal priority"
+ " and uses java:comp/DefaultContextService to determine context propagation and clearing")
public void testManagedThreadFactoryDefinitionDefaultsEJB() throws Throwable {
URLBuilder requestURL = URLBuilder.get().withBaseURL(ejbContextURL)
.withPaths("ManagedThreadFactoryDefinitionOnEJBInjectedServlet").withTestName(testname);
runTest(requestURL);
}

//@Challenge(link = "https://github.com/jakartaee/concurrency/issues/226", version = "3.0.0")
@Assertion(id = "GIT:156",
strategy = "ManagedThreadFactory can be supplied to a ForkJoinPool, which manages thread context and priority as configured")
public void testParallelStreamBackedByManagedThreadFactory() throws Throwable {
runTest(baseURL, testname);
}

//@Challenge(link = "https://github.com/jakartaee/concurrency/issues/226", version = "3.0.0")
@Assertion(id = "GIT:156",
strategy = "ManagedThreadFactoryDefinition defined on an EJB is supplied to a ForkJoinPool"
+ " and uses java:comp/DefaultContextService to determine context propagation and priority.")
public void testParallelStreamBackedByManagedThreadFactoryEJB() throws Throwable {
URLBuilder requestURL = URLBuilder.get().withBaseURL(ejbContextURL)
.withPaths("ManagedThreadFactoryDefinitionOnEJBInjectedServlet").withTestName(testname);
runTest(requestURL);
}
}
Loading