[dna-commits] DNA SVN: r520 - in trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation: contribution and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Tue Sep 16 12:39:31 EDT 2008


Author: rhauch
Date: 2008-09-16 12:39:31 -0400 (Tue, 16 Sep 2008)
New Revision: 520

Modified:
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
Log:
DNA-224 - dna-connector-federation: one test in FederatingCommandExecutorTest doesn't work with JDK 1.6.0_05 on Mac OS X
http://jira.jboss.com/jira/browse/DNA-224

The problem appeared because of a modified implementation of a Set, which resulted in a different order to some of the top-level nodes in a Projection.  This in fact was a bug where the top-level nodes of a projection were not ordered.  This was fixed by making them ordered, keeping the same order as the projection's rules.

All tests now pass on JDK 1.5 and JDK 1.6.

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java	2008-09-16 15:38:12 UTC (rev 519)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java	2008-09-16 16:39:31 UTC (rev 520)
@@ -322,13 +322,20 @@
      * Get the paths in the repository that serve as top-level nodes exposed by this projection.
      * 
      * @param factory the path factory that can be used to create new paths; may not be null
-     * @return the set of top-level paths; never null
+     * @return the list of top-level paths, in the proper order and containing no duplicates; never null
      */
-    public Set<Path> getTopLevelPathsInRepository( PathFactory factory ) {
+    public List<Path> getTopLevelPathsInRepository( PathFactory factory ) {
         ArgCheck.isNotNull(factory, "factory");
-        Set<Path> paths = new HashSet<Path>();
+        List<Rule> rules = getRules();
+        Set<Path> uniquePaths = new HashSet<Path>();
+        List<Path> paths = new ArrayList<Path>(rules.size());
         for (Rule rule : getRules()) {
-            paths.addAll(rule.getTopLevelPathsInRepository(factory));
+            for (Path path : rule.getTopLevelPathsInRepository(factory)) {
+                if (!uniquePaths.contains(path)) {
+                    paths.add(path);
+                    uniquePaths.add(path);
+                }
+            }
         }
         return paths;
     }
@@ -450,9 +457,9 @@
          * Get the paths in the repository that serve as top-level nodes exposed by this rule.
          * 
          * @param factory the path factory that can be used to create new paths; may not be null
-         * @return the set of top-level paths; never null
+         * @return the list of top-level paths, which are ordered and which must be unique; never null
          */
-        public abstract Set<Path> getTopLevelPathsInRepository( PathFactory factory );
+        public abstract List<Path> getTopLevelPathsInRepository( PathFactory factory );
 
         /**
          * Get the path in source that is projected from the supplied repository path, or null if the supplied repository path is
@@ -500,6 +507,7 @@
         /** The paths (relative to the source path) that identify exceptions to this rule */
         private final List<Path> exceptions;
         private final int hc;
+        private final List<Path> topLevelRepositoryPaths;
 
         public PathRule( Path repositoryPath,
                          Path sourcePath ) {
@@ -524,6 +532,7 @@
             }
             this.hc = HashCode.compute(sourcePath, repositoryPath, exceptions);
             assert exceptionPathsAreRelative();
+            this.topLevelRepositoryPaths = Collections.singletonList(getPathInRepository());
         }
 
         public PathRule( Path repositoryPath,
@@ -540,6 +549,7 @@
             }
             this.hc = HashCode.compute(sourcePath, repositoryPath, exceptions);
             assert exceptionPathsAreRelative();
+            this.topLevelRepositoryPaths = Collections.singletonList(getPathInRepository());
         }
 
         private boolean exceptionPathsAreRelative() {
@@ -617,8 +627,8 @@
          * @see org.jboss.dna.connector.federation.Projection.Rule#getTopLevelPathsInRepository(org.jboss.dna.spi.graph.PathFactory)
          */
         @Override
-        public Set<Path> getTopLevelPathsInRepository( PathFactory factory ) {
-            return Collections.singleton(getPathInRepository());
+        public List<Path> getTopLevelPathsInRepository( PathFactory factory ) {
+            return topLevelRepositoryPaths;
         }
 
         /**

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java	2008-09-16 15:38:12 UTC (rev 519)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/contribution/Contribution.java	2008-09-16 16:39:31 UTC (rev 520)
@@ -24,6 +24,7 @@
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.NoSuchElementException;
 import net.jcip.annotations.Immutable;
 import org.jboss.dna.common.util.StringUtil;
@@ -141,7 +142,7 @@
                                        Path pathInSource,
                                        DateTime expirationTime,
                                        Collection<Property> properties,
-                                       Collection<Segment> children ) {
+                                       List<Segment> children ) {
         if (properties == null || properties.isEmpty()) {
             // There are no properties ...
             if (children == null || children.isEmpty()) {

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java	2008-09-16 15:38:12 UTC (rev 519)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java	2008-09-16 16:39:31 UTC (rev 520)
@@ -442,7 +442,7 @@
                     // We do this by getting the top-level repository paths of the projection, and then
                     // use those to figure out the children of the nodes.
                     Contribution contribution = null;
-                    Set<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
+                    List<Path> topLevelPaths = projection.getTopLevelPathsInRepository(pathFactory);
                     switch (topLevelPaths.size()) {
                         case 0:
                             break;
@@ -456,7 +456,8 @@
                             break;
                         }
                         default: {
-                            Set<Path.Segment> children = new HashSet<Path.Segment>();
+                            // We assume that the top-level paths do not overlap ...
+                            List<Path.Segment> children = new ArrayList<Path.Segment>(topLevelPaths.size());
                             for (Path topLevelPath : topLevelPaths) {
                                 if (path.isAncestorOf(topLevelPath)) {
                                     assert topLevelPath.size() > path.size();
@@ -482,7 +483,7 @@
                         sourceConnection.execute(getExecutionContext(), fromSource);
                         if (!fromSource.hasError()) {
                             Collection<Property> properties = fromSource.getProperties();
-                            Collection<Segment> children = fromSource.getChildren();
+                            List<Segment> children = fromSource.getChildren();
                             DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
                                                                                                                                  TimeUnit.MILLISECONDS);
                             Contribution contribution = Contribution.create(source, pathInSource, expTime, properties, children);
@@ -498,7 +499,7 @@
                         for (BasicGetNodeCommand fromSource : fromSourceCommands) {
                             if (fromSource.hasError()) continue;
                             Collection<Property> properties = fromSource.getProperties();
-                            Collection<Segment> children = fromSource.getChildren();
+                            List<Segment> children = fromSource.getChildren();
                             DateTime expTime = fromSource.getCachePolicy() == null ? expirationTime : getCurrentTimeInUtc().plus(fromSource.getCachePolicy().getTimeToLive(),
                                                                                                                                  TimeUnit.MILLISECONDS);
                             Contribution contribution = Contribution.create(source,




More information about the dna-commits mailing list