cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1503509 - in /cxf/trunk: api/src/main/java/org/apache/cxf/BusFactory.java rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
Date Mon, 15 Jul 2013 22:50:49 GMT
Author: dkulp
Date: Mon Jul 15 22:50:49 2013
New Revision: 1503509

URL: http://svn.apache.org/r1503509
Log:
Fix problems with thread bus not being retrieved correctly
Also cleanup bus's in the one test case.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java?rev=1503509&r1=1503508&r2=1503509&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/BusFactory.java Mon Jul 15 22:50:49 2013
@@ -228,8 +228,14 @@ public abstract class BusFactory {
             }
             return b.bus;
         }
-        BusHolder b = threadBus.get();
-        return b == null ? null : b.bus;
+        BusHolder h = threadBus.get();
+        if (h == null || h.stale) {
+            Thread cur = Thread.currentThread();
+            synchronized (threadBusses) {
+                h = threadBusses.get(cur);
+            }
+        }
+        return h == null || h.stale ? null : h.bus;
     }
     private static synchronized Bus createThreadBus() {
         BusHolder b = getThreadBusHolder(false);

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java?rev=1503509&r1=1503508&r2=1503509&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java (original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java Mon Jul 15 22:50:49
2013
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
+import org.apache.cxf.BusFactory;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
 import org.apache.cxf.buslifecycle.BusLifeCycleListener;
@@ -34,12 +35,22 @@ import org.apache.cxf.transport.ConduitI
 import org.apache.cxf.transport.DestinationFactoryManager;
 import org.easymock.EasyMock;
 import org.easymock.IMocksControl;
+
 import org.junit.Assert;
 import org.junit.Test;
 
 public class CXFBusImplTest extends Assert {
 
     @Test
+    public void testThreadBus() throws BusException {
+        BusFactory.setDefaultBus(null);
+        BusFactory.setThreadDefaultBus(null);
+        Bus bus = BusFactory.newInstance().createBus();
+        Bus b2 = BusFactory.getThreadDefaultBus(false);
+        assertSame(bus, b2);
+        bus.shutdown(true);
+    }
+    @Test
     public void testConstructionWithoutExtensions() throws BusException {
         
         Bus bus = new ExtensionManagerBus();
@@ -47,6 +58,7 @@ public class CXFBusImplTest extends Asse
         assertNotNull(bus.getExtension(ConduitInitiatorManager.class));   
         assertNotNull(bus.getExtension(DestinationFactoryManager.class));
         assertNotNull(bus.getExtension(PhaseManager.class));
+        bus.shutdown(true);
     }
     
     @Test
@@ -82,6 +94,7 @@ public class CXFBusImplTest extends Asse
         String extension = "CXF";
         bus.setExtension(extension, String.class);
         assertSame(extension, bus.getExtension(String.class));
+        bus.shutdown(true);
     }
     
     @Test
@@ -91,6 +104,7 @@ public class CXFBusImplTest extends Asse
         assertEquals("The bus id should be cxf", id, Bus.DEFAULT_BUS_ID + Math.abs(bus.hashCode()));
         bus.setId("test");
         assertEquals("The bus id should be changed", "test", bus.getId());
+        bus.shutdown(true);
     }
     
     @Test
@@ -107,7 +121,7 @@ public class CXFBusImplTest extends Asse
         lifeCycleManager.registerLifeCycleListener(listener);
         bus.shutdown(true);
         EasyMock.verify(listener);
-        
+        bus.shutdown(true);        
     }
 
 }



Mime
View raw message