sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From romb...@apache.org
Subject svn commit: r1706100 - in /sling/trunk/tooling/ide: api/src/org/apache/sling/ide/transport/ api/src/org/apache/sling/ide/transport/impl/ impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/ impl-vlt/src/org/apache/sling/ide/impl/vlt/
Date Wed, 30 Sep 2015 17:56:31 GMT
Author: rombert
Date: Wed Sep 30 17:56:30 2015
New Revision: 1706100

URL: http://svn.apache.org/viewvc?rev=1706100&view=rev
Log:
SLING-4438 - Don't execute duplicate or out-of-order commands 

Add batching for child reorder commands

Modified:
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/Command.java
    sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/impl/DefaultBatcher.java
    sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/VltBatcherTest.java
    sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/ReorderChildNodesCommand.java

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/Command.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/Command.java?rev=1706100&r1=1706099&r2=1706100&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/Command.java (original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/Command.java Wed Sep 30
17:56:30 2015
@@ -27,7 +27,7 @@ public interface Command<T> {
      *
      */
     enum Kind {
-        DELETE, ADD_OR_UPDATE
+        DELETE, ADD_OR_UPDATE, REORDER_CHILDREN;
     }
 
 	Result<T> execute();

Modified: sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/impl/DefaultBatcher.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/impl/DefaultBatcher.java?rev=1706100&r1=1706099&r2=1706100&view=diff
==============================================================================
--- sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/impl/DefaultBatcher.java
(original)
+++ sling/trunk/tooling/ide/api/src/org/apache/sling/ide/transport/impl/DefaultBatcher.java
Wed Sep 30 17:56:30 2015
@@ -46,12 +46,14 @@ public class DefaultBatcher implements B
             }
         }
         
+        result.addAll(0, batched.getReorders());
         result.addAll(0, batched.getUpdates());
         result.addAll(0, batched.getDeletes());
         
         // Expected order is:
         // - delete
         // - add-or-update
+        // - reorder
         // - everything else, in the order it was specified
         
         queue.clear();
@@ -63,6 +65,7 @@ public class DefaultBatcher implements B
         
         private List<Command<?>> deletes = new ArrayList<Command<?>>();
         private List<Command<?>> updates = new ArrayList<Command<?>>();
+        private List<Command<?>> reorders = new ArrayList<Command<?>>();
         
         public boolean addLinked(Command<?> newCmd) {
             
@@ -76,9 +79,13 @@ public class DefaultBatcher implements B
                     return true;
                     
                 case ADD_OR_UPDATE:
-                    processAddOrUpdate(newCmd);
+                    processWithPathEqualityCheck(newCmd, updates);
                     return true;
-                
+                    
+                case REORDER_CHILDREN:
+                    processWithPathEqualityCheck(newCmd, reorders);
+                    return true;
+                    
                 default:
                     return false;
             
@@ -106,9 +113,9 @@ public class DefaultBatcher implements B
             deletes.add(newCmd);
         }
         
-        private void processAddOrUpdate(Command<?> newCmd) {
+        private void processWithPathEqualityCheck(Command<?> newCmd, List<Command<?>>
oldCmds) {
             String path = newCmd.getPath();
-            for (Command<?> oldCmd : updates) {
+            for (Command<?> oldCmd : oldCmds) {
                 // if we already have an add-or-update for this path, skip it    
                 if ( path.equals(oldCmd.getPath()) ) {
                     return;
@@ -116,7 +123,7 @@ public class DefaultBatcher implements B
             }
             
             // no adds or updates, add it as-is
-            updates.add(newCmd);            
+            oldCmds.add(newCmd);
         }
         
         public List<Command<?>> getDeletes() {
@@ -126,5 +133,9 @@ public class DefaultBatcher implements B
         public List<Command<?>> getUpdates() {
             return updates;
         }
+        
+        public List<Command<?>> getReorders() {
+            return reorders;
+        }
     }
 }

Modified: sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/VltBatcherTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/VltBatcherTest.java?rev=1706100&r1=1706099&r2=1706100&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/VltBatcherTest.java
(original)
+++ sling/trunk/tooling/ide/impl-vlt-test/src/test/java/org/apache/sling/ide/impl/vlt/transport/VltBatcherTest.java
Wed Sep 30 17:56:30 2015
@@ -132,4 +132,39 @@ public class VltBatcherTest {
         assertThat(batched.get(0), Matchers.<Command<?>> sameInstance(first));
         assertThat(batched.get(1), Matchers.<Command<?>> sameInstance(second));
     }
+
+
+    @Test
+    public void identicalsReorderingsAreCompacted() {
+        
+        ReorderChildNodesCommand first = new ReorderChildNodesCommand(mockRepo, credentials,
new ResourceProxy("/content"), null);
+        ReorderChildNodesCommand second = new ReorderChildNodesCommand(mockRepo, credentials,new
ResourceProxy("/content"), null);
+        
+        batcher.add(first);
+        batcher.add(second);
+        
+        List<Command<?>> batched = batcher.get();
+        
+        assertThat(batched, hasSize(1));
+        Command<?> command = batched.get(0);
+        assertThat(command, instanceOf(ReorderChildNodesCommand.class));
+        assertThat(command.getPath(), equalTo("/content"));
+    }
+    
+    @Test
+    public void unrelatedReorderingsAreNotCompacted() {
+        
+        ReorderChildNodesCommand first = new ReorderChildNodesCommand(mockRepo, credentials,
new ResourceProxy("/content/a"), null);
+        ReorderChildNodesCommand second = new ReorderChildNodesCommand(mockRepo, credentials,new
ResourceProxy("/content/b"), null);
+        
+        batcher.add(first);
+        batcher.add(second);
+        
+        List<Command<?>> batched = batcher.get();
+        
+        assertThat(batched, hasSize(2));
+        assertThat(batched.get(0), Matchers.<Command<?>> sameInstance(first));
+        assertThat(batched.get(1), Matchers.<Command<?>> sameInstance(second));
+    }
+    
 }

Modified: sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/ReorderChildNodesCommand.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/ReorderChildNodesCommand.java?rev=1706100&r1=1706099&r2=1706100&view=diff
==============================================================================
--- sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/ReorderChildNodesCommand.java
(original)
+++ sling/trunk/tooling/ide/impl-vlt/src/org/apache/sling/ide/impl/vlt/ReorderChildNodesCommand.java
Wed Sep 30 17:56:30 2015
@@ -164,5 +164,9 @@ public class ReorderChildNodesCommand ex
 
         getLogger().trace(out.toString());
     }
-
+    
+    @Override
+    public Kind getKind() {
+        return Kind.REORDER_CHILDREN;
+    }
 }



Mime
View raw message