ace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1574924 - in /ace/trunk: org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/ org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/
Date Thu, 06 Mar 2014 15:36:45 GMT
Author: jawi
Date: Thu Mar  6 15:36:45 2014
New Revision: 1574924

URL: http://svn.apache.org/r1574924
Log:
ACE-409 - specify a refresh cause:

- when a refresh event is sent by the RepositoryAdmin, add a cause property to 
  the event to be able to make distinction in refresh events.


Modified:
    ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java
    ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java

Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java?rev=1574924&r1=1574923&r2=1574924&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/BaseRepositoryAdminTest.java
Thu Mar  6 15:36:45 2014
@@ -26,6 +26,7 @@ import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.HashMap;
 import java.util.Hashtable;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.Callable;
@@ -344,6 +345,10 @@ public abstract class BaseRepositoryAdmi
     }
 
     protected <T> T runAndWaitForEvent(Callable<T> callable, final boolean debug,
final String... topicList) throws Exception {
+        return runAndWaitForEvent(callable, debug, null, topicList);
+    }
+    
+    protected <T> T runAndWaitForEvent(Callable<T> callable, final boolean debug,
final List<Event> events, final String... topicList) throws Exception {
         Dictionary<String, Object> topics = new Hashtable<String, Object>();
         topics.put(EventConstants.EVENT_TOPIC, topicList);
 
@@ -360,6 +365,9 @@ public abstract class BaseRepositoryAdmi
                         System.err.println("Received event: " + event.getTopic());
                     }
                     if (waitingForTopic.remove(event.getTopic())) {
+                        if (events != null) {
+                            events.add(event);
+                        }
                         if (debug) {
                             System.err.println("Event was expected.");
                         }

Modified: ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java?rev=1574924&r1=1574923&r2=1574924&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
(original)
+++ ace/trunk/org.apache.ace.client.repository.itest/src/org/apache/ace/it/repositoryadmin/RepositoryAdminTest.java
Thu Mar  6 15:36:45 2014
@@ -26,7 +26,9 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Callable;
 import java.util.jar.Attributes;
@@ -48,6 +50,7 @@ import org.apache.ace.client.repository.
 import org.apache.ace.client.repository.stateful.StatefulTargetObject;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.event.Event;
 import org.osgi.service.useradmin.User;
 
 public class RepositoryAdminTest extends BaseRepositoryAdminTest {
@@ -189,14 +192,16 @@ public class RepositoryAdminTest extends
 
         sgo.approve();
 
+        List<Event> events = new ArrayList<Event>();
         runAndWaitForEvent(new Callable<Void>() {
             public Void call() throws Exception {
                 m_repositoryAdmin.commit();
                 return null;
             }
-        }, false, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED);
+        }, false, events, DeploymentVersionObject.TOPIC_ADDED, TOPIC_STATUS_CHANGED, RepositoryAdmin.TOPIC_REFRESH);
 
         assertFalse("We approved the new version by hand, so we should not need approval.",
sgo.needsApprove());
+        assertContainsRefreshCause(events, "commit");
 
         runAndWaitForEvent(new Callable<Object>() {
             public Object call() throws Exception {
@@ -481,15 +486,17 @@ public class RepositoryAdminTest extends
             // expected
         }
 
+        List<Event> events = new ArrayList<Event>();
         runAndWaitForEvent(new Callable<Object>() {
             public Object call() throws Exception {
                 m_repositoryAdmin.checkout();
                 return null;
             }
-        }, false, RepositoryAdmin.TOPIC_REFRESH);
+        }, false, events, RepositoryAdmin.TOPIC_REFRESH);
 
         assertTrue("After initial checkout, the repository is current.", m_repositoryAdmin.isCurrent());
         assertFalse("Immediately after login, the repository cannot be modified.", m_repositoryAdmin.isModified());
+        assertContainsRefreshCause(events, "checkout");
 
         ArtifactObject b1 = runAndWaitForEvent(new Callable<ArtifactObject>() {
             public ArtifactObject call() throws Exception {
@@ -619,13 +626,26 @@ public class RepositoryAdminTest extends
 
         assertEquals("We expect 2 items in the bundle repository;", 2, m_artifactRepository.get().size());
 
+        events.clear();
         runAndWaitForEvent(new Callable<Object>() {
             public Object call() throws Exception {
                 m_repositoryAdmin.revert();
                 return null;
             }
-        }, false, RepositoryAdmin.TOPIC_REFRESH, RepositoryAdmin.TOPIC_STATUSCHANGED);
+        }, false, events, RepositoryAdmin.TOPIC_STATUSCHANGED, RepositoryAdmin.TOPIC_REFRESH);
 
         assertEquals("We expect 1 item in the bundle repository;", 1, m_artifactRepository.get().size());
+        assertContainsRefreshCause(events, "revert");
+    }
+
+    private void assertContainsRefreshCause(List<Event> events, String cause) {
+        boolean found = false;
+        for (Event event : events) {
+            if (RepositoryAdmin.TOPIC_REFRESH.equals(event.getTopic())) {
+                assertEquals("Refresh property does not have the correct cause property?!",
event.getProperty("cause"), cause);
+                found = true;
+            }
+        }
+        assertTrue("Events did not contain expected refresh event!", found);
     }
 }

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java?rev=1574924&r1=1574923&r2=1574924&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/ObjectRepositoryImpl.java
Thu Mar  6 15:36:45 2014
@@ -20,7 +20,6 @@ package org.apache.ace.client.repository
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java?rev=1574924&r1=1574923&r2=1574924&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
(original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryAdminImpl.java
Thu Mar  6 15:36:45 2014
@@ -84,6 +84,11 @@ public class RepositoryAdminImpl impleme
     private final static String PREFS_LOCAL_FILE_LOCATION = "FileLocation";
     private final static String PREFS_LOCAL_FILE_CURRENT = "current";
     private final static String PREFS_LOCAL_FILE_BACKUP = "backup";
+    
+    private static final String KEY_CAUSE = "cause";
+    private static final String CAUSE_COMMIT = "commit";
+    private static final String CAUSE_REVERT = "revert";
+    private static final String CAUSE_CHECKOUT = "checkout";
 
     /**
      * Maps from interface classes of the ObjectRepositories to their implementations.
@@ -282,7 +287,10 @@ public class RepositoryAdminImpl impleme
             for (RepositorySet set : m_repositorySets) {
                 set.checkout();
             }
-            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, null);
+
+            Properties props = new Properties();
+            props.put(KEY_CAUSE, CAUSE_CHECKOUT);
+            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, props);
         }
     }
 
@@ -295,7 +303,10 @@ public class RepositoryAdminImpl impleme
             for (RepositorySet set : m_repositorySets) {
                 set.commit();
             }
-            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, null);
+
+            Properties props = new Properties();
+            props.put(KEY_CAUSE, CAUSE_COMMIT);
+            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, props);
         }
     }
 
@@ -320,7 +331,10 @@ public class RepositoryAdminImpl impleme
             for (RepositorySet set : m_repositorySets) {
                 set.revert();
             }
-            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, null);
+            
+            Properties props = new Properties();
+            props.put(KEY_CAUSE, CAUSE_REVERT);
+            m_changeNotifier.notifyChanged(TOPIC_REFRESH_SUFFIX, props);
         }
     }
 



Mime
View raw message