minor, fix backward compatible for KylinVersion

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

Branch: refs/heads/yaho-cube-planner
Commit: d0fe948d93123abed3c21428e20a50a2b67c2ff6
Parents: 7d28875
Author: lidongsjtu <lid...@apache.org>
Authored: Fri Aug 11 16:09:03 2017 +0800
Committer: Hongbin Ma <mahong...@apache.org>
Committed: Fri Aug 11 16:55:56 2017 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/common/KylinVersion.java   |  6 ++-
 .../apache/kylin/common/KylinVersionTest.java   | 40 ++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/d0fe948d/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java 
b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
index 6eba7c5..960bafe 100644
--- a/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
+++ b/core-common/src/main/java/org/apache/kylin/common/KylinVersion.java
@@ -58,7 +58,7 @@ public class KylinVersion implements Comparable {
 
         major = Integer.parseInt(splits[0]);
         minor = Integer.parseInt(splits[1]);
-        revision = Integer.parseInt(splits[2]);
+        revision = splits.length < 3 ? 0 : Integer.parseInt(splits[2]);
     }
 
     @Override
@@ -168,7 +168,9 @@ public class KylinVersion implements Comparable {
     public static String getKylinClientInformation() {
         StringBuilder buf = new StringBuilder();
 
-        buf.append("kylin.home: ").append(KylinConfig.getKylinHome() == null ? 
"UNKNOWN" : new 
File(KylinConfig.getKylinHome()).getAbsolutePath()).append("\n");
+        buf.append("kylin.home: ").append(
+                KylinConfig.getKylinHome() == null ? "UNKNOWN" : new 
File(KylinConfig.getKylinHome()).getAbsolutePath())
+                .append("\n");
         
buf.append("kylin.version:").append(KylinVersion.getCurrentVersion()).append("\n");
         buf.append("commit:").append(getGitCommitInfo()).append("\n");
         
buf.append("os.name:").append(System.getProperty("os.name")).append("\n");

http://git-wip-us.apache.org/repos/asf/kylin/blob/d0fe948d/core-common/src/test/java/org/apache/kylin/common/KylinVersionTest.java
----------------------------------------------------------------------
diff --git 
a/core-common/src/test/java/org/apache/kylin/common/KylinVersionTest.java 
b/core-common/src/test/java/org/apache/kylin/common/KylinVersionTest.java
new file mode 100644
index 0000000..96b3189
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/KylinVersionTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+
+package org.apache.kylin.common;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class KylinVersionTest {
+    @Test
+    public void testNormal() {
+        KylinVersion ver1 = new KylinVersion("2.1.0");
+        Assert.assertEquals(2, ver1.major);
+        Assert.assertEquals(1, ver1.minor);
+        Assert.assertEquals(0, ver1.revision);
+    }
+
+    @Test
+    public void testNoRevision() {
+        KylinVersion ver1 = new KylinVersion("2.1");
+        Assert.assertEquals(2, ver1.major);
+        Assert.assertEquals(1, ver1.minor);
+        Assert.assertEquals(0, ver1.revision);
+    }
+}

Reply via email to