2 Replies Latest reply on Feb 29, 2012 1:35 AM by kpiwko

    Arquillian Event model

    kpiwko

      Hi Arquillians,

       

      I'm a bit struggled by trying to verify that interaction between multiple extensions is going as expected. I have an Android Extension which basically allows to enrich Arquillian Drone extension by providing an Android Emulator for Drone.

       

      The code is located here:

       

      https://github.com/kpiwko/arquillian-extension-android/tree/android-extension

       

      The problem here is the event hierarchy. There are 3 entry points which observe BeforeSuite event:

      • ArquillianDroneConfigurator
      • AndroidExtensionConfigurator
      • AndroidDroneConfigurator

       

      These three basically load configuration from arquilian.xml. Some events are fired to ensure the rest of the work is propagated.

       

      ArquillianDrone extension then user a second entry point, BeforeClass. I had problem that this event was fired before processing of BeforeSuite was done for other two extensions, so it failed because AndroidEmulator WebDriver Hub was not ready yet and thus WebDriver wasn't able to connect to a specific URL.

       

      I solved this problem via a lock object with is unlocked after Hub is ready and active polling for the event which precedes the Drone creation (@Observes EventContent<EventName>). Not really happy with this, but it works.

       

      I've created a generic extension which logs all the events fired and made it a part of android-tests. However, the order is not actually what I'd expect and some of the events are not logged at all.

       

       

      public class GenericObserver { 
      
          private static ListLog log = new ListLog();
         
          public void observes(@Observes(precedence = -10000) Object object) throws Exception {
              File output = new File("target/event-order");
              output.createNewFile();
        
              log.write(object.getClass() + "\n");
              log.outputToFile(output);
          } 
      
      }
      

       

      The output is like:

       

      class org.jboss.arquillian.config.descriptor.impl.ArquillianDescriptorImpl

      class org.jboss.arquillian.core.api.event.ManagerStarted

      class org.jboss.arquillian.drone.impl.DroneRegistryImpl

      class org.jboss.arquillian.android.drone.impl.WebDriverHubSynchronizationLock

      class org.jboss.arquillian.android.drone.configuration.AndroidDroneConfiguration

      class org.jboss.arquillian.android.drone.event.AndroidDroneConfigured

      class org.jboss.arquillian.android.configuration.AndroidExtensionConfiguration

      class org.jboss.arquillian.android.configuration.AndroidSdk

      class org.jboss.arquillian.android.impl.ProcessExecutor

      class org.jboss.arquillian.android.impl.AndroidBridgeImpl

      class org.jboss.arquillian.android.impl.AndroidEmulator

      class org.jboss.arquillian.android.spi.event.AndroidDeviceReady

      class org.jboss.arquillian.android.spi.event.AndroidVirtualDeviceAvailable

      class org.jboss.arquillian.android.spi.event.AndroidBridgeInitialized

      class org.jboss.arquillian.android.spi.event.AndroidExtensionConfigured

      class org.jboss.arquillian.test.spi.event.suite.BeforeSuite

      class org.jboss.arquillian.test.spi.TestClass

      class org.jboss.arquillian.test.spi.event.suite.BeforeClass

      class org.jboss.arquillian.test.spi.TestClass

      class org.jboss.arquillian.drone.impl.MethodContext

      class org.jboss.arquillian.drone.event.MethodDroneConfigured

      class org.jboss.arquillian.test.spi.event.enrichment.BeforeEnrichment

      class org.jboss.arquillian.test.spi.event.enrichment.AfterEnrichment

      class org.jboss.arquillian.test.spi.event.suite.Before

      class org.jboss.arquillian.test.spi.TestClass

      class org.jboss.arquillian.test.spi.TestResult

      class org.jboss.arquillian.test.spi.event.suite.Test

      class org.jboss.arquillian.test.spi.TestClass

      class org.jboss.arquillian.test.spi.event.suite.After

      class org.jboss.arquillian.test.spi.TestClass

      class org.jboss.arquillian.test.spi.event.suite.AfterClass

      class java.lang.Object

      class org.jboss.arquillian.test.spi.event.suite.AfterSuite

      class org.jboss.arquillian.core.api.event.ManagerStopping

       

      Note that for instance AndroidBridgeInitialized is fired in an observer which @Observes AndroidExtensionConfigured, so the order is wrong. Also my method (@Observers AfterSuite xyz), which fires a dispose-event for AndroidEmulator from an observer method defined in EmulatorShutdown is not fired at all.

       

      What am I doing wrong?

       

      Following observers are registered in the tests:

       

      https://github.com/kpiwko/arquillian-extension-android/blob/android-extension/android-impl/src/main/java/org/jboss/arquillian/android/ArquillianAndroidExtension.java

      https://github.com/kpiwko/arquillian-extension-android/blob/android-extension/android-drone/src/main/java/org/jboss/arquillian/android/drone/AndroidDroneExtension.java

      https://github.com/arquillian/arquillian-extension-drone/blob/master/drone-impl/src/main/java/org/jboss/arquillian/drone/DroneExtension.java

       

      Any feedback is highly appreciated.

       

      Thanks,

       

      Karel

        • 1. Re: Arquillian Event model
          aslak

          for a full debug of the internals, change org.jboss.arquillian.core.impl.ManagerImpl.DEBUG to true in the source. (doing it in the test is to late to get the BeforeSuite parts)

           

          (note to self, expose that as a sys property

          • 2. Re: Arquillian Event model
            kpiwko

            Thanks a million, Aslak. That was it.

             

            Using debug information I figured out that some of the Observers are fired, but their arguments contain nulls. This was caused by ordering of Observers on BeforeSuite event, which is JVM/classpath order related.

             

            I did some changes which allowed me to remove SynchronizationLock. Also, https://issues.jboss.org/browse/ARQ-792 might make this much easier in future.