Arquillian Event model
kpiwko Feb 28, 2012 9:44 AMHi 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:
Any feedback is highly appreciated.
Thanks,
Karel