harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r489069 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/Timer.java test/api/java/common/javax/swing/Timer_MultithreadedTest.java
Date Wed, 20 Dec 2006 12:43:25 GMT
Author: apetrenko
Date: Wed Dec 20 04:43:24 2006
New Revision: 489069

URL: http://svn.apache.org/viewvc?view=rev&rev=489069
Log:
Patch for HARMONY-2438 "[classlib][swing] intermittent failures of swing module tests, once
mode"

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Timer.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/Timer_MultithreadedTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Timer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Timer.java?view=diff&rev=489069&r1=489068&r2=489069
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Timer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/Timer.java
Wed Dec 20 04:43:24 2006
@@ -14,10 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Alexander T. Simbirtsev
- * @version $Revision$
- */
 package javax.swing;
 
 import java.awt.event.ActionEvent;
@@ -27,22 +23,32 @@
 
 import javax.swing.event.EventListenerList;
 
+/**
+ * <p>
+ * <i>Timer</i>
+ * </p>
+ * <h3>Implementation Notes:</h3>
+ * <ul>
+ * <li>The <code>serialVersionUID</code> fields are explicitly declared
as a performance
+ * optimization, not as a guarantee of serialization compatibility.</li>
+ * </ul>
+ */
 public class Timer implements Serializable {
 
     private class FiringEventRunnable implements Runnable {
         private ActionEvent event;
         private int queuedCounter;
 
-        public void preQueueInit(final long scheduledTime) {
+        public synchronized void preQueueInit(final long scheduledTime) {
             queuedCounter++;
             event = new ActionEvent(Timer.this, 0, null, scheduledTime, 0);
         }
 
-        public boolean isQueued() {
+        public synchronized boolean isQueued() {
             return queuedCounter > 0;
         }
         
-        public void run() {
+        public synchronized void run() {
             if (getLogTimers()) {
                 System.out.println("Timer ringing: " + Timer.this);
             }
@@ -66,6 +72,8 @@
     private boolean isCoalesce = true;
     private TimerTask timerTask;
 
+    private static final long serialVersionUID = 3624204224649954546L;
+
     /**
      * this thread is used to execute all timers
      */
@@ -188,6 +196,7 @@
         return new TimerTask() {
             private final FiringEventRunnable fireEvent = new FiringEventRunnable();
             
+            @Override
             public void run() {
                 if (!isCoalesce || !fireEvent.isQueued()) {
                     fireEvent.preQueueInit(scheduledExecutionTime());

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/Timer_MultithreadedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/Timer_MultithreadedTest.java?view=diff&rev=489069&r1=489068&r2=489069
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/Timer_MultithreadedTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/Timer_MultithreadedTest.java
Wed Dec 20 04:43:24 2006
@@ -14,11 +14,6 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-/**
- * @author Alexander T. Simbirtsev
- * @version $Revision$
- *
- */
 package javax.swing;
 
 import java.awt.event.ActionEvent;
@@ -26,11 +21,11 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.PrintStream;
+
 import junit.framework.TestCase;
 
 public class Timer_MultithreadedTest extends TestCase {
     private Timer timer;
-
     static class ConcreteActionListener implements ActionListener {
         class Delay {
             private boolean wasStopped;
@@ -171,6 +166,7 @@
         listener1.waitNumActions(500, 5);
         assertTrue("ActionListener's ActionPerformed invoked ", listener1.action != null);
         timer.stop();
+
         // checking does setRepeats actually affects the work of timer
         ConcreteActionListener listener2 = new ConcreteActionListener("2");
         timer = new Timer(10, listener2);
@@ -187,6 +183,7 @@
         listener2.waitAction(100);
         assertNull("ActionListener's ActionPerformed didn't invoke ", listener2.action);
         timer.stop();
+
         ConcreteActionListener listener3 = new ConcreteActionListener("3");
         timer = new Timer(100, listener3);
         timer.setRepeats(false);
@@ -198,6 +195,7 @@
         listener3.waitAction(1500);
         assertNotNull("ActionListener's ActionPerformed did invoke ", listener3.action);
         timer.stop();
+
         ConcreteActionListener listener4 = new ConcreteActionListener("4");
         timer = new Timer(100, listener4);
         timer.setRepeats(false);
@@ -219,6 +217,7 @@
         assertEquals("Initial delay is ", 100, timer.getInitialDelay());
         timer.setInitialDelay(300);
         assertEquals("Initial delay is ", 300, timer.getInitialDelay());
+
         // checking does SetInitialDelay actually affects the work of timer
         ConcreteActionListener listener2 = new ConcreteActionListener("2");
         timer = new Timer(10, listener2);
@@ -230,6 +229,7 @@
         listener2.waitAction(1000);
         assertTrue("ActionListener's ActionPerformed invoked ", listener2.action != null);
         timer.stop();
+
         timer = new Timer(10, listener2);
         timer.setInitialDelay(200);
         timer.start();
@@ -245,6 +245,7 @@
         assertEquals("delay is ", 100, timer.getDelay());
         timer.setDelay(300);
         assertEquals("delay is ", 300, timer.getDelay());
+
         // checking does SetDelay affects working timer
         listener = new ConcreteActionListener();
         timer = new Timer(4000, listener);
@@ -254,6 +255,7 @@
         listener.waitAction(200);
         assertNull("ActionListener's ActionPerformed didn't invoke ", listener.action);
         timer.stop();
+
         listener = new ConcreteActionListener();
         timer = new Timer(150, listener);
         timer.start();
@@ -277,11 +279,17 @@
         listener.reset();
         listener.waitAction(100);
         assertFalse("timer is not running ", timer.isRunning());
+
         timer.setRepeats(false);
         timer.setDelay(100);
+        listener.reset();
         timer.start();
         assertTrue("timer is running ", timer.isRunning());
         listener.waitAction(1500);
+        assertTrue("timer hasn't rung", listener.performed);
+        listener.reset();
+        listener.waitAction(100);
+        assertFalse("timer must not ring", listener.performed);
         assertFalse("timer is running ", timer.isRunning());
     }
 
@@ -313,6 +321,7 @@
         timer.start();
         listener.waitAction(500);
         assertNull("ActionListener's ActionPerformed didn't invoke ", listener.action);
+
         // testing the right order of timers being triggered
         ConcreteActionListener listener1 = new ConcreteActionListener("1");
         ConcreteActionListener listener2 = new ConcreteActionListener("2");
@@ -372,13 +381,9 @@
     public void testSetLogTimers() {
         class LogOutputStream extends OutputStream {
             public boolean written = false;
-            public boolean log_allowed = false;
 
             @Override
             public void write(int b) throws IOException {
-                //if we fail we know who is logging by stack trace
-                assertTrue("log must not be written", log_allowed);
-
                 written = true;
             }
         }
@@ -390,16 +395,16 @@
         try {
             Timer.setLogTimers(false);
             ConcreteActionListener listener = new ConcreteActionListener();
-            Timer timer = new Timer(10, listener);
+            timer = new Timer(10, listener);
             timer.start();
             assertFalse("[1] doesn't log timers", Timer.getLogTimers());
             listener.waitAction(250);
             assertTrue("[1] action performed ", listener.performed);
+            assertFalse("[1] log's not written", logOut.written);
             timer.stop();
             listener.reset();
 
             Timer.setLogTimers(true);
-            logOut.log_allowed = true;
             timer.start();
             listener.waitAction(250);
             assertTrue("[2] logs timers ", Timer.getLogTimers());
@@ -411,11 +416,11 @@
 
             Timer.setLogTimers(false);
             logOut.written = false;
-            logOut.log_allowed = false;
             timer.start();
             listener.waitAction(50);
             assertFalse("[3] doesn't log timers ", Timer.getLogTimers());
             assertTrue("[3] action performed", listener.performed);
+            assertFalse("[3] log's not written", logOut.written);
         } finally {
             System.setOut(oldOut);
             Timer.setLogTimers(false);



Mime
View raw message