6 Replies Latest reply on Mar 16, 2018 12:16 PM by Ondra Chaloupka

    Using BYTEMAN in JUnit test with Arquillian

    tommaso borgato Newbie

      Hi All,

      I am trying to use BYTEMAN on the client side in a test run with Arquillian:

       

      @RunWith(Arquillian.class)

       

      So I cannot add:

       

      @RunWith(BMUnitRunner.class)

       

      What I am trying to do is to mimic what happens inside class BMUnitRunner.

       

      BMUnitConfigState.pushConfigurationState(
                        MyTestCase.class.getAnnotation(BMUnitConfig.class)
                      , MyTestCase.class);
      BMUnit.loadScriptFile(
                        MyTestCase.class
                      , BMRunnerUtil.computeBMScriptName(MyTestCase.class.getAnnotation(BMScript.class).value())
                      , BMRunnerUtil.normaliseLoadDirectory(MyTestCase.class.getAnnotation(BMScript.class)));

       

      My test class is annotated:

       

      @RunWith(Arquillian.class)
      @BMUnitConfig(loadDirectory="target/test-classes")
      @BMScript(value="bytemarules.btm")
      public class CMyTestCase 

       

      and the script file is loaded but the rules are not executed!

        • 1. Re: Using BYTEMAN in JUnit test with Arquillian
          Andrew Dinn Master

          Hi Tommaso,

           

          I think it is only possible to do what you want by linking into hooks provided by the Arquilian test runner (Arquilian.class). I don't know enough about how Arquilian works to explain how you would do that (well, actually, I know nothing about how Arquilian works). However, the good news is: I do know that someone else has already done this step for you.

           

          The Arquilian project  integrated Byteman into its test model with a byteman extension quite a few years ago. You probably ought to ask about this on the Arquilian forum where there are lots of people who have used it. You might also find the info you need in the Arquilian docs or by googling Arquilian Byteman extension.

           

          regards,

           

           

          Andrew Dinn

          • 2. Re: Using BYTEMAN in JUnit test with Arquillian
            tommaso borgato Newbie

            Thank you Andrew!

             

            In the meantime I found that manually replicating the Byteman call performed in class BMUnitRunner inside my JUnit Test class, does work:

             

                @BeforeClass
                public static void beforeClass() throws Exception {
                    BMUnitConfigState.pushConfigurationState(
                            MyTestCase.class.getAnnotation(BMUnitConfig.class)
                            , MyTestCase.class);
                    BMUnit.loadScriptFile(
                              MyTestCase.class
                            , BMRunnerUtil.computeBMScriptName(MyTestCase.class.getAnnotation(BMScript.class).value())
                            , BMRunnerUtil.normaliseLoadDirectory(MyTestCase.class.getAnnotation(BMScript.class)));
                }
            
            
                @AfterClass
                public static void afterClass() throws Exception {
                    BMUnit.unloadScriptFile(
                            MyTestCase.class
                            , BMRunnerUtil.computeBMScriptName(MyTestCase.class.getAnnotation(BMScript.class).value()));
                    BMUnitConfigState.popConfigurationState(MyTestCase.class);
                }

             

            Basically those calls just do the annotation parsing on the JUnit Test class....

            • 3. Re: Using BYTEMAN in JUnit test with Arquillian
              Andrew Dinn Master

              tommaso-borgato  wrote:

               

              Thank you Andrew!

               

              In the meantime I found that manually replicating the Byteman call performed in class BMUnitRunner inside my JUnit Test class, does work:

              . . .

              Basically those calls just do the annotation parsing on the JUnit Test class....

              Well, that's good to know. Do make sure that the unload happens inside a finally block so you guarantee to remove the loaded rules!

               

              regards,

               

               

              Andrew Dinn

              • 5. Re: Using BYTEMAN in JUnit test with Arquillian
                tommaso borgato Newbie

                Thank you Ondra, I tried following the README but it did not work for client side code .... I wrote to Aslak Knutsen (he is part of the arquillian-extension-byteman team) ..... hope he can help me ....

                • 6. Re: Using BYTEMAN in JUnit test with Arquillian
                  Ondra Chaloupka Expert

                  Sure, yeap agree

                   

                  I've just quickly checked the extension. I wonder the rule run in the container correctly? I could be missing here something just it seems to me there is not installed both extensions - for client and for the container

                  arquillian-extension-byteman/org.jboss.arquillian.core.spi.LoadableExtension at master · arquillian/arquillian-extension…

                  what about to try to add one more line to the org.jboss.arquillian.core.spi.LoadableExtension file to contain and then compile the extension on your own?

                   

                  org.jboss.arquillian.extension.byteman.impl.BytemanExtension
                  org.jboss.arquillian.extension.byteman.impl.BytemanRemoteExtension

                   

                  Either way there could be some other issue easily.