You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/10/20 09:01:28 UTC

svn commit: r586675 - in /incubator/tuscany/java/sca/modules/policy-transaction/src: main/java/org/apache/tuscany/sca/policy/transaction/ main/resources/ test/java/org/apache/tuscany/sca/policy/transaction/

Author: rfeng
Date: Sat Oct 20 00:01:28 2007
New Revision: 586675

URL: http://svn.apache.org/viewvc?rev=586675&view=rev
Log:
Use HOWL log and test 2PC with mocked XA resources

Added:
    incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties   (with props)
Modified:
    incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java
    incubator/tuscany/java/sca/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java

Modified: incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java?rev=586675&r1=586674&r2=586675&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java (original)
+++ incubator/tuscany/java/sca/modules/policy-transaction/src/main/java/org/apache/tuscany/sca/policy/transaction/TransactionModuleActivator.java Sat Oct 20 00:01:28 2007
@@ -19,10 +19,14 @@
 
 package org.apache.tuscany.sca.policy.transaction;
 
+import java.io.File;
+
 import javax.transaction.TransactionManager;
-import javax.transaction.xa.XAException;
 
+import org.apache.geronimo.transaction.log.HOWLLog;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.geronimo.transaction.manager.XidFactory;
+import org.apache.geronimo.transaction.manager.XidFactoryImpl;
 import org.apache.tuscany.sca.core.ExtensionPointRegistry;
 import org.apache.tuscany.sca.core.ModuleActivator;
 
