users@glassfish.java.net

Unit test EJB timers

From: <glassfish_at_javadesktop.org>
Date: Wed, 05 May 2010 05:09:58 PDT

I'm trying to unit test EJB's relying on timers using the embedded EJB container. The timeouts don't seem to be dispatched. Everything works fine using the regular GlassFish though.

Anybody has an idea how to enable the timer service ?

The nudge() method is not called in the embedded EJB container. Trying to inject the TimerService throws a colorful stacktrace which ends with:

Caused by: java.lang.IllegalStateException: EJB Timer Service not available
        at com.sun.ejb.EjbNamingReferenceManagerImpl.getEJBContextObject(EjbNamingReferenceManagerImpl.java:227)
        at com.sun.enterprise.container.common.impl.ComponentEnvManagerImpl$EjbContextProxy.create(ComponentEnvManagerImpl.java:854)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:688)
        at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:657)
        at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:148)
        ... 43 more

=============
Creating the container
=============
...
EJBContainer ejbContainer = EJBContainer.createEJBContainer();
...

=====
The EJB
=====

@Singleton
@Startup
public class HelloBean implements Hello {
    @Resource
    private TimerService timerService;

    @Schedule(second = "*/5", minute = "*", hour = "*",persistent=false)
    private void nudge() {
        System.out.println( "Wakig up ... " );
    }
}
[Message sent by forum member 'jan_goyvaerts']

http://forums.java.net/jive/thread.jspa?messageID=406800