activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r679504 - in /activemq/sandbox/zookeeper/zookeeper-protocols/src: main/java/org/apache/zookeeper/protocols/ZNodeName.java test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java
Date Thu, 24 Jul 2008 19:16:40 GMT
Author: jstrachan
Date: Thu Jul 24 12:16:40 2008
New Revision: 679504

URL: http://svn.apache.org/viewvc?rev=679504&view=rev
Log:
changed ZNodeName to sort by sequence number first, for easier support of things like shared
locks

Modified:
    activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZNodeName.java
    activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java

Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZNodeName.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZNodeName.java?rev=679504&r1=679503&r2=679504&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZNodeName.java
(original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/main/java/org/apache/zookeeper/protocols/ZNodeName.java
Thu Jul 24 12:16:40 2008
@@ -70,14 +70,19 @@
     }
 
     public int compareTo(ZNodeName that) {
-        int answer = this.prefix.compareTo(that.prefix);
+        int answer;
+        int s1 = this.sequence;
+        int s2 = that.sequence;
+        if (s1 == -1 && s2 == -1) {
+            answer = 0;
+        } else {
+            answer = s1 == -1 ? 1 : s2 == -1 ? -1 : s1 - s2;
+        }
         if (answer == 0) {
-            int s1 = this.sequence;
-            int s2 = that.sequence;
-            if (s1 == -1 && s2 == -1) {
-                return this.name.compareTo(that.name);
+            answer = this.prefix.compareTo(that.prefix);
+            if (answer == 0) {
+                answer = this.name.compareTo(that.name);
             }
-            answer = s1 == -1 ? 1 : s2 == -1 ? -1 : s1 - s2;
         }
         return answer;
     }

Modified: activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java?rev=679504&r1=679503&r2=679504&view=diff
==============================================================================
--- activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java
(original)
+++ activemq/sandbox/zookeeper/zookeeper-protocols/src/test/java/org/apache/zookeeper/protocols/ZNodeNameTest.java
Thu Jul 24 12:16:40 2008
@@ -26,14 +26,16 @@
  * @version $Revision: 1.1 $
  */
 public class ZNodeNameTest extends TestCase {
+
     public void testOrderWithSamePrefix() throws Exception {
         String[] names = { "x-3", "x-5", "x-11", "x-1" };
         String[] expected = { "x-1", "x-3", "x-5", "x-11" };
         assertOrderedNodeNames(names, expected);
     }
+
     public void testOrderWithDifferentPrefixes() throws Exception {
-        String[] names = { "r-3", "r-2", "r-1", "w-2", "w-1" };
-        String[] expected = { "r-1", "r-2", "r-3", "w-1", "w-2" };
+        String[] names = { "x-22", "s-11", "s-21", "s-20", "x-19" };
+        String[] expected = { "s-11", "x-19", "s-20", "s-21", "x-22" };
         assertOrderedNodeNames(names, expected);
     }
 



Mime
View raw message