Tx Control spec compliance - re-fix the setRollbackOnly issue in pre completion and add a unit test
diff --git a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java
index 678f416..109ff85 100644
--- a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java
+++ b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java
@@ -315,10 +315,11 @@
 						if (re.getCause() instanceof SetRollbackOnlyException) {
 							// This means that a pre-completion callback called setRollbackOnly
 							// which can be safely ignored (i.e. it's not really an exception)
-						}
-						TransactionRolledBackException tre = 
+						} else {
+							TransactionRolledBackException tre = 
 								new TransactionRolledBackException(re.getMessage(), re);
-						throw tre;
+							throw tre;
+						}
 					}
 				}
 			} catch (Exception e) {
diff --git a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
index aa5c0a0..d528fbe 100644
--- a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
+++ b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
@@ -94,6 +94,24 @@
 	}
 
 	@Test
+	public void testRequiredMarkedRollbackInPrecompletion() {
+		
+		AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>();
+		
+		txControl.required(() -> {
+			
+			assertTrue(txControl.activeTransaction());
+			
+			txControl.getCurrentContext().postCompletion(finalStatus::set);
+			
+			txControl.getCurrentContext().preCompletion(txControl::setRollbackOnly);
+			return null;
+		});
+		
+		assertEquals(ROLLED_BACK, finalStatus.get());
+	}
+
+	@Test
 	public void testRequiredUserException() {
 		
 		AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>();