Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2022 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.ContextService.contextPropagate;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import javax.naming.InitialContext;
import ee.jakarta.tck.concurrent.common.context.IntContext;
import ee.jakarta.tck.concurrent.common.context.StringContext;
import ee.jakarta.tck.concurrent.framework.TestServlet;
import jakarta.annotation.Resource;
import jakarta.ejb.EJB;
import jakarta.enterprise.concurrent.ContextService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.UserTransaction;
@WebServlet("/ContextServiceDefinitionFromEJBServlet")
public class ContextServiceDefinitionFromEJBServlet extends TestServlet {
private static final long serialVersionUID = 1L;
private static final long MAX_WAIT_SECONDS = TimeUnit.MINUTES.toSeconds(2);
/**
* Java SE thread pool with threads that lack context.
*/
private ExecutorService unmanagedThreads;
@Resource
UserTransaction tx;
@EJB
private ContextServiceDefinitionInterface contextServiceDefinitionBean;
@Override
public void destroy() {
unmanagedThreads.shutdownNow();
}
@Override
public void before() throws ServletException {
unmanagedThreads = Executors.newFixedThreadPool(10);
}
/**
* A ContextServiceDefinition defined in an EJB with all attributes configured
* propagates/clears/ignores context types as configured.
* ContextA, which is tested here, propagates Application context and IntContext,
* clears StringContext, and leaves Transaction context unchanged.
*/
public void testContextServiceDefinitionFromEJBAllAttributes() throws Throwable {
ContextService contextServiceA = InitialContext.doLookup("java:app/concurrent/EJBContextA");
BiFunction