incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lin...@apache.org
Subject svn commit: r980298 - in /incubator/aries/trunk/transaction/transaction-blueprint/src: main/java/org/apache/aries/transaction/ test/java/org/apache/aries/transaction/ test/resources/org/apache/aries/transaction/
Date Thu, 29 Jul 2010 03:02:21 GMT
Author: linsun
Date: Thu Jul 29 03:02:21 2010
New Revision: 980298

URL: http://svn.apache.org/viewvc?rev=980298&view=rev
Log:
adding logging for TxComponentMetaDataHelperImpl, update test cases a bit

Modified:
    incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
    incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
    incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries.xml
    incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries2.xml

Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java?rev=980298&r1=980297&r2=980298&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
(original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/main/java/org/apache/aries/transaction/TxComponentMetaDataHelperImpl.java
Thu Jul 29 03:02:21 2010
@@ -29,9 +29,14 @@ import java.util.regex.Pattern;
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class TxComponentMetaDataHelperImpl implements TxComponentMetaDataHelper {
 
+    private static final Logger LOGGER =
+        LoggerFactory.getLogger(TxComponentMetaDataHelperImpl.class);
+
     private static class TranData
     {
       private final Map<Pattern, String> map;
@@ -148,10 +153,10 @@ public class TxComponentMetaDataHelperIm
       }
     }
     
-    private final Map<ComponentMetadata, TranData> data = new ConcurrentHashMap<ComponentMetadata,
TranData>();
+    private static final Map<ComponentMetadata, TranData> data = new ConcurrentHashMap<ComponentMetadata,
TranData>();
     // bundle transaction map keeps track of the default transaction behavior for the bundle
at the bundle-wide level.
     // this is configured via top level tx:transaction element for the blueprint managed
bundle
-    private ConcurrentHashMap<ComponentDefinitionRegistry, List<BundleWideTxData>>
bundleTransactionMap = new ConcurrentHashMap<ComponentDefinitionRegistry, List<BundleWideTxData>>();
+    private static final ConcurrentHashMap<ComponentDefinitionRegistry, List<BundleWideTxData>>
bundleTransactionMap = new ConcurrentHashMap<ComponentDefinitionRegistry, List<BundleWideTxData>>();
 
     public synchronized void setComponentTransactionData(ComponentMetadata component, String
value, String method)
     {
@@ -172,6 +177,9 @@ public class TxComponentMetaDataHelperIm
 
     public String getComponentMethodTxAttribute(ComponentMetadata component, String methodName)
     {
+    	if (LOGGER.isDebugEnabled()) {
+    	    LOGGER.debug("Getting the txAttribute for the component {0} and method {1}", component.getId(),
methodName);
+    	}
         TranData td = data.get(component);
         String result = null;
 
@@ -181,6 +189,9 @@ public class TxComponentMetaDataHelperIm
         } 
         
         if (result != null) {
+        	if (LOGGER.isDebugEnabled()) {
+        	    LOGGER.debug("Return the txAttribute {0} for the component and method", result);
+        	}
             return result;
         } else {
             /* check the bundle wide transaction configuration in the following priority
order from (high to low)
@@ -194,24 +205,35 @@ public class TxComponentMetaDataHelperIm
             ComponentDefinitionRegistry cdr = getComponentDefinitionRegistry(compId);
             if (cdr == null) {
                 // no bundle wide transaction configuration avail
-                return null;
+            	result = null;
             } else {
                 List<BundleWideTxData> bundleData = bundleTransactionMap.get(cdr);
                 result = BundleWideTxDataUtil.getAttribute(compId, methodName, bundleData);
             }
         }
 
+    	if (LOGGER.isDebugEnabled()) {
+    	    LOGGER.debug("Return the txAttribute {0} for the component and method", result);
+    	}
         return result;
     }
     
-    public synchronized void populateBundleWideTransactionData(ComponentDefinitionRegistry
cdr, String value,
+    public void populateBundleWideTransactionData(ComponentDefinitionRegistry cdr, String
value,
             String method, String bean) {
+    	if (LOGGER.isDebugEnabled()) {
+    	    LOGGER.debug("Start populating bundle wide transaction data value {0} method {1}
bean {2} per component definition registry", new Object[]{value, method, bean});
+    	}
+
         BundleWideTxData bundleWideTxData = new BundleWideTxData(value, method, bean);
         List<BundleWideTxData> bundleData = bundleTransactionMap.get(cdr);
         if (bundleData == null) {
             bundleData = new ArrayList<BundleWideTxData>();
             bundleData.add(bundleWideTxData);
+            if (LOGGER.isDebugEnabled()) {
+        	    LOGGER.debug("Adding component definition registry and bundleData to the bundleTransactionMap",
new Object[]{cdr, bundleData});
+            }
             bundleTransactionMap.put(cdr, bundleData);
+
         } else {
             bundleData.add(bundleWideTxData);
         }

Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java?rev=980298&r1=980297&r2=980298&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
(original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/test/java/org/apache/aries/transaction/BundleWideNameSpaceHandlerTest.java
Thu Jul 29 03:02:21 2010
@@ -19,9 +19,11 @@
 package org.apache.aries.transaction;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.net.URI;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
@@ -38,11 +40,14 @@ import org.apache.aries.blueprint.contai
 import org.apache.aries.blueprint.container.NamespaceHandlerRegistry.NamespaceHandlerSet;
 import org.apache.aries.blueprint.namespace.ComponentDefinitionRegistryImpl;
 import org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl;
+import org.junit.After;
+import org.junit.Before;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
 import org.osgi.service.blueprint.reflect.BeanProperty;
+import org.osgi.util.tracker.ServiceTracker;
 
 import org.apache.aries.transaction.TxComponentMetaDataHelperImpl;
 import org.apache.aries.transaction.TxInterceptorImpl;
@@ -51,29 +56,44 @@ import org.apache.aries.unittest.mocks.S
 
 public class BundleWideNameSpaceHandlerTest {
     
+	Bundle b;
+	private NamespaceHandlerRegistry nhri;
+	private TxComponentMetaDataHelperImpl txenhancer;
+	
+    @Before
+    public void setUp() {
+        b = Skeleton.newMock(new BundleMock("org.apache.aries.tx", new Properties()), Bundle.class);
+        BundleContext ctx = b.getBundleContext();
+        nhri = new NamespaceHandlerRegistryImpl(ctx);
+        
+        TransactionManager tm = Skeleton.newMock(TransactionManager.class);
+        
+        txenhancer = new TxComponentMetaDataHelperImpl();
+        
+        TxInterceptorImpl txinterceptor = new TxInterceptorImpl();
+        txinterceptor.setTransactionManager(tm);
+        txinterceptor.setTxMetaDataHelper(txenhancer);
+        
+        TxElementHandler namespaceHandler = new TxElementHandler();
+        namespaceHandler.setTransactionInterceptor(txinterceptor);
+        namespaceHandler.setTxMetaDataHelper(txenhancer);
+            
+        Properties props = new Properties();
+        props.put("osgi.service.blueprint.namespace", "http://aries.apache.org/xmlns/transactions/v1.0.0");
+        ctx.registerService(NamespaceHandler.class.getName(), namespaceHandler, props);
+    }
+    
+    @After
+    public void tearDown() throws Exception{
+    	b = null;
+        nhri = null;
+        txenhancer = null;
+    }
     
     @Test
     public void testMultipleElements() throws Exception
     {
-      Bundle b = Skeleton.newMock(new BundleMock("org.apache.aries.tx", new Properties()),
Bundle.class);
-      BundleContext ctx = b.getBundleContext();
-      NamespaceHandlerRegistry nhri = new NamespaceHandlerRegistryImpl(ctx);
-      
-      TransactionManager tm = Skeleton.newMock(TransactionManager.class);
-      
-      TxComponentMetaDataHelperImpl txenhancer = new TxComponentMetaDataHelperImpl();
-      
-      TxInterceptorImpl txinterceptor = new TxInterceptorImpl();
-      txinterceptor.setTransactionManager(tm);
-      txinterceptor.setTxMetaDataHelper(txenhancer);
-      
-      TxElementHandler namespaceHandler = new TxElementHandler();
-      namespaceHandler.setTransactionInterceptor(txinterceptor);
-      namespaceHandler.setTxMetaDataHelper(txenhancer);
-          
-      Properties props = new Properties();
-      props.put("osgi.service.blueprint.namespace", "http://aries.apache.org/xmlns/transactions/v1.0.0");
-      ctx.registerService(NamespaceHandler.class.getName(), namespaceHandler, props);
+
       Parser p = new Parser();
       
       URL bpxml = this.getClass().getResource("bundlewide-aries.xml");
@@ -87,9 +107,12 @@ public class BundleWideNameSpaceHandlerT
       
       ComponentDefinitionRegistry cdr = new ComponentDefinitionRegistryImpl();
       p.populate(nshandlers, cdr);
+            
+      BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top1");
+      BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down1");
       
-      BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top");
-      BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down");
+      assertNotNull(compTop);
+      assertNotNull(compDown);
       
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(compTop, "doSomething"));
       assertEquals("Never", txenhancer.getComponentMethodTxAttribute(compDown, "doSomething"));
@@ -99,25 +122,6 @@ public class BundleWideNameSpaceHandlerT
     @Test
     public void testMultipleElements2() throws Exception
     {
-      Bundle b = Skeleton.newMock(new BundleMock("org.apache.aries.tx", new Properties()),
Bundle.class);
-      BundleContext ctx = b.getBundleContext();
-      NamespaceHandlerRegistry nhri = new NamespaceHandlerRegistryImpl(ctx);
-      
-      TransactionManager tm = Skeleton.newMock(TransactionManager.class);
-      
-      TxComponentMetaDataHelperImpl txenhancer = new TxComponentMetaDataHelperImpl();
-      
-      TxInterceptorImpl txinterceptor = new TxInterceptorImpl();
-      txinterceptor.setTransactionManager(tm);
-      txinterceptor.setTxMetaDataHelper(txenhancer);
-      
-      TxElementHandler namespaceHandler = new TxElementHandler();
-      namespaceHandler.setTransactionInterceptor(txinterceptor);
-      namespaceHandler.setTxMetaDataHelper(txenhancer);
-          
-      Properties props = new Properties();
-      props.put("osgi.service.blueprint.namespace", "http://aries.apache.org/xmlns/transactions/v1.0.0");
-      ctx.registerService(NamespaceHandler.class.getName(), namespaceHandler, props);
       Parser p = new Parser();
       
       URL bpxml = this.getClass().getResource("bundlewide-aries2.xml");
@@ -132,9 +136,13 @@ public class BundleWideNameSpaceHandlerT
       ComponentDefinitionRegistry cdr = new ComponentDefinitionRegistryImpl();
       p.populate(nshandlers, cdr);
       
-      BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top");
-      BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down");
-      BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle");
+      BeanMetadata compTop = (BeanMetadata) cdr.getComponentDefinition("top2");
+      BeanMetadata compDown = (BeanMetadata) cdr.getComponentDefinition("down2");
+      BeanMetadata compMiddle = (BeanMetadata) cdr.getComponentDefinition("middle2");
+      
+      assertNotNull(compTop);
+      assertNotNull(compDown);
+      assertNotNull(compMiddle);
       
       assertEquals("RequiresNew", txenhancer.getComponentMethodTxAttribute(compTop, "update1234"));
       assertEquals("Required", txenhancer.getComponentMethodTxAttribute(compTop, "update"));

Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries.xml?rev=980298&r1=980297&r2=980298&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries.xml
(original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries.xml
Thu Jul 29 03:02:21 2010
@@ -19,10 +19,10 @@
 -->
 <blueprint  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
             xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
-	<tx:transaction bean="top" method="*" value="Required"/>
-	<tx:transaction bean="down" method="*" value="Never"/>
+	<tx:transaction bean="top1" method="*" value="Required"/>
+	<tx:transaction bean="down1" method="*" value="Never"/>
 	
-	<bean id="top" class="org.apache.aries.transaction.TestBean"/>
+	<bean id="top1" class="org.apache.aries.transaction.TestBean"/>
 	
-	<bean id="down" class="org.apache.aries.transaction.TestBean2"/>
+	<bean id="down1" class="org.apache.aries.transaction.TestBean2"/>
 </blueprint>
\ No newline at end of file

Modified: incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries2.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries2.xml?rev=980298&r1=980297&r2=980298&view=diff
==============================================================================
--- incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries2.xml
(original)
+++ incubator/aries/trunk/transaction/transaction-blueprint/src/test/resources/org/apache/aries/transaction/bundlewide-aries2.xml
Thu Jul 29 03:02:21 2010
@@ -19,17 +19,17 @@
 -->
 <blueprint  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
             xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0">
-	<tx:transaction bean="top" method="*" value="NotSupported"/>
-	<tx:transaction bean="down" method="*" value="Required"/>
+	<tx:transaction bean="top2" method="*" value="NotSupported"/>
+	<tx:transaction bean="down2" method="*" value="Required"/>
 	
-	<bean id="top" class="org.apache.aries.transaction.TestBean">
+	<bean id="top2" class="org.apache.aries.transaction.TestBean">
 		<tx:transaction method="update*" value="Required"/>
 		<tx:transaction method="update123*" value="RequiresNew"/>
 	</bean>
 	
-    <bean id="down" class="org.apache.aries.transaction.TestBean2">
+    <bean id="down2" class="org.apache.aries.transaction.TestBean2">
 	    <tx:transaction method="update*" value="NotSupported"/>
 	</bean>
 	
-	<bean id="middle" class="org.apache.aries.transaction.TestBean3"/>
+	<bean id="middle2" class="org.apache.aries.transaction.TestBean3"/>
 </blueprint>
\ No newline at end of file



Mime
View raw message