Arquillian Byteman extension - Rule ruleMapKey always empty -> no code injected
henrik_sr Nov 28, 2012 1:51 AMHi
This question may not be related to Byteman but instead the Arquillian forum - if so I will move it.
I am working on a project where we use Arquillian together with GlassFish 3.
However, we have struggled to use the Arquillian-ByteMan extension and seem to have hit wall wrt. getting our injection code invoked.
When we debug, the context in which the public static execute method on Rule is invoked has an empty HashMap<String, Rule> ruleKeyMap.
Hence our injected rule code is never invoked.
Before reaching the execute method we have verified that the rule is in fact added to the ruleKeyMap and not yet been purged.
Below you will find the very simple test class and also the dependencies used.
Please note that I have to set autoInstallAgent to false and in my running Glassfish3 instance add this to the
JVM options of the server config: -javaagent:${com.sun.aas.instanceRoot}/lib/byteman-2.1.0.jar=listener:true,port:9999
So to sum up - can anyone maybe explain in which contexts the Rule class is used and why this problem occurs.
Currently we can not defend spending more time on getting this work so another approach will have to be taken.
If anyone can guide us in the right direction I will however try to get this working since it really seems ideal for our error test scenarios.
Thank you in advance.
Regards Henrik
@RunWith(Arquillian.class)
public class ByteManGlassfish3Test_IT
{
@Deployment
public static Archive<?> deployment()
{
return DeploymentHelper.createArchive();
}
@Test
@BMRule(
name="FaultyInjectionRule",
targetClass="com.ejb.egs.ByteManGlassfish3Test_IT.TestClass",
targetMethod="testMethod",
action="System.out.println(\"Test impl\");"
)
public void injectFaultyMethod() throws Exception
{
new TestClass().testMethod();
}
public static class TestClass
{
public void testMethod()
{
System.out.println("Real Impl");
Assert.fail();
}
}
}
Added to my pom.xml
<properties>
<toolsjar>${java.home}/../Classes/classes.jar</toolsjar>
<version.byteman>2.1.0</version.byteman>
</properties>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-extension-byteman</artifactId>
<version>1.0.0.Alpha2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${toolsjar}</systemPath>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
<version>${version.byteman}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-submit</artifactId>
<version>${version.byteman}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-install</artifactId>
<scope>test</scope>
<version>${version.byteman}</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-bmunit</artifactId>
<scope>test</scope>
<version>${version.byteman}</version>
</dependency>
Added to my arquillian.xml in test resources:
<extension qualifier="byteman">
<property name="autoInstallAgent">false</property>
<property name="agentProperties">org.jboss.byteman.verbose=true</property>
<property name="clientAgentPort">9999</property>
<property name="containerAgentPort">9999</property>
</extension>
Added to my running Glassfish 3 instance
-javaagent:${com.sun.aas.instanceRoot}/lib/byteman-2.1.0.jar=listener:true,port:9999
-Dorg.jboss.byteman.verbose=true