@@ -31,23 +35,65 @@
  */
 public class TransactionModuleActivator implements ModuleActivator {
     private TransactionManager transactionManager;
-    
+    private HOWLLog howlLog;
+    private XidFactory xidFactory;
+
+    private String logFileDir = "target/logs";
+    private String bufferClassName = "org.objectweb.howl.log.BlockLogBuffer";
+    private int bufferSizeKBytes = 32;
+    private boolean checksumEnabled = true;
+    private boolean adler32Checksum = true;
+    private int flushSleepTimeMilliseconds = 50;
+    private String logFileExt = "log";
+    private String logFileName = "transaction";
+    private int maxBlocksPerFile = -1;
+    private int maxLogFiles = 2;
+    private int maxBuffers = 0;
+    private int minBuffers = 4;
+    private int threadsWaitingForceThreshold = -1;
+    private File serverBaseDir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
+
     /**
      * @see org.apache.tuscany.sca.core.ModuleActivator#start(org.apache.tuscany.sca.core.ExtensionPointRegistry)
      */
     public void start(ExtensionPointRegistry registry) {
         try {
-            this.transactionManager = new GeronimoTransactionManager();
-        } catch (XAException e) {
+            xidFactory = new XidFactoryImpl();
+            howlLog =
+                new HOWLLog(bufferClassName, bufferSizeKBytes, checksumEnabled, adler32Checksum,
+                            flushSleepTimeMilliseconds, logFileDir, logFileExt, logFileName, maxBlocksPerFile,
+                            maxBuffers, maxLogFiles, minBuffers, threadsWaitingForceThreshold, xidFactory,
+                            serverBaseDir);
+
+            howlLog.doStart();
+            this.transactionManager = new GeronimoTransactionManager(1200, xidFactory, howlLog);
+        } catch (Exception e) {
             throw new IllegalStateException(e);
         }
-        registry.addExtensionPoint(this.transactionManager);
+        if (registry != null) {
+            registry.addExtensionPoint(this.transactionManager);
+        }
     }
 
     /**
      * @see org.apache.tuscany.sca.core.ModuleActivator#stop(org.apache.tuscany.sca.core.ExtensionPointRegistry)
      */
     public void stop(ExtensionPointRegistry registry) {
+        try {
+            howlLog.doStop();
+            if (registry != null) {
+                registry.removeExtensionPoint(transactionManager);
+            }
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
+
+    public TransactionManager getTransactionManager() {
+        if (transactionManager == null) {
+            start(null);
+        }
+        return transactionManager;
     }
 
 }

Added: incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties?rev=586675&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties (added)
+++ incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties Sat Oct 20 00:01:28 2007
@@ -0,0 +1,29 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+#  
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=INFO, CONSOLE
+
+# CONSOLE is set to be a ConsoleAppender.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+
+
+# Print only messages of level WARN or above in the package com.foo.
+log4j.logger.org.apache.tuscany=INFO
\ No newline at end of file

Propchange: incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/modules/policy-transaction/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java?rev=586675&r1=586674&r2=586675&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java (original)
+++ incubator/tuscany/java/sca/modules/policy-transaction/src/test/java/org/apache/tuscany/sca/policy/transaction/TransactionManagerHelperTestCase.java Sat Oct 20 00:01:28 2007
@@ -22,6 +22,7 @@
 import java.util.logging.Logger;
 
 import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
 import javax.transaction.xa.XAException;
 import javax.transaction.xa.XAResource;
 import javax.transaction.xa.Xid;
@@ -29,7 +30,7 @@
 import junit.framework.TestCase;
 
 import org.apache.geronimo.transaction.GeronimoUserTransaction;
-import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
+import org.apache.geronimo.transaction.manager.NamedXAResource;
 
 /**
  * @version $Rev$ $Date$
@@ -37,15 +38,22 @@
 public class TransactionManagerHelperTestCase extends TestCase {
     private static final Logger logger = Logger.getLogger(TransactionManagerHelper.class.getName());
 
-    public static class MockXAResource implements XAResource {
+    public static class MockXAResource implements NamedXAResource {
+
+        private String rm;
         private String id;
         private int timeout = 1000;
 
-        public MockXAResource(String id) {
+        public MockXAResource(String rm, String id) {
             super();
+            this.rm = rm;
             this.id = id;
         }
 
+        public String getName() {
+            return rm + ":" + id;
+        }
+
         public void commit(Xid xid, boolean onePhase) throws XAException {
             logger.info(id + ": commit(" + xid + "," + onePhase + ")");
         }
@@ -63,7 +71,12 @@
         }
 
         public boolean isSameRM(XAResource xares) throws XAException {
-            return xares instanceof MockXAResource;
+            if (xares instanceof MockXAResource) {
+                MockXAResource res = (MockXAResource)xares;
+                return res.rm.endsWith(rm);
+            } else {
+                return false;
+            }
         }
 
         public int prepare(Xid xid) throws XAException {
@@ -125,7 +138,9 @@
     }
 
     public void testHelper() throws Exception {
-        GeronimoTransactionManager tm = new GeronimoTransactionManager();
+        TransactionModuleActivator activator = new TransactionModuleActivator();
+        activator.start(null);
+        TransactionManager tm = activator.getTransactionManager();
         GeronimoUserTransaction tx = new GeronimoUserTransaction(tm);
         TransactionManagerHelper helper = new TransactionManagerHelper(tm);
 
@@ -136,8 +151,8 @@
         assertNotNull(t1);
         // The current TX should be T1
         assertSame(t1, tm.getTransaction());
-        tm.getTransaction().enlistResource(new MockXAResource("001"));
-        tm.getTransaction().enlistResource(new MockXAResource("002"));
+        tm.getTransaction().enlistResource(new MockXAResource("Derby", "001"));
+        tm.getTransaction().enlistResource(new MockXAResource("DB2", "002"));
 
         Transaction suspended = helper.suspendsTransactionPreInvoke();
         // T1 is suspended
@@ -149,7 +164,7 @@
         assertNotNull(t2);
         // The current TX should be T2
         assertSame(t2, tm.getTransaction());
-        tm.getTransaction().enlistResource(new MockXAResource("003"));
+        tm.getTransaction().enlistResource(new MockXAResource("Oracle", "003"));
 
         tx.rollback();
 
@@ -163,5 +178,7 @@
         helper.managedGlobalTransactionPostInvoke(t1);
         assertNotNull(tm.getTransaction());
         assertEquals(6, t1.getStatus());
+
+        activator.stop(null);
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org