You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2018/01/19 17:28:48 UTC

[aries-tx-control] 01/04: Tx Control Service spec work Support XA recovery based on a system property as well as config admin. Correctly advertise recovery support Don't use a javax.resource exception that isn't imported

This is an automated email from the ASF dual-hosted git repository.

timothyjward pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-tx-control.git

commit eb3d657b702b25a5dd88457670647b4233d1615c
Author: Tim Ward <ti...@apache.org>
AuthorDate: Fri Jan 19 16:15:49 2018 +0000

    Tx Control Service spec work
    Support XA recovery based on a system property as well as config admin.
    Correctly advertise recovery support
    Don't use a javax.resource exception that isn't imported
---
 tx-control-services/tx-control-service-xa/.gitignore         |  1 +
 tx-control-services/tx-control-service-xa/bnd.bnd            |  3 ++-
 .../tx/control/service/xa/impl/TransactionControlImpl.java   | 12 +++++++-----
 .../service/xa/impl/TransactionControlRunningTest.java       |  5 ++++-
 .../service/xa/impl/TransactionControlStatusTest.java        |  5 ++++-
 .../tx/control/service/xa/impl/TransactionLifecycleTest.java |  5 ++++-
 6 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/tx-control-services/tx-control-service-xa/.gitignore b/tx-control-services/tx-control-service-xa/.gitignore
new file mode 100644
index 0000000..b83d222
--- /dev/null
+++ b/tx-control-services/tx-control-service-xa/.gitignore
@@ -0,0 +1 @@
+/target/
diff --git a/tx-control-services/tx-control-service-xa/bnd.bnd b/tx-control-services/tx-control-service-xa/bnd.bnd
index 8dd8683..02fcc35 100644
--- a/tx-control-services/tx-control-service-xa/bnd.bnd
+++ b/tx-control-services/tx-control-service-xa/bnd.bnd
@@ -63,4 +63,5 @@ Import-Package: !javax.resource.*, \
                 org.osgi.service.transaction.control, \
                 *
     
-Provide-Capability: osgi.service;objectClass="org.osgi.service.transaction.control.TransactionControl";osgi.local.enabled="true";osgi.xa.enabled="true";uses:="org.osgi.service.transaction.control"
\ No newline at end of file
+Provide-Capability: osgi.service;objectClass="org.osgi.service.transaction.control.TransactionControl";osgi.local.enabled="true";osgi.xa.enabled="true";osgi.recovery.enabled="true";uses:="org.osgi.service.transaction.control"
+
diff --git a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlImpl.java b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlImpl.java
index 516ba50..11e2031 100644
--- a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlImpl.java
+++ b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlImpl.java
@@ -30,7 +30,6 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Map;
 
-import javax.resource.spi.IllegalStateException;
 import javax.transaction.SystemException;
 import javax.transaction.xa.XAResource;
 
@@ -153,19 +152,21 @@ public class TransactionControlImpl extends AbstractTransactionControlImpl {
 	}
 
 	private HOWLLog getLog(BundleContext ctx) throws Exception {
-		Object recovery = config.getOrDefault("recovery.log.enabled", false);
+		Object recovery = config.getOrDefault("recovery.log.enabled", 
+				Boolean.parseBoolean(String.valueOf(ctx.getProperty(
+						"org.apache.aries.tx.control.service.xa.recovery.log.enabled"))));
 		
 		if (recovery instanceof Boolean ? (Boolean) recovery : Boolean.valueOf(recovery.toString())) {
-			String logFileExt = "log";
+            String logFileExt = "log";
             String logFileName = "transaction";
             
             String logFileDir;
 
             Object o = config.get("recovery.log.dir");
             if(o == null) {
-            	logFileDir = ctx.getDataFile("recoveryLog").getAbsolutePath();
+                logFileDir = ctx.getDataFile("recoveryLog").getAbsolutePath();
             } else {
-            	logFileDir = o.toString();
+                logFileDir = o.toString();
             }
             
             File f = new File(logFileDir);
@@ -264,6 +265,7 @@ public class TransactionControlImpl extends AbstractTransactionControlImpl {
 		
 		props.put("osgi.xa.enabled", Boolean.TRUE);
 		props.put("osgi.local.enabled", getLocalResourceSupport() != DISABLED);
+		props.put("osgi.recovery.enabled", log != null);
 		props.put(Constants.SERVICE_DESCRIPTION, "The Apache Aries Transaction Control Service for XA Transactions");
 		props.put(Constants.SERVICE_VENDOR, "Apache Aries");
 		
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 a7ad5d0..aa5c0a0 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
@@ -35,6 +35,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.transaction.control.LocalResource;
 import org.osgi.service.transaction.control.ResourceProvider;
 import org.osgi.service.transaction.control.ScopedWorkException;
@@ -44,6 +45,8 @@ import org.osgi.service.transaction.control.TransactionStatus;
 public class TransactionControlRunningTest {
 
 	@Mock
+	BundleContext ctx;
+	@Mock
 	ResourceProvider<Object> testProvider;
 	@Mock
 	LocalResource testResource;
@@ -52,7 +55,7 @@ public class TransactionControlRunningTest {
 
 	@Before
 	public void setUp() throws Exception {
-		txControl = new TransactionControlImpl(null, Collections.emptyMap());
+		txControl = new TransactionControlImpl(ctx, Collections.emptyMap());
 	}
 
 	@Test
diff --git a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlStatusTest.java b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlStatusTest.java
index 7f3a797..28ae10c 100644
--- a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlStatusTest.java
+++ b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlStatusTest.java
@@ -37,6 +37,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.transaction.control.LocalResource;
 import org.osgi.service.transaction.control.ResourceProvider;
 import org.osgi.service.transaction.control.TransactionContext;
@@ -45,6 +46,8 @@ import org.osgi.service.transaction.control.TransactionContext;
 public class TransactionControlStatusTest {
 
 	@Mock
+	BundleContext ctx;
+	@Mock
 	ResourceProvider<Object> testProvider;
 	@Mock
 	LocalResource testResource;
@@ -58,7 +61,7 @@ public class TransactionControlStatusTest {
 
 		resource = new Object();
 		
-		txControl = new TransactionControlImpl(null, Collections.emptyMap());
+		txControl = new TransactionControlImpl(ctx, Collections.emptyMap());
 	}
 
 	@Test
diff --git a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionLifecycleTest.java b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionLifecycleTest.java
index a85cdf1..d82cede 100644
--- a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionLifecycleTest.java
+++ b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionLifecycleTest.java
@@ -30,6 +30,7 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.osgi.framework.BundleContext;
 import org.osgi.service.transaction.control.LocalResource;
 import org.osgi.service.transaction.control.ResourceProvider;
 
@@ -37,6 +38,8 @@ import org.osgi.service.transaction.control.ResourceProvider;
 public class TransactionLifecycleTest {
 
 	@Mock
+	BundleContext ctx;
+	@Mock
 	ResourceProvider<Object> testProvider;
 	@Mock
 	LocalResource testResource;
@@ -45,7 +48,7 @@ public class TransactionLifecycleTest {
 
 	@Before
 	public void setUp() throws Exception {
-		txControl = new TransactionControlImpl(null, Collections.emptyMap());
+		txControl = new TransactionControlImpl(ctx, Collections.emptyMap());
 	}
 
 	@Test

-- 
To stop receiving notification emails like this one, please contact
"commits@aries.apache.org" <co...@aries.apache.org>.