river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter_firmst...@apache.org
Subject svn commit: r1552964 - in /river/jtsk/skunk/qa_refactor/trunk: qa/src/com/sun/jini/test/impl/thread/ qa/src/com/sun/jini/test/spec/discoveryservice/lease/ src/com/sun/jini/fiddler/ src/org/apache/river/api/net/
Date Sun, 22 Dec 2013 05:09:18 GMT
Author: peter_firmstone
Date: Sun Dec 22 05:09:18 2013
New Revision: 1552964

URL: http://svn.apache.org/r1552964
Log:
Fix LeaseExpiration test synchronization

Fix FiddlerImpl thread initialization

Fix race condition in WakeupManagerTaskExceptionTest after test failure was experienced.

Change logging in RFC3986URLClassLoader for parallel class loading to INFO.

Modified:
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/thread/WakeupManagerTaskExceptionTest.java
    river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/lease/LeaseExpiration.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerImpl.java
    river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerInit.java
    river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/thread/WakeupManagerTaskExceptionTest.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/thread/WakeupManagerTaskExceptionTest.java?rev=1552964&r1=1552963&r2=1552964&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/thread/WakeupManagerTaskExceptionTest.java
(original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/impl/thread/WakeupManagerTaskExceptionTest.java
Sun Dec 22 05:09:18 2013
@@ -46,15 +46,20 @@ public class WakeupManagerTaskExceptionT
         final boolean result[] = new boolean[]{false};
         manager.schedule(goodTaskTime, new Runnable() {
             public void run() {
-                result[0] = true;
+                // This happens in another thread
+                synchronized (result){
+                    result[0] = true;
+                }
             }
         });
         while (System.currentTimeMillis() < goodTaskTime + 10) {
             Thread.sleep((goodTaskTime+10)-System.currentTimeMillis());
         }
-        if (!result[0]) {
-            throw new TestException("A task that throws a runtime exception"
-                + " prevents other tasks from running");
+        synchronized (result){
+            if (!result[0]) {
+                throw new TestException("A task that throws a runtime exception"
+                    + " prevents other tasks from running");
+            }
         }
     }
 }

Modified: river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/lease/LeaseExpiration.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/lease/LeaseExpiration.java?rev=1552964&r1=1552963&r2=1552964&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/lease/LeaseExpiration.java
(original)
+++ river/jtsk/skunk/qa_refactor/trunk/qa/src/com/sun/jini/test/spec/discoveryservice/lease/LeaseExpiration.java
Sun Dec 22 05:09:18 2013
@@ -155,6 +155,7 @@ public class LeaseExpiration extends Abs
             }
             synchronized(eventLock) {
                 eventReceived = true;
+                eventLock.notifyAll();
             }
         }
     }//end class ServiceEventListener
@@ -190,7 +191,7 @@ public class LeaseExpiration extends Abs
     private static final long N_SECS = 30;
     private final long duration = N_SECS*1000;
     private MarshalledObject handback = null;
-    private volatile boolean eventReceived = false;
+    private boolean eventReceived = false;
     private final Object eventLock = new Object();
 
     /** Constructs and returns the duration values (in milliseconds) to 
@@ -301,24 +302,32 @@ public class LeaseExpiration extends Abs
         long nSecsWait = ( (nSecsLookupDiscovery > (actualDur/1000)) ?
                             nSecsLookupDiscovery : (actualDur/1000) );
         /* Give the event time to arrive */
-        int i = 0;
-        if(!eventReceived) {
-        for(i=1;i<nSecsWait;i++) {
-                DiscoveryServiceUtil.delayMS(1000);
-                if(eventReceived) break;
-            }
-        }//endif
-        if(eventReceived) {
-            logger.log(Level.FINE, 
-                              "first discovery event received after "
-                              +i+" second(s)");
-        } else {
-            throw new TestException(
-                             " -- waited "+i+" seconds, but no discovery "
-                             +"event received for the first lookup "
-                             +"service started");
-        }//endif
-
+        long startTime = System.currentTimeMillis();
+        long finishWait = nSecsWait * 1000;
+        long waitDuration = 0L;
+        synchronized (eventLock){
+            if(!eventReceived) {
+                while (waitDuration < finishWait) {
+                    try {
+                        eventLock.wait(1000);
+                        waitDuration = System.currentTimeMillis() - startTime;
+                        if(eventReceived) break;
+                    } catch (InterruptedException e){
+                        Thread.currentThread().interrupt();// restore
+                    }
+                }
+            }//endif
+            if(eventReceived) {
+                logger.log(Level.FINE, 
+                                  "first discovery event received after "
+                                  +waitDuration/1000+" second(s)");
+            } else {
+                throw new TestException(
+                                 " -- waited "+waitDuration/1000+" seconds, but no discovery
"
+                                 +"event received for the first lookup "
+                                 +"service started");
+            }//endif
+        }
         /* Start another lookup belonging to same group(s) as first */
         logger.log(Level.FINE, 
                           "starting a new lookup service");
@@ -338,22 +347,29 @@ public class LeaseExpiration extends Abs
                           "  lookup MemberGroup(s) = "
                           +GroupsUtil.toCommaSeparatedStr(memberGroups1));
         /* Give the event time to arrive */
