7 Replies Latest reply on Apr 16, 2019 7:20 PM by rachmato

    Using BYTEMAN in JUnit test with Arquillian

    tommaso-borgato

      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
          adinn

          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

            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
              adinn

              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

              • 4. Re: Using BYTEMAN in JUnit test with Arquillian
                ochaloup

                Even I haven't tried it personally, have you tried the arquillian extension? GitHub - arquillian/arquillian-extension-byteman: Byteman integration for Arquillian

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

                  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
                    ochaloup

                    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.

                    • 7. Re: Using BYTEMAN in JUnit test with Arquillian
                      rachmato

                      I've got the same problem. I believe if you annotate the method with @RunAsClient it should cause the agent to be installed on the client side, but so far it hasn't worked for me. This method is used in one testcase in the testsuite for the extension and works. Still trying to get it working.

                       

                      Posted my version of "constructive feedback" as an issue on the project: Byteman extension is incomplete · Issue #24 · arquillian/arquillian-extension-byteman · GitHub

                       

                      UPDATE: Adding the annotation @RunAsClient *will* cause the Byteman agent to be installed in the test process; rules seem to execute fine as long as you are prepared to live with @BMRules and @BMRule.