2012-09-29

Arquillian and @Asynchronous

I have just learnt that Arquillian does not support @Asynchronous calls. So if you have @Asynchronous EJBs, then they might run fine on JBoss 7 (provided it's full profile and not just web profile, as far as I know), but not when you deploy it via Arquillian. The problem is, the errors this will produce are as misleading as it gets. I got NoClassDefFoundError for example.

Original situation

The bean.
@Stateless
@Asynchronous
@Local(LibraryImporter.class)
public class CacheAwareLibraryImporter implements LibraryImporter {

// … omitted for brevity

   @Override
   @TransactionAttribute(TransactionAttributeType.REQUIRED)
   public Future importLibrary(File libraryFile) {
// code...
   }
}
The test.
@RunWith(Arquillian.class)
public class DefaultSongServiceMacOsIT {

   @EJB
   private LibraryService libraryService;

// … omitted for brevity
This doesn't work with Arquillian.

Workaround

Here's my workaround. You may want to look at the diff file instead. The new bean (in src/test/java).
@Stateless
@Local({ LibraryImporter.class, SynchronousLibraryImporter.class })
public class SynchronousCacheAwareLibraryImporter extends
       CacheAwareLibraryImporter implements SynchronousLibraryImporter {

   @Override
   @TransactionAttribute(TransactionAttributeType.REQUIRED)
   public Future importLibrary(File libraryFile) {
       return super.importLibrary(libraryFile);
   }

}
The new interface (in src/test/java).
public interface SynchronousLibraryImporter extends LibraryImporter {

}
The test.
@RunWith(Arquillian.class)
public class DefaultSongServiceMacOsIT {

   @EJB
   private SynchronousLibraryService libraryService;

// … omitted for brevity
Nice...-ty. This is a known issue and they haven't done much about it so far.

2 comments:

  1. 111Skin coupons give you access to luxurious skincare products made with advanced formulations and premium ingredients. 111Skin is known for its innovative approach to skincare, and it offers a variety of high-performance serums, masks, moisturizers, and treatments that target different skin problems.

    111skin coupon provide a chance for skincare lovers to enjoy high-end skincare essentials at reduced prices. 111Skin products are created using state-of-the-art technology and powerful ingredients that aim to refresh, moisturize, and renew the skin for a glowing look.

    ReplyDelete
  2. Visit your internet presence and explore the worlds of Arquillian and @Asynchronous. Examine their benefits and features to see how they can transform your programming experience. This is really vital and helpful information that I and other readers found to be extremely helpful. Thank you for consistently providing readers with insightful and helpful content; your blog is going great, congrats! In the meanwhile, you can check out this.
    fairfax dui lawyer

    ReplyDelete