-        i = 0;
-        if(!eventReceived) {
-        for(i=1;i<nSecsWait;i++) {
-                DiscoveryServiceUtil.delayMS(1000);
-                if(eventReceived) break;
-            }
-        }//endif
-        if(eventReceived) {
-            logger.log(Level.FINE, 
-               "second discovery event received after "+i+" second(s)");
-        } else {
-            throw new TestException(
-                             " -- waited "+i+" seconds, but no discovery "
-                             +"event received for the second lookup "
-                             +"service started");
-        }//endif
+        startTime = System.currentTimeMillis();
+        synchronized (eventLock){
+            if(!eventReceived) {
+                while (waitDuration < finishWait) {
+                    try {
+                        eventLock.wait(1000);
+                        waitDuration = System.currentTimeMillis() - startTime;
+                        if(eventReceived) break;
+                    } catch (InterruptedException e){
+                        Thread.currentThread().interrupt();// restore
+                    }
+                }
+            }//endif
+            if(eventReceived) {
+                logger.log(Level.FINE, 
+                   "second discovery event received after "+waitDuration/1000+" second(s)");
+            } else {
+                throw new TestException(
+                                 " -- waited "+waitDuration/1000+" seconds, but no discovery
"
+                                 +"event received for the second lookup "
+                                 +"service started");
+            }//endif
+        }
         /* Remove the lease from the renewal manager so it can expire */
         try {
             lrm.remove(lease);
@@ -369,7 +385,7 @@ public class LeaseExpiration extends Abs
         logger.log(Level.FINE, 
                               "waiting for lease expiration ...");
         boolean leaseExpired = false;
-        for(i=0;i<N_CYCLES_WAIT_EXPIRATION;i++) {
+        for(int i=0;i<N_CYCLES_WAIT_EXPIRATION;i++) {
             DiscoveryServiceUtil.delayMS(2*actualDur);
             /* Verify the lease has expired by trying to renew the lease */
             try {
@@ -409,22 +425,29 @@ public class LeaseExpiration extends Abs
                           "  lookup MemberGroup(s) = "
                           +GroupsUtil.toCommaSeparatedStr(memberGroups2));
         /* Give the event time to arrive */
-        i = 0;
-        if(!eventReceived) {
-        for(i=1;i<nSecsWait;i++) {
-                DiscoveryServiceUtil.delayMS(1000);
-                if(eventReceived) break;
-            }
-        }//endif
-        if(eventReceived) {
-            throw new TestException(
-                                 " -- last discovery event received after "
-                                 +i+" second(s)");
-        } else {
-            logger.log(Level.FINE, 
-                           "no events received after "+i+" second(s)");
+        startTime = System.currentTimeMillis();
+        synchronized (eventLock){
+            if(!eventReceived) {
+                while (waitDuration < finishWait) {
+                    try {
+                        eventLock.wait(1000);
+                        waitDuration = System.currentTimeMillis() - startTime;
+                        if (eventReceived) break;
+                    } catch (InterruptedException e){
+                        Thread.currentThread().interrupt();// restore
+                    }
+                }
+            }//endif
+            if(eventReceived) {
+                throw new TestException(
+                                     " -- last discovery event received after "
+                                     +waitDuration/1000+" second(s)");
+            } else {
+                logger.log(Level.FINE, 
+                               "no events received after "+waitDuration/1000+" second(s)");
 
-        }//endif
+            }//endif
+        }
     }//end run
 
 } //end class LeaseExpiration

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerImpl.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerImpl.java?rev=1552964&r1=1552963&r2=1552964&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerImpl.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerImpl.java Sun Dec 22
05:09:18 2013
@@ -115,6 +115,7 @@ import java.rmi.RemoteException;
 import java.rmi.server.ExportException;
 import java.security.AccessControlContext;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 
 import java.security.PrivilegedExceptionAction;
@@ -499,8 +500,6 @@ class FiddlerImpl implements ServerProxy
         taskMgr = i.taskMgr;
         activationSystem = i.activationSystem;
         serverExporter = i.serverExporter;
-        leaseExpireThread = i.leaseExpireThread;
-        snapshotThread = i.snapshotThread;
         logHandler = i.logHandler;
         activationID = i.activationID;
         // These three fields are used by the Starter.start() implementation.
@@ -508,6 +507,26 @@ class FiddlerImpl implements ServerProxy
         config = i.config;
         context = i.context;
         loginContext = i.loginContext;
+        leaseExpireThread = AccessController.doPrivileged(
+            new PrivilegedAction<LeaseExpireThread>(){
+                @Override
+                public LeaseExpireThread run() {
+                    return new LeaseExpireThread(FiddlerImpl.this);
+                }
+                    
+            }, context);
+        if (log != null){
+            snapshotThread = AccessController.doPrivileged(
+                new PrivilegedAction<SnapshotThread>(){
+                    @Override
+                    public SnapshotThread run() {
+                        return new SnapshotThread(FiddlerImpl.this);
+                    }
+
+                }, context);
+        } else {
+            snapshotThread = null;
+        }
     }
     /* ************************** END Constructors ************************* */
 
