3 Replies Latest reply on Jul 23, 2013 11:44 AM by Andrew Dinn

    Byteman Exception while running Hibernate-ORM Tests

    Chris Cranford Newbie

      While running the hibernate-orm test cases for 4.2.2.Final, the following exception occured:

       

      java.net.ConnectException: Connection refused: connect

        at java.net.DualStackPlainSocketImpl.connect0(Native Method)

      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:69)

      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)

      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)

      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)

      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)

      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)

      at java.net.Socket.connect(Socket.java:579)

      at java.net.Socket.connect(Socket.java:528)

      at java.net.Socket.<init>(Socket.java:425)

      at java.net.Socket.<init>(Socket.java:208)

      at org.jboss.byteman.agent.submit.Submit$Comm.<init>(Submit.java:871)

      at org.jboss.byteman.agent.submit.Submit.submitRequest(Submit.java:777)

      at org.jboss.byteman.agent.submit.Submit.addScripts(Submit.java:595)

      at org.jboss.byteman.contrib.bmunit.BMUnit.loadScriptText(BMUnit.java:358)

      at org.jboss.byteman.contrib.bmunit.BMUnitRunner$7.evaluate(BMUnitRunner.java:316)

      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

      at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

      at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)

       

      BMUnit : Unable to identify test JVM process during agent load

       

      In speaking with folks in the hibernate channel, they weren't able to specifically assist with why the test was failing and recommended I post here for assistance.  Can someone explain what this may be trying to connect to and what could potentially be blocking this test case?   Windows Firewall is disabled but we do have a corporate firewall which my system is behind (if that helps).

        • 1. Re: Byteman Exception while running Hibernate-ORM Tests
          Andrew Dinn Master

          Hi Chris,

           

           

          Chris Cranford wrote:

           

          While running the hibernate-orm test cases for 4.2.2.Final, the following exception occured:

           

          java.net.ConnectException: Connection refused: connect

            at java.net.DualStackPlainSocketImpl.connect0(Native Method)

          . . .

          at java.net.Socket.<init>(Socket.java:208)

          at org.jboss.byteman.agent.submit.Submit$Comm.<init>(Submit.java:871)

          at org.jboss.byteman.agent.submit.Submit.submitRequest(Submit.java:777)

          at org.jboss.byteman.agent.submit.Submit.addScripts(Submit.java:595)

          at org.jboss.byteman.contrib.bmunit.BMUnit.loadScriptText(BMUnit.java:358)

          at org.jboss.byteman.contrib.bmunit.BMUnitRunner$7.evaluate(BMUnitRunner.java:316)

          at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)

          at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)

          at org.junit.internal.runners.statements.FailOnTimeout$StatementThread.run(FailOnTimeout.java:62)

           

          BMUnit : Unable to identify test JVM process during agent load

           

          In speaking with folks in the hibernate channel, they weren't able to specifically assist with why the test was failing and recommended I post here for assistance.  Can someone explain what this may be trying to connect to and what could potentially be blocking this test case?   Windows Firewall is disabled but we do have a corporate firewall which my system is behind (if that helps).

           

          Ok, first I'll explain -- very briefly -- what is happening here.

           

          The connection  is being made by Byteman to Byteman. More precisely, the connection is being opened by BMUnit -- that's an auxiliary Byteman package which integrates Byteman into JUnit and TestNG. The listener on the other side of the connection is the Byteman agent -- that's part of the core Byteman package which is responsible for redefining application or JDK runtime bytecode on the fly. The agent changes bytecode on demand so that the application  under test can be forced to perform the actions needed by the test scenario.

           

          What is the connection used for? BMUNit uses it to upload details of what bytecode to change and how to change it before running a test. It uses a second connection after the test to tell the agent to unload the changes. The changes are specified in annotations on the test class/emthods.

           

          Why does BMUnit need to talk to Byteman using a socket connection? In one word, security. The port is the only point of communication wit the agent (after the comand line) so it is the only thing you need to secure to restrict access to the agent. Given that the agent can change any bytecode that's critically important.

           

          Right, so why are you getting an error?

           

          Well, I can think of two immediate possibilities. Unless someone has configured something clever (let's ignore that 3rd option for now) BMUNit will be attempting to connect using localhost:9090 as the hostname and port.

           

          So, possibility 1) if your firewall does does not allow Byteman to open a listener socket or BMUnit to open a client socket for this host/port combination then you will see this error. Check your firewall config? If it turns out that this port is not accessible then you can do one of two things

           

          • make the port accessible
          • tell Byteman to use a different, accessible port (details below in a second)

           

          Now for possibility 2)  if you are using Byteman for your Hibernate tests and also using Byteman to run some other tests at the same time on the same host then you you will have two JVMs both trying to use local port 9090. If it turns out that this is what was happening then you can do one of two things

           

          • only execute one set of tests at a time
          • tell Byteman to use a different, accessible port unique to each test JVM

           

          How do you configure which port Bytreman uses? At the moment the port used by BMUNit/Byteman is configured using a system property

           

            org.jboss.byteman.contrib.bmunit.agent.port

           

          The value should be a String  representation of the port number e.g. "54321", "0x8fff".

           

          So, if you are running you tests from maven then change the surefire configuration to define this system property:

           

          <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-surefire-plugin</artifactId>

              <configuration>

                . . .

                <systemPropertyVariables>

                  <org.jboss.byteman.contrib.bmunit.agent.port>0x8fff</org.jboss.byteman.contrib.bmunit.agent.port>

                </systemPropertyVariables>

              </configuration>

          </plugin>

           

           

          If you are running your tests from a Java command line then pass the following extra argument on the command line

           

            -Dorg.jboss.byteman.contrib.bmunit.agent.port=0x8fff

           

          So, please check for these two possibilities and let me know if the suggested fixes work or if something else is going wrong.

           

          regards,

           

           

          Andrew Dinn

          • 2. Re: Byteman Exception while running Hibernate-ORM Tests
            Chris Cranford Newbie

            The tests are being executed from the gradle build system that Hibernate uses and there is no Windows Firewall enabled on this machine.  I tried your suggestion of passing the -Dorg.jboss.byteman.contrib.bmunit.agent.port=0x8fff on the gradle command line but the test case still failed with the same problem.  I never saw anything attempt to listen on port 9090 (without the -D argument) or on port 54321 (with the -D argument) from netstat.  So is it possible that the agent isn't being started before the BMUnit test case is executed?

            • 3. Re: Byteman Exception while running Hibernate-ORM Tests
              Andrew Dinn Master

              Hi Chris,

              Chris Cranford wrote:

               

              The tests are being executed from the gradle build system that Hibernate uses and there is no Windows Firewall enabled on this machine.  I tried your suggestion of passing the -Dorg.jboss.byteman.contrib.bmunit.agent.port=0x8fff on the gradle command line but the test case still failed with the same problem.  I never saw anything attempt to listen on port 9090 (without the -D argument) or on port 54321 (with the -D argument) from netstat.  So is it possible that the agent isn't being started before the BMUnit test case is executed?

               

              Yes, it is possible that the agent is not being started. The agent is automatically installed into the test JVM when the first Byteman-based test is run. If there is a problem loading or running the agent then you should be able to observe both progress and lack thereof by setting the following two system properties

               

                -Dorg.jboss.byteman.contrib.bmunit.verbose=true

                -Dorg.jboss.byteman.verbose=true

               

              Setting the first variable causes BMUnit to print trace messages to System.out. So, if the agent install fails then you should see some messages from Byteman in the test output indicating the nature of the failure. If it succeeds you should see a confirmation message.

               

              Setting the second variable causes the Byteman agent to print trace messages to System.out. So, if the  agent does install but fails to open the listener socket or dies for some other reason you ought to see error messages from Byteman in the test output.

               

              If you can try running with these settings and report whatever errors you find I may be able to diagnose the problem. Thanks very much for helping debug this issue.

               

              regards,

               

               

              Andrew Dinn