0 Replies Latest reply on Feb 14, 2012 6:14 AM by Juergen Zimmermann

    Troubles with concurrency testing

    Juergen Zimmermann Master

      I want to test whether concurrent updates on the same persistent object are correctly detected. The JPA entity class has an attribute annotated with @Version.

       

      In the Arquillian / JUnit test class I'm starting a 2nd thread to do an update, so that in the main/original thread an error should occur when there is also an update. However, the 2nd thread fails due to an exception (see below). The 2nd thread is executed using:

      // Helper object for the 2nd thread

      KundenverwaltungConcurrencyHelper concurrentUpdate = new KundenverwaltungConcurrencyHelper(...);

      ExecutorService executorService = Executors.newSingleThreadExecutor();

      Future<Void> future = executorService.submit(concurrentUpdate);

       

      IMHO, the stacktrace below indicates that WELD needs some activation/initialization in the 2nd thread. The EntityManager is @Inject-ed into session beans via Seam Persistence which is initialized:

      public class SeamConfig {

          @Produces

          @PersistenceUnit

          @ConversationScoped

          @ExtensionManaged

          @SuppressWarnings("unused")

          private EntityManagerFactory emf;

      }

       

      How can I provide an active context for WELD in the 2nd thread? Is there a problem with @ConversationScoped which I need for the web interface? Any hint is appreciated.

       

      The stacktrace:

      11:47:18,914 ERROR [org.jboss.ejb3.invocation] (pool-5-thread-1) JBAS014134: EJB Invocation failed on component Kundenverwaltung for method public de.shop.kundenverwaltung.domain.AbstractKunde de.shop.kundenverwaltung.service.Kundenverwaltung.findKundeById(java.lang.Long,de.shop.kundenverwaltung.service.KundenverwaltungDao$Fetch): javax.ejb.EJBTransactionRolledbackException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:139) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:204) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.mandatory(CMTTxInterceptor.java:257) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:184) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:76) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:57) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:173) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at de.shop.kundenverwaltung.service.Kundenverwaltung$$$view5.findKundeById(Unknown Source) [classes:]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_02]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.7.0_02]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_02]

          at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_02]

          at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:264) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:52) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:137) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:260) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:111) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at de.shop.kundenverwaltung.service.Kundenverwaltung$Proxy$_$$_Weld$Proxy$.findKundeById(Kundenverwaltung$Proxy$_$$_Weld$Proxy$.java) [classes:]

          at de.shop.test.service.KundenverwaltungConcurrencyTest$KundenverwaltungConcurrencyHelper.update(KundenverwaltungConcurrencyTest.java:243) [classes:]

          at de.shop.test.util.AbstractConcurrencyHelper.call(AbstractConcurrencyHelper.java:59) [classes:]

          at de.shop.test.util.AbstractConcurrencyHelper.call(AbstractConcurrencyHelper.java:20) [classes:]

          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [:1.7.0_02]

          at java.util.concurrent.FutureTask.run(FutureTask.java:166) [:1.7.0_02]

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [:1.7.0_02]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [:1.7.0_02]

          at java.lang.Thread.run(Thread.java:722) [:1.7.0_02]

      Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped

          at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:598) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:104) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at org.jboss.weld.proxies.EntityManager$ManagedPersistenceContext$912270063$Proxy$_$$_WeldClientProxy.find(EntityManager$ManagedPersistenceContext$912270063$Proxy$_$$_WeldClientProxy.java) [weld-core-1.1.4.Final.jar:]

          at de.shop.util.Dao.find(Dao.java:35) [classes:]

          at de.shop.kundenverwaltung.service.224799517$Proxy$_$$_WeldSubclass.find(224799517$Proxy$_$$_WeldSubclass.java) [classes:]

          at de.shop.kundenverwaltung.service.KundenverwaltungDao.findKunde(KundenverwaltungDao.java:66) [classes:]

          at de.shop.kundenverwaltung.service.224799517$Proxy$_$$_WeldSubclass.findKunde(224799517$Proxy$_$$_WeldSubclass.java) [classes:]

          at de.shop.kundenverwaltung.service.KundenverwaltungDao.findKunde(KundenverwaltungDao.java:55) [classes:]

          at de.shop.kundenverwaltung.service.224799517$Proxy$_$$_WeldSubclass.findKunde(224799517$Proxy$_$$_WeldSubclass.java) [classes:]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_02]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.7.0_02]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_02]

          at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_02]

          at org.jboss.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:112) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]

          at org.jboss.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:133) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]

          at org.jboss.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:112) [jboss-interceptor-core-2.0.0.Alpha3.jar:2.0.0.Alpha3]

          at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:53) [weld-core-1.1.4.Final.jar:2011-11-22 20:01]

          at de.shop.kundenverwaltung.service.224799517$Proxy$_$$_WeldSubclass.findKunde(224799517$Proxy$_$$_WeldSubclass.java) [classes:]

          at de.shop.kundenverwaltung.service.Kundenverwaltung.findKundeById(Kundenverwaltung.java:102) [classes:]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_02]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.7.0_02]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_02]

          at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_02]

          at org.jboss.as.ee.component.ManagedReferenceMethodInterceptorFactory$ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptorFactory.java:72) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:122) [jboss-as-weld-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:130) [jboss-as-weld-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:37) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:374) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at de.shop.util.LogInterceptor.log(LogInterceptor.java:77) [classes:]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.7.0_02]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [:1.7.0_02]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [:1.7.0_02]

          at java.lang.reflect.Method.invoke(Method.java:601) [:1.7.0_02]

          at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:123) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:37) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.jpa.interceptor.SBInvocationInterceptor.processInvocation(SBInvocationInterceptor.java:45) [jboss-as-jpa-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53) [jboss-as-ee-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:51) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:202) [jboss-as-ejb3-7.1.0.CR1b.jar:7.1.0.CR1b]

          ... 40 more