helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kisho...@apache.org
Subject [20/52] [abbrv] git commit: [HELIX-302] fix helix version compare bug
Date Wed, 20 Nov 2013 21:12:35 GMT
[HELIX-302] fix helix version compare bug


Project: http://git-wip-us.apache.org/repos/asf/incubator-helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-helix/commit/b3eca30d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-helix/tree/b3eca30d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-helix/diff/b3eca30d

Branch: refs/heads/helix-yarn
Commit: b3eca30dded9d62b196083b1c89fa0acc77d49c2
Parents: 3de26c7
Author: zzhang <zzhang@apache.org>
Authored: Tue Nov 12 16:40:17 2013 -0800
Committer: zzhang <zzhang@apache.org>
Committed: Tue Nov 12 16:40:17 2013 -0800

----------------------------------------------------------------------
 .../java/org/apache/helix/HelixConnection.java  |  2 +-
 .../apache/helix/HelixManagerProperties.java    |  9 +++-
 .../manager/zk/HelixConnectionAdaptor.java      |  2 +-
 .../helix/manager/zk/ZkHelixConnection.java     |  2 +-
 .../apache/helix/TestHelixVersionCompare.java   | 55 ++++++++++++++++++++
 5 files changed, 65 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b3eca30d/helix-core/src/main/java/org/apache/helix/HelixConnection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixConnection.java b/helix-core/src/main/java/org/apache/helix/HelixConnection.java
index 9d93c97..0e674d2 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixConnection.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixConnection.java
@@ -112,7 +112,7 @@ public interface HelixConnection {
    * Provides admin interface to setup and modify cluster
    * @return instantiated HelixAdmin
    */
-  HelixAdmin createClusterManagmentTool();
+  HelixAdmin createClusterManagementTool();
 
   /**
    * create a default property-store for a cluster

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b3eca30d/helix-core/src/main/java/org/apache/helix/HelixManagerProperties.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/HelixManagerProperties.java b/helix-core/src/main/java/org/apache/helix/HelixManagerProperties.java
index 2318d20..aca2f30 100644
--- a/helix-core/src/main/java/org/apache/helix/HelixManagerProperties.java
+++ b/helix-core/src/main/java/org/apache/helix/HelixManagerProperties.java
@@ -96,7 +96,7 @@ public class HelixManagerProperties {
    */
   static boolean versionNoLessThan(String version1, String version2) {
     if (version1 == null || version2 == null) {
-      LOG.warn("fail to compare versions. version1: " + version1 + ", version2: " + version2);
+      LOG.warn("Skip null version check. version1: " + version1 + ", version2: " + version2);
       return true;
     }
 
@@ -105,7 +105,8 @@ public class HelixManagerProperties {
 
     if (version1Splits == null || version1Splits.length == 0 || version2Splits == null
         || version2Splits.length == 0) {
-      LOG.warn("fail to compare versions. version1: " + version1 + ", version2: " + version2);
+      LOG.warn("Skip empty version check. version1: " + version1 + ", version2: " + version2);
+      return true;
     }
 
     for (int i = 0; i < version1Splits.length && i < version2Splits.length;
i++) {
@@ -115,9 +116,13 @@ public class HelixManagerProperties {
 
         if (versionNum1 < versionNum2) {
           return false;
+        } else if (versionNum1 > versionNum2) {
+          return true;
         }
       } catch (Exception e) {
         // ignore non-numerical strings and strings after non-numerical strings
+        LOG.warn("Skip non-numerical version check. version1: " + version1 + ", version2:
"
+            + version2);
         break;
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b3eca30d/helix-core/src/main/java/org/apache/helix/manager/zk/HelixConnectionAdaptor.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/HelixConnectionAdaptor.java
b/helix-core/src/main/java/org/apache/helix/manager/zk/HelixConnectionAdaptor.java
index 487c3a6..ecafbc8 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/HelixConnectionAdaptor.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/HelixConnectionAdaptor.java
@@ -191,7 +191,7 @@ public class HelixConnectionAdaptor implements HelixManager {
 
   @Override
   public HelixAdmin getClusterManagmentTool() {
-    return _connection.createClusterManagmentTool();
+    return _connection.createClusterManagementTool();
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b3eca30d/helix-core/src/main/java/org/apache/helix/manager/zk/ZkHelixConnection.java
----------------------------------------------------------------------
diff --git a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkHelixConnection.java b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkHelixConnection.java
index 7d6f132..1bdc54c 100644
--- a/helix-core/src/main/java/org/apache/helix/manager/zk/ZkHelixConnection.java
+++ b/helix-core/src/main/java/org/apache/helix/manager/zk/ZkHelixConnection.java
@@ -241,7 +241,7 @@ public class ZkHelixConnection implements HelixConnection, IZkStateListener
{
   }
 
   @Override
-  public HelixAdmin createClusterManagmentTool() {
+  public HelixAdmin createClusterManagementTool() {
     return new ZKHelixAdmin(_zkclient);
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-helix/blob/b3eca30d/helix-core/src/test/java/org/apache/helix/TestHelixVersionCompare.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/TestHelixVersionCompare.java b/helix-core/src/test/java/org/apache/helix/TestHelixVersionCompare.java
new file mode 100644
index 0000000..ede570a
--- /dev/null
+++ b/helix-core/src/test/java/org/apache/helix/TestHelixVersionCompare.java
@@ -0,0 +1,55 @@
+package org.apache.helix;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class TestHelixVersionCompare {
+
+  @Test
+  public void testNullVersionCompare() {
+    boolean isNoLessThan = HelixManagerProperties.versionNoLessThan(null, null);
+    Assert.assertTrue(isNoLessThan, "Skip version compare if no version is specified");
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("1.0", null);
+    Assert.assertTrue(isNoLessThan, "Skip version compare if no version is specified");
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan(null, "1.0");
+    Assert.assertTrue(isNoLessThan, "Skip version compare if no version is specified");
+  }
+
+  @Test
+  public void testEmptyVersionCompare() {
+    boolean isNoLessThan = HelixManagerProperties.versionNoLessThan("", "");
+    Assert.assertTrue(isNoLessThan, "Skip version compare if empty version is specified");
+
+  }
+
+  @Test
+  public void testNonNumericalVersionCompare() {
+    boolean isNoLessThan =
+        HelixManagerProperties.versionNoLessThan("project.version1", "project.version2");
+    Assert.assertTrue(isNoLessThan, "Skip version compare if non-numerical version is specified");
+
+  }
+
+  @Test
+  public void testNumericalVersionCompare() {
+    boolean isNoLessThan = HelixManagerProperties.versionNoLessThan("0.7.0", "0.6.1");
+    Assert.assertTrue(isNoLessThan);
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("0.5.31", "0.6.1");
+    Assert.assertFalse(isNoLessThan);
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("0.5.31-SNAPSHOT", "0.6.1");
+    Assert.assertFalse(isNoLessThan);
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("0.5.31-incubating", "0.6.1");
+    Assert.assertFalse(isNoLessThan);
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("0.7.0", "0.6.1-SNAPSHOT");
+    Assert.assertTrue(isNoLessThan);
+
+    isNoLessThan = HelixManagerProperties.versionNoLessThan("0.7.0", "0.6.1-incubating");
+    Assert.assertTrue(isNoLessThan);
+  }
+}


Mime
View raw message