3 Replies Latest reply on Dec 1, 2016 7:32 AM by g.hohl

    Accessing the test class if a, e.g., a BeforeSetup event is fired

    g.hohl

      Hello everyone,

       

      as I need to do some preparation before Arquillian starts the embedded WildFly instance I came across the Arquillian lifecycle extension tutorial:

      https://github.com/arquillian/arquillian-examples/tree/master/arquillian-lifecycle-extension-tutorial/

      That example works well, but offers only @BeforeDeploy, @AfterDeploy, @BeforeUnDeploy and @AfterUnDeploy (in addition to the @Deployment, @BeforeClass, @Before, @Test, @After and @AfterClass). But all of these phases are too late as the WildFly instance is already running.

       

      Based on that tutorial I discovered that there are more events like e.g. BeforeSetup. So I extended that tutorial by these events only to realize that the correspondingly annotated methods in my test suite are not invoked.

      After some research I found out that the problem is that the signature of the additional methods in my LifecycleExecutor are the same like the methods which already exist in the tutorial: First parameter is the event, the second parameter is the TestCase object. But the org.jboss.arquillian.core.impl.ObserverImpl can't invoke it because it doesn't have the TestCase object in that phase.

       

      Now my question is if I have some kind of mistake in my program and just have to rearrange the signature of my methods.

      Or is there no access on the TestCase possible at all in that phase? And if, why? At the moment that doesn't make much sense to me.

        • 1. Re: Accessing the test class if a, e.g., a BeforeSetup event is fired
          g.hohl

          Seems that I got one step further in my research. In meantime I arrived at the org.jboss.arquillian.junit.Arquillian class which is the JUnit runner of the Arquillian framework.

          I have to admit that I wasn't aware of the fact that for every test suite a JUnit runner is instantiated. The JUnit framework passes the test class to the constructor of the runner.

          But that means that it should be possible to have the test class the whole time which makes me wondering why I don't get it.

          Within the run(RunNotifier) method of the Arquillian runner I at least see why: They don't take it for the calls there which also includes the BeforeSetup event.

           

          At this point it looks like I have to overwrite the Arquillian runner somehow...

           

          If anyone has a better solution, please, comment.

          • 2. Re: Accessing the test class if a, e.g., a BeforeSetup event is fired
            g.hohl

            Seems I have to overwrite the following classes:

            - org.jboss.arquillian.junit.Arquillian

            - org.jboss.arquillian.test.spi.TestRunnerAdaptorBuilder

            - org.jboss.arquillian.test.impl.EventTestRunnerAdaptor

            - org.jboss.arquillian.test.impl.TestContextHandler

             

            The TestContextHandler is a little bit of a problem as it is loaded through an extension. And as far as I can see there is no way to disable / remove an extension, only to enable / add one.

            • 3. Re: Accessing the test class if a, e.g., a BeforeSetup event is fired
              g.hohl

              Okay, after writing 27 classes and interfaces I can now handle also the other life-cycle phases.

               

              Unfortunately that doesn't seem to solve my original problem. Currently I need to add extra VM arguments if I want to execute the JUnit tests in Eclipse:

              -Djboss.home=target/wildfly-10.1.0.Final -Djava.util.logging.manager=org.jboss.logmanager.LogManager -Dlogging.configuration=file:src/test/resources/logging.properties

              But it's not very handy if you have to copy that to every JUnit launch configuration. And if someone of your team-mates doesn't know it...

              Why it doesn't solve my problem: Also I set these properties using System.getProperties().setProperty(String, String) in the BeforeSetup event, it seems that some parts of WildFly have already been loaded.

              I get the following message after the BeforeSetup event:

              Cannot not load JBoss LogManager. The LogManager has likely been accessed prior to this initialization.

              And after the BeforeStart event WildFly exits with an exception completely:

              Dez 01, 2016 1:22:01 PM org.jboss.msc.service.ServiceContainerImpl <clinit>

              INFO: JBoss MSC version 1.2.6.Final

              Dez 01, 2016 1:22:01 PM org.jboss.as.server.ApplicationServerService start

              INFO: WFLYSRV0049: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) starting

              Dez 01, 2016 1:22:03 PM org.jboss.as.controller.AbstractOperationContext executeStep

              ERROR: WFLYCTL0013: Operation ("parallel-extension-add") failed - address: ([])

              java.lang.RuntimeException: WFLYCTL0079: Failed initializing module org.jboss.as.logging

                  at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:115)

                  at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:890)

                  at org.jboss.as.controller.AbstractOperationContext.processStages(AbstractOperationContext.java:659)

                  at org.jboss.as.controller.AbstractOperationContext.executeOperation(AbstractOperationContext.java:370)

                  at org.jboss.as.controller.OperationContextImpl.executeOperation(OperationContextImpl.java:1329)

                  at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:467)

                  at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:387)

                  at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:349)

                  at org.jboss.as.server.ServerService.boot(ServerService.java:397)

                  at org.jboss.as.server.ServerService.boot(ServerService.java:366)

                  at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:299)

                  at java.lang.Thread.run(Thread.java:745)

              Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"

                  at java.util.concurrent.FutureTask.report(FutureTask.java:122)

                  at java.util.concurrent.FutureTask.get(FutureTask.java:192)

                  at org.jboss.as.controller.extension.ParallelExtensionAddHandler$1.execute(ParallelExtensionAddHandler.java:107)

                  ... 11 more

              Caused by: java.lang.IllegalStateException: WFLYLOG0078: The logging subsystem requires the log manager to be org.jboss.logmanager.LogManager. The subsystem has not be initialized and cannot be used. To use JBoss Log Manager you must add the system property "java.util.logging.manager" and set it to "org.jboss.logmanager.LogManager"

                  at org.jboss.as.logging.LoggingExtension.initialize(LoggingExtension.java:147)

                  at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:131)

                  at org.jboss.as.controller.extension.ExtensionAddHandler.initializeExtension(ExtensionAddHandler.java:104)

                  at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:144)

                  at org.jboss.as.controller.extension.ParallelExtensionAddHandler$ExtensionInitializeTask.call(ParallelExtensionAddHandler.java:127)

                  at java.util.concurrent.FutureTask.run(FutureTask.java:266)

                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

                  at java.lang.Thread.run(Thread.java:745)

                  at org.jboss.threads.JBossThread.run(JBossThread.java:320)

               

              Dez 01, 2016 1:22:03 PM org.jboss.as.server.ServerService$4 logExit

              FATAL: WFLYSRV0056: Server boot has failed in an unrecoverable manner; exiting. See previous messages for details.

              Dez 01, 2016 1:22:03 PM org.jboss.as.server.ApplicationServerService stop

              INFO: WFLYSRV0050: WildFly Full 10.1.0.Final (WildFly Core 2.2.0.Final) stopped in 65ms

              Seems I have to go back again and look at which point that WildFly instance or logging instance is initialized.