Author: mcombellack
Date: Mon Apr 14 02:39:57 2008
New Revision: 647714
URL: http://svn.apache.org/viewvc?rev=647714&view=rev
Log:
TUSCANY-2192 - Fixed issue where the unit test would still sometimes fail
because the access to OneWayServiceImpl.callCount was not Thread safe
Modified:
incubator/tuscany/java/sca/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java
incubator/tuscany/java/sca/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java
Modified:
incubator/tuscany/java/sca/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java?rev=647714&r1=647713&r2=647714&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java
(original)
+++
incubator/tuscany/java/sca/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java
Mon Apr 14 02:39:57 2008
@@ -20,6 +20,8 @@
import org.apache.tuscany.sca.itest.oneway.OneWayService;
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
+
/**
* The service for the oneway itest
*
@@ -28,15 +30,14 @@
public class OneWayServiceImpl implements OneWayService {
-
- public static int callCount = 0;
-
+ /**
+ * Counts the number of invocations to doSomething()
+ */
+ public static final AtomicInteger callCount = new AtomicInteger();
+
public void doSomething(int count){
-
- synchronized(this){
- callCount++;
- }
-
+ callCount.incrementAndGet();
+
// System.out.println("Service: doSomething " + count + " callCount = "
+ callCount);
// System.out.flush();
Modified:
incubator/tuscany/java/sca/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java
URL:
http://svn.apache.org/viewvc/incubator/tuscany/java/sca/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java?rev=647714&r1=647713&r2=647714&view=diff
==============================================================================
---
incubator/tuscany/java/sca/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java
(original)
+++
incubator/tuscany/java/sca/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java
Mon Apr 14 02:39:57 2008
@@ -77,7 +77,7 @@
// This loop will wait for the required number of @OneWay
method calls to
// have taken place or MAX_SLEEP_TIME to have passed.
long startSleep = System.currentTimeMillis();
- while (OneWayClientImpl.callCount !=
OneWayServiceImpl.callCount
+ while (OneWayClientImpl.callCount !=
OneWayServiceImpl.callCount.get()
&& System.currentTimeMillis() - startSleep <
MAX_SLEEP_TIME) {
Thread.sleep(100);
// System.out.println("" + OneWayClientImpl.callCount +
"," + OneWayServiceImpl.callCount);
@@ -85,7 +85,7 @@
System.out.println("Finished callCount = " +
OneWayServiceImpl.callCount);
- Assert.assertEquals(OneWayClientImpl.callCount,
OneWayServiceImpl.callCount);
+ Assert.assertEquals(OneWayClientImpl.callCount,
OneWayServiceImpl.callCount.get());
}
} catch (Exception ex) {
System.err.println("Exception: " + ex.toString());
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]