Permalink
Browse files

JBTM-1289 XTS participant completion tests should use a rendezvous to…

… delay close until participant has completed
  • Loading branch information...
1 parent 7284be3 commit 54dc9a9412bfbbcb456fa8169708d5c9d810b559 @paulrobinson paulrobinson committed Nov 26, 2012
View
30 XTS/byteman_support/pom.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated by the @authors tag. All rights reserved. See the copyright.txt in the distribution
+ for a full listing of individual contributors. This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser
+ General Public License, v. 2.1. This program is distributed in the hope that it will be useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License, v.2.1 along with this distribution; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.narayana.xts</groupId>
+ <artifactId>xts-all</artifactId>
+ <version>5.0.0.M2-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>byteman_support</artifactId>
+ <packaging>jar</packaging>
+ <name>Reusable Byteman rules for xts</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.byteman</groupId>
+ <artifactId>byteman</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.byteman</groupId>
+ <artifactId>byteman-submit</artifactId>
+ </dependency>
+ </dependencies>
+</project>
View
53 XTS/byteman_support/src/main/java/org/jboss/jbossts/xts/bytemanSupport/BMScript.java
@@ -0,0 +1,53 @@
+package org.jboss.jbossts.xts.bytemanSupport;
+
+import org.jboss.byteman.agent.submit.Submit;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author paul.robinson@redhat.com 22/11/2012
+ */
+public class BMScript {
+
+ private static final Submit submit = new Submit();
+
+ public static void submit(String scriptResourcePath) {
+
+ try {
+ List<InputStream> streams = getScriptFromResource(scriptResourcePath);
+ submit.addRulesFromResources(streams);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to submit Byteman script", e);
+ }
+ }
+
+ public static void remove(String scriptResourcePath) {
+
+ try {
+ List<InputStream> streams = getScriptFromResource(scriptResourcePath);
+ submit.deleteRulesFromResources(streams);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to remove Byteman script", e);
+ }
+ }
+
+ private static List<InputStream> getScriptFromResource(String scriptResourcePath) {
+ URL resource = Thread.currentThread().getContextClassLoader().getResource(scriptResourcePath);
+ if (resource == null) {
+ throw new RuntimeException("'" + scriptResourcePath + "' can't be found on the classpath");
+ }
+
+ List<InputStream> streams = new ArrayList<InputStream>();
+ try {
+ streams.add(resource.openStream());
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to open stream at url location: " + resource.toString());
+ }
+ return streams;
+ }
+
+}
View
13 ...ossts/xts/bytemanSupport/participantCompletion/ParticipantCompletionCoordinatorRules.java
@@ -0,0 +1,13 @@
+package org.jboss.jbossts.xts.bytemanSupport.participantCompletion;
+
+/**
+ * @Author paul.robinson@redhat.com 26/11/2012
+ */
+public class ParticipantCompletionCoordinatorRules {
+
+ public static String RESOURCE_PATH= "org/jboss/jbossts/xts/bytemanSupport/participantCompletion/participant_completion_coordinator_rules.btm";
+
+ public static void setParticipantCount(Integer participantCount) {
+ //Dummy method, detected by Byteman Rules
+ }
+}
View
40 ...sts/xts/bytemanSupport/participantCompletion/participant_completion_coordinator_rules.btm
@@ -0,0 +1,40 @@
+RULE create counter
+CLASS org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules
+METHOD setParticipantCount(Integer)
+BIND counter:Integer=$1
+IF TRUE
+DO debug("participant_completion.counter.create: " + counter),
+ deleteCounter("completes"),
+ createCounter("completes", counter)
+ENDRULE
+
+RULE complete called
+CLASS com.arjuna.webservices11.wsba.sei.BusinessAgreementWithParticipantCompletionCoordinatorPortTypeImpl
+METHOD completedOperation(NotificationType)
+AT RETURN
+BIND NOTHING
+IF (debug("participant_completion.counter.decrement") AND decrementCounter("completes") == 0)
+DO debug("participant_completion.called.waking"),
+ signalWake("complete", true),
+ debug("participant_completion.called.donewake")
+ENDRULE
+
+RULE close called
+CLASS com.arjuna.webservices11.wsarjtx.sei.TerminationCoordinatorPortTypeImpl
+METHOD closeOperation(NotificationType)
+BIND NOTHING
+IF TRUE
+DO debug("participant_completion.close.waiting"),
+ waitFor("complete"),
+ debug("participant_completion.close.woken")
+ENDRULE
+
+RULE cancel called
+CLASS com.arjuna.webservices11.wsarjtx.sei.TerminationCoordinatorPortTypeImpl
+METHOD cancelOperation(NotificationType)
+BIND NOTHING
+IF TRUE
+DO debug("participant_completion.cancel.waiting"),
+ waitFor("complete"),
+ debug("participant_completion.cancel.woken")
+ENDRULE
View
2 XTS/localjunit/WSTX/src/main/java/com/arjuna/wst11/tests/arq/ba/Close.java
@@ -67,8 +67,6 @@ public void testClose()
throw eouter;
}
- //[JBTM-1292]
- Thread.sleep(3*1000);
uba.close();
assertTrue(p.passed());
View
2 XTS/localjunit/WSTX/src/main/java/com/arjuna/wst11/tests/arq/ba/Exit.java
@@ -68,8 +68,6 @@ public void testExit()
throw eouter;
}
- //[JBTM-1292]
- Thread.sleep(3*1000);
uba.close();
assertTrue(p.passed());
View
2 XTS/localjunit/WSTX/src/main/java/com/arjuna/wst11/tests/arq/ba/MultiClose.java
@@ -73,8 +73,6 @@ public void testMultiClose()
}
throw eouter;
}
- //[JBTM-1292]
- Thread.sleep(3*1000);
uba.close();
assertTrue(p.passed());
}
View
18 XTS/localjunit/WSTX/src/test/java/com/arjuna/wst11/tests/arq/ba/CloseTest.java
@@ -4,7 +4,11 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.jbossts.xts.bytemanSupport.BMScript;
+import org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules;
import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,11 +24,23 @@
public static WebArchive createDeployment() {
return WarDeployment.getDeployment(
Close.class,
- DemoBusinessParticipant.class);
+ DemoBusinessParticipant.class,
+ ParticipantCompletionCoordinatorRules.class);
}
+
+ @BeforeClass()
+ public static void submitBytemanScript() throws Exception {
+ BMScript.submit(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
+ @AfterClass()
+ public static void removeBytemanScript() {
+ BMScript.remove(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
@Test
public void test() throws Exception {
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
test.testClose();
}
}
View
18 XTS/localjunit/WSTX/src/test/java/com/arjuna/wst11/tests/arq/ba/CompensateTest.java
@@ -4,7 +4,11 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.jbossts.xts.bytemanSupport.BMScript;
+import org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules;
import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -20,11 +24,23 @@
public static WebArchive createDeployment() {
return WarDeployment.getDeployment(
Compensate.class,
- DemoBusinessParticipant.class);
+ DemoBusinessParticipant.class,
+ ParticipantCompletionCoordinatorRules.class);
}
+
+ @BeforeClass()
+ public static void submitBytemanScript() throws Exception {
+ BMScript.submit(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
+ @AfterClass()
+ public static void removeBytemanScript() {
+ BMScript.remove(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
@Test
public void test() throws Exception {
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
test.testCompensate();
}
}
View
21 XTS/localjunit/WSTX/src/test/java/com/arjuna/wst11/tests/arq/ba/MultiCloseTest.java
@@ -4,7 +4,11 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.jbossts.xts.bytemanSupport.BMScript;
+import org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules;
import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,6 +18,7 @@
@RunWith(Arquillian.class)
public class MultiCloseTest {
+
@Inject
MultiClose test;
@@ -22,11 +27,23 @@ public static WebArchive createDeployment() {
return WarDeployment.getDeployment(
MultiClose.class,
DemoBusinessParticipant.class,
- FailureBusinessParticipant.class);
+ FailureBusinessParticipant.class,
+ ParticipantCompletionCoordinatorRules.class);
}
-
+
+ @BeforeClass()
+ public static void submitBytemanScript() throws Exception {
+ BMScript.submit(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
+ @AfterClass()
+ public static void removeBytemanScript() {
+ BMScript.remove(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
@Test
public void test() throws Exception {
+ ParticipantCompletionCoordinatorRules.setParticipantCount(2);
test.testMultiClose();
}
}
View
18 XTS/localjunit/WSTX/src/test/java/com/arjuna/wst11/tests/arq/ba/MultiCompensateTest.java
@@ -4,7 +4,11 @@
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.jbossts.xts.bytemanSupport.BMScript;
+import org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules;
import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -22,11 +26,23 @@ public static WebArchive createDeployment() {
return WarDeployment.getDeployment(
MultiCompensate.class,
DemoBusinessParticipant.class,
- FailureBusinessParticipant.class);
+ FailureBusinessParticipant.class,
+ ParticipantCompletionCoordinatorRules.class);
}
+
+ @BeforeClass()
+ public static void submitBytemanScript() throws Exception {
+ BMScript.submit(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
+ @AfterClass()
+ public static void removeBytemanScript() {
+ BMScript.remove(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
@Test
public void test() throws Exception {
+ ParticipantCompletionCoordinatorRules.setParticipantCount(2);
test.testMultiCompensate();
}
}
View
68 XTS/localjunit/pom.xml
@@ -18,19 +18,52 @@
<description>localjunit tests for xts</description>
<properties>
<buildType>11</buildType>
- <general.server.jvm.args>-Xms64m -Xmx1024m -XX:MaxPermSize=512m</general.server.jvm.args>
+ <general.server.jvm.args>-Xms64m -Xmx1024m -XX:MaxPermSize=512m
+ -Dorg.jboss.byteman.verbose
+ -Djboss.modules.system.pkgs=org.jboss.byteman
+ -Dorg.jboss.byteman.transform.all
+ -javaagent:${project.build.directory}/lib/byteman.jar=listener:true
+ </general.server.jvm.args>
<ipv4.server.jvm.args></ipv4.server.jvm.args>
<ipv6.server.jvm.args>-Djboss.bind.address=[::1] -Djboss.bind.address.management=[::1] -Djboss.bind.address.unsecure=[::1] -Djava.net.preferIPv4Stack=false -Djava.net.preferIPv6Addresses=true</ipv6.server.jvm.args>
<server.debug.args>Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5006</server.debug.args>
</properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <stripVersion>true</stripVersion>
+ <includeGroupIds>org.jboss.byteman</includeGroupIds>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<dependency>
<groupId>org.jboss.narayana.xts</groupId>
<artifactId>jbossxts</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.jboss.narayana.xts</groupId>
+ <artifactId>byteman_support</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>compile</scope>
@@ -67,6 +100,37 @@
</plugins>
</build>
</profile>
+ <profile>
+ <id>arq-remote</id>
+ <activation>
+ <activeByDefault>false</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>once</forkMode>
+ <systemPropertyVariables combine.children="append">
+ <!--
+ Used in arquillian.xml
+ -->
+ <server.jvm.args>${general.server.jvm.args} ${ipv4.server.jvm.args}</server.jvm.args>
+ <node.address>127.0.0.1</node.address>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.as</groupId>
+ <artifactId>jboss-as-arquillian-container-remote</artifactId>
+ <version>${jboss-as.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </profile>
<profile>
<id>arq</id>
<activation>
@@ -83,7 +147,7 @@
Used in arquillian.xml
-->
<server.jvm.args>${general.server.jvm.args} ${ipv4.server.jvm.args}</server.jvm.args>
- <node.address>127.0.0.1</node.address>
+ <node.address>127.0.0.1</node.address>
</systemPropertyVariables>
</configuration>
</plugin>
View
1 XTS/pom.xml
@@ -37,6 +37,7 @@
</plugins>
</build>
<modules>
+ <module>byteman_support</module>
<module>WSAS</module>
<module>WSAS/xts-test-servlet</module>
<module>WS-C</module>
View
8 common/pom.xml
@@ -52,6 +52,14 @@
</plugins>
</build>
<dependencies>
+ <dependency>
+ <groupId>org.jboss.byteman</groupId>
+ <artifactId>byteman</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.byteman</groupId>
+ <artifactId>byteman-submit</artifactId>
+ </dependency>
<!-- START TEST -->
<dependency>
<groupId>junit</groupId>
View
15 pom.xml
@@ -943,6 +943,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.narayana.xts</groupId>
+ <artifactId>byteman_support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>restat-web</artifactId>
<version>${project.version}</version>
@@ -973,27 +978,27 @@
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman</artifactId>
- <version>2.0.1</version>
+ <version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-install</artifactId>
- <version>2.0.1</version>
+ <version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-submit</artifactId>
- <version>2.0.1</version>
+ <version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-bmunit</artifactId>
- <version>2.0.1</version>
+ <version>2.1.2</version>
</dependency>
<dependency>
<groupId>org.jboss.byteman</groupId>
<artifactId>byteman-dtest</artifactId>
- <version>2.0.1</version>
+ <version>2.1.2</version>
</dependency>
</dependencies>
</dependencyManagement>
View
23 txframework/pom.xml
@@ -37,6 +37,24 @@
<skip>true</skip>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>test-compile</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <stripVersion>true</stripVersion>
+ <includeGroupIds>org.jboss.byteman</includeGroupIds>
+ <outputDirectory>${project.build.directory}/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
@@ -112,6 +130,11 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.jboss.narayana.xts</groupId>
+ <artifactId>byteman_support</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.jboss.narayana.rts</groupId>
<artifactId>restat-util</artifactId>
View
29 .../src/test/java/org/jboss/narayana/txframework/functional/BAParticipantCompletionTest.java
@@ -5,6 +5,8 @@
import com.arjuna.wst.TransactionRolledBackException;
import junit.framework.Assert;
import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.jbossts.xts.bytemanSupport.BMScript;
+import org.jboss.jbossts.xts.bytemanSupport.participantCompletion.ParticipantCompletionCoordinatorRules;
import org.jboss.narayana.txframework.api.annotation.lifecycle.ba.Close;
import org.jboss.narayana.txframework.api.annotation.lifecycle.ba.Compensate;
import org.jboss.narayana.txframework.api.annotation.lifecycle.ba.ConfirmCompleted;
@@ -13,7 +15,9 @@
import org.jboss.narayana.txframework.functional.common.SomeApplicationException;
import org.jboss.narayana.txframework.functional.interfaces.BAParticipantCompletion;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -27,6 +31,17 @@
UserBusinessActivity uba;
BAParticipantCompletion client;
+
+ @BeforeClass()
+ public static void submitBytemanScript() throws Exception {
+ BMScript.submit(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
+ @AfterClass()
+ public static void removeBytemanScript() {
+ BMScript.remove(ParticipantCompletionCoordinatorRules.RESOURCE_PATH);
+ }
+
@Before
public void setupTest() throws Exception
{
@@ -45,9 +60,10 @@ public void teardownTest() throws Exception
@Test
public void testAutoComplete() throws Exception
{
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
+
uba.begin();
client.saveDataAutoComplete();
- Thread.sleep(10000); //JBTM-1203
uba.close();
assertOrder(ConfirmCompleted.class, Close.class);
@@ -57,9 +73,10 @@ public void testAutoComplete() throws Exception
@Test
public void testManualComplete() throws Exception
{
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
+
uba.begin();
client.saveDataManualComplete(ServiceCommand.COMPLETE);
- Thread.sleep(10000); //JBTM-1203
uba.close();
assertOrder(ConfirmCompleted.class, Close.class);
@@ -68,10 +85,11 @@ public void testManualComplete() throws Exception
@Test
public void testMultiInvoke() throws Exception
{
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
+
uba.begin();
client.saveDataManualComplete();
client.saveDataManualComplete(ServiceCommand.COMPLETE);
- Thread.sleep(10000); //JBTM-1203
uba.close();
assertOrder(ConfirmCompleted.class, Close.class);
@@ -80,9 +98,10 @@ public void testMultiInvoke() throws Exception
@Test
public void testClientDrivenCompensate() throws Exception
{
+ ParticipantCompletionCoordinatorRules.setParticipantCount(1);
+
uba.begin();
client.saveDataAutoComplete();
- Thread.sleep(10000); //JBTM-1203
uba.cancel();
assertOrder(ConfirmCompleted.class, Compensate.class);
@@ -113,8 +132,8 @@ public void testCannotComplete() throws Exception
{
uba.begin();
client.saveDataAutoComplete(ServiceCommand.CANNOT_COMPLETE);
- Thread.sleep(10000); //JBTM-1203
uba.close();
+
assertOrder();
}
View
5 txframework/src/test/resources/arquillian.xml
@@ -16,6 +16,11 @@
<!-- If you want to use the JBOSS_HOME environment variable, just delete the jbossHome property -->
<configuration>
<property name="serverConfig">standalone-xts.xml</property>
+ <property name="javaVmArguments">-Dorg.jboss.byteman.verbose
+ -Djboss.modules.system.pkgs=org.jboss.byteman
+ -Dorg.jboss.byteman.transform.all
+ -javaagent:../lib/byteman.jar=listener:true
+ </property>
</configuration>
</container>

0 comments on commit 54dc9a9

Please sign in to comment.