You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2013/07/16 01:27:52 UTC

svn commit: r1503518 - in /cxf/branches/2.6.x-fixes: api/src/main/java/org/apache/cxf/BusFactory.java rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java

Author: dkulp
Date: Mon Jul 15 23:27:51 2013
New Revision: 1503518

URL: http://svn.apache.org/r1503518
Log:
Merged revisions 1503514 via  git cherry-pick from
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

........
  r1503514 | dkulp | 2013-07-15 19:14:22 -0400 (Mon, 15 Jul 2013) | 11 lines

  Merged revisions 1503509 via  git cherry-pick from
  https://svn.apache.org/repos/asf/cxf/trunk

  ........
    r1503509 | dkulp | 2013-07-15 18:50:49 -0400 (Mon, 15 Jul 2013) | 3 lines

    Fix problems with thread bus not being retrieved correctly
    Also cleanup bus's in the one test case.

  ........

........

Modified:
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java
    cxf/branches/2.6.x-fixes/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java?rev=1503518&r1=1503517&r2=1503518&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java (original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/BusFactory.java Mon Jul 15 23:27:51 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/branches/2.6.x-fixes/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java?rev=1503518&r1=1503517&r2=1503518&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java (original)
+++ cxf/branches/2.6.x-fixes/rt/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java Mon Jul 15 23:27:51 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;
@@ -35,12 +36,22 @@ import org.apache.cxf.transport.Destinat
 import org.apache.cxf.wsdl.WSDLManager;
 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 {
         
         CXFBusImpl bus = new ExtensionManagerBus();
@@ -49,6 +60,7 @@ public class CXFBusImplTest extends Asse
         assertNotNull(bus.getExtension(DestinationFactoryManager.class));
         assertNotNull(bus.getExtension(WSDLManager.class));
         assertNotNull(bus.getExtension(PhaseManager.class));
+        bus.shutdown(true);
     }
     
     @Test
@@ -88,6 +100,7 @@ public class CXFBusImplTest extends Asse
         String extension = "CXF";
         bus.setExtension(extension, String.class);
         assertSame(extension, bus.getExtension(String.class));
+        bus.shutdown(true);
     }
     
     @Test
@@ -97,6 +110,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
@@ -159,7 +173,7 @@ public class CXFBusImplTest extends Asse
         lifeCycleManager.registerLifeCycleListener(listener);
         bus.shutdown(true);
         EasyMock.verify(listener);
-        
+        bus.shutdown(true);        
     }
 
 }