@@ -575,7 +594,7 @@ class FiddlerImpl implements ServerProxy
          *  currently discovered lookup service(s).
          *  @serial
          */
-        public HashMap discoveredRegsMap;
+        public final HashMap discoveredRegsMap;
         /** The managed set containing the names of the groups whose
          *  members are the lookup services the lookup discovery service
          *  should attempt to discover for the current registration.
@@ -2262,24 +2281,15 @@ class FiddlerImpl implements ServerProxy
      */
     static class LeaseExpireThread extends InterruptedStatusThread {
 
-        private FiddlerImpl fiddler;
+        private final FiddlerImpl fiddler;
         /** Create a daemon thread */
         public LeaseExpireThread(FiddlerImpl fiddler) {
             super("lease expire");
             setDaemon(true);
             this.fiddler = fiddler;
         }//end constructor
-        
-        /**
-         * This can only be called prior to the thread starting, otherwise it
-         * blocks until the thread finishes executing.
-         * @param fiddler 
-         */
-        synchronized void setFiddler(FiddlerImpl fiddler){
-            this.fiddler = fiddler;
-        }
 
-        public synchronized void run() {
+        public void run() {
             try {
                 fiddler.concurrentObj.writeLock();
             } catch (ConcurrentLockException e) {
@@ -2402,25 +2412,16 @@ class FiddlerImpl implements ServerProxy
      * be treated as a reader process.
      */
     static class SnapshotThread extends InterruptedStatusThread {
-        private FiddlerImpl fiddler;
+        private final FiddlerImpl fiddler;
         
         /** Create a daemon thread */
-        public SnapshotThread() {
+        public SnapshotThread(FiddlerImpl fiddler) {
             super("snapshot thread");
             setDaemon(true);
-        }
-        
-        /**
-         * Due to synchronization this can only be set prior to this thread
-         * starting.
-         * 
-         * @param fiddler 
-         */
-        synchronized void setFiddler(FiddlerImpl fiddler){
             this.fiddler = fiddler;
         }
 
-        public synchronized void run() {
+        public void run() {
             try {
                 fiddler.concurrentObj.readLock();
             } catch (ConcurrentLockException e) {
@@ -5337,7 +5338,6 @@ class FiddlerImpl implements ServerProxy
                 /* start up all the daemon threads */
                 leaseExpireThread.start();
                 if(log != null) {
-                    snapshotThread.setFiddler(FiddlerImpl.this);
                     snapshotThread.start();
                 }
                 logInfoStartup();

Modified: river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerInit.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerInit.java?rev=1552964&r1=1552963&r2=1552964&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerInit.java (original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/com/sun/jini/fiddler/FiddlerInit.java Sun Dec 22
05:09:18 2013
@@ -73,8 +73,6 @@ class FiddlerInit {
     TaskManager taskMgr;
     ActivationSystem activationSystem;
     Exporter serverExporter;
-    LeaseExpireThread leaseExpireThread;
-    SnapshotThread snapshotThread;
     LocalLogHandler logHandler;
     ActivationID activationID = null;
     // These three fields are used by the Starter.start() implementation.
@@ -281,13 +279,6 @@ class FiddlerInit {
                                           +"retrieving service's exporter",
                                           e);
             }
-
-            /* Create the following threads here, after a possible JAAS login,
-             * rather than in the constructor, before the login. This must
-             * be done so that the threads will have the correct subject.
-             */
-            leaseExpireThread = new FiddlerImpl.LeaseExpireThread(null);
-            if(log != null) snapshotThread = new FiddlerImpl.SnapshotThread();
         } catch(Throwable e) {
             cleanupInitFailure();
             handleActivatableInitThrowable(e);

Modified: river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java
URL: http://svn.apache.org/viewvc/river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java?rev=1552964&r1=1552963&r2=1552964&view=diff
==============================================================================
--- river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java
(original)
+++ river/jtsk/skunk/qa_refactor/trunk/src/org/apache/river/api/net/RFC3986URLClassLoader.java
Sun Dec 22 05:09:18 2013
@@ -122,11 +122,11 @@ public class RFC3986URLClassLoader exten
         } catch (SecurityException ex) {
             logger.log(Level.INFO, "Insufficient permission to enable parallel class loading,
disabled", ex);
         } catch (IllegalAccessException ex) {
-            logger.log(Level.SEVERE, "Unable to invoke parallel class loading", ex);
+            logger.log(Level.INFO, "Unable to invoke parallel class loading", ex);
         } catch (IllegalArgumentException ex) {
-            logger.log(Level.SEVERE, "Unable to invoke parallel class loading", ex);
+            logger.log(Level.INFO, "Unable to invoke parallel class loading", ex);
         } catch (InvocationTargetException ex) {
-            logger.log(Level.SEVERE, "Unable to invoke parallel class loading", ex);
+            logger.log(Level.INFO, "Unable to invoke parallel class loading", ex);
         }
         String codebaseAnnotationProperty = null;
 	String prop = AccessController.doPrivileged(



Mime
View raw message