You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2016/12/10 12:38:02 UTC

kylin git commit: minor, add UT for metadata copy functions

Repository: kylin
Updated Branches:
  refs/heads/master fbb7ed921 -> 77d5d7d62


minor, add UT for metadata copy functions


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

Branch: refs/heads/master
Commit: 77d5d7d627dcbb0ed66461a46834711106a055e1
Parents: fbb7ed9
Author: lidongsjtu <li...@apache.org>
Authored: Sat Dec 10 20:29:41 2016 +0800
Committer: lidongsjtu <li...@apache.org>
Committed: Sat Dec 10 20:36:15 2016 +0800

----------------------------------------------------------------------
 .../org/apache/kylin/cube/model/CubeDesc.java   |  3 +-
 .../org/apache/kylin/cube/CubeDescTest.java     | 26 ++++++--
 .../kylin/metadata/model/DataModelDesc.java     |  9 +--
 .../kylin/metadata/model/DataModelDescTest.java | 67 ++++++++++++++++++++
 4 files changed, 95 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/77d5d7d6/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
----------------------------------------------------------------------
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
index 56a8b7e..6088bb4 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/model/CubeDesc.java
@@ -1129,8 +1129,9 @@ public class CubeDesc extends RootPersistentEntity implements IEngineAware {
         newCubeDesc.setAggregationGroups(cubeDesc.getAggregationGroups());
         newCubeDesc.setOverrideKylinProps(cubeDesc.getOverrideKylinProps());
         newCubeDesc.setConfig((KylinConfigExt) cubeDesc.getConfig());
-        newCubeDesc.updateRandomUuid();
+        newCubeDesc.setLastModified(cubeDesc.getLastModified());
         newCubeDesc.setPartitionOffsetStart(cubeDesc.getPartitionOffsetStart());
+        newCubeDesc.updateRandomUuid();
         return newCubeDesc;
     }
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/77d5d7d6/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
----------------------------------------------------------------------
diff --git a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
index 27c154b..78cf222 100644
--- a/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
+++ b/core-cube/src/test/java/org/apache/kylin/cube/CubeDescTest.java
@@ -40,13 +40,15 @@ import org.junit.rules.ExpectedException;
 
 import com.google.common.collect.Maps;
 
+import static org.junit.Assert.assertEquals;
+
 /**
  * @author yangli9
  */
 public class CubeDescTest extends LocalFileMetadataTestCase {
 
     private static final String CUBE_WITH_SLR_DESC = "test_kylin_cube_with_slr_desc";
-    
+
     private String SELLER_ID;
     private String SLR_SEGMENT_CD;
     private String LSTG_FORMAT_NAME;
@@ -55,14 +57,14 @@ public class CubeDescTest extends LocalFileMetadataTestCase {
     private String CATEG_LVL2_NAME;
     private String CATEG_LVL3_NAME;
     private String LEAF_CATEG_ID;
-    
+
     @Rule
     public ExpectedException thrown = ExpectedException.none();
 
     @Before
     public void setUp() throws Exception {
         this.createTestMetadata();
-        
+
         CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
         AggregationGroup g = cubeDesc.getAggregationGroups().get(0);
         SELLER_ID = getColInAggrGroup(g, "SELLER_ID");
@@ -230,7 +232,7 @@ public class CubeDescTest extends LocalFileMetadataTestCase {
     }
 
     @Test
-    public void testCombinationIntOverflow() throws  Exception {
+    public void testCombinationIntOverflow() throws Exception {
         for (File f : new File(LocalFileMetadataTestCase.LOCALMETA_TEMP_DATA, "cube_desc").listFiles()) {
             if (f.getName().endsWith(".bad")) {
                 String path = f.getPath();
@@ -254,6 +256,20 @@ public class CubeDescTest extends LocalFileMetadataTestCase {
     }
 
     @Test
+    public void testGetCopyOf() throws Exception {
+        CubeDesc desc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
+        CubeDesc copyDesc = CubeDesc.getCopyOf(desc);
+
+        // uuid is different, set to equals for json comparison
+        copyDesc.setUuid(desc.getUuid());
+
+        String descStr = JsonUtil.writeValueAsIndentString(desc);
+        String copyStr = JsonUtil.writeValueAsIndentString(copyDesc);
+
+        assertEquals(descStr, copyStr);
+    }
+
+    @Test
     public void testGetCubeDesc() throws Exception {
         CubeDesc cubeDesc = CubeDescManager.getInstance(getTestConfig()).getCubeDesc(CUBE_WITH_SLR_DESC);
         Assert.assertNotNull(cubeDesc);
@@ -272,7 +288,7 @@ public class CubeDescTest extends LocalFileMetadataTestCase {
 
         Map<?, ?> map2 = JsonUtil.readValue(mapStr, HashMap.class);
 
-        Assert.assertEquals(map, map2);
+        assertEquals(map, map2);
 
     }
 

http://git-wip-us.apache.org/repos/asf/kylin/blob/77d5d7d6/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
index 3f868a2..99636d7 100644
--- a/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
+++ b/core-metadata/src/main/java/org/apache/kylin/metadata/model/DataModelDesc.java
@@ -153,7 +153,7 @@ public class DataModelDesc extends RootPersistentEntity {
     public JoinDesc getJoinByPKSide(TableRef table) {
         return joinsTree.getJoinByPKSide(table);
     }
-    
+
     public JoinsTree getJoinsTree() {
         return joinsTree;
     }
@@ -181,7 +181,7 @@ public class DataModelDesc extends RootPersistentEntity {
         }
         return false;
     }
-    
+
     public boolean isFactTable(TableRef t) {
         if (t == null)
             return false;
@@ -196,7 +196,7 @@ public class DataModelDesc extends RootPersistentEntity {
         }
         return false;
     }
-    
+
     public boolean containsTable(String fullTableName) {
         for (TableRef t : allTableRefs) {
             if (t.getTableIdentity().equals(fullTableName))
@@ -204,7 +204,7 @@ public class DataModelDesc extends RootPersistentEntity {
         }
         return false;
     }
-    
+
     public String getFilterCondition() {
         return filterCondition;
     }
@@ -526,6 +526,7 @@ public class DataModelDesc extends RootPersistentEntity {
         copy.filterCondition = orig.filterCondition;
         copy.partitionDesc = PartitionDesc.getCopyOf(orig.getPartitionDesc());
         copy.capacity = orig.capacity;
+        copy.lastModified = orig.lastModified;
         copy.updateRandomUuid();
         return copy;
     }

http://git-wip-us.apache.org/repos/asf/kylin/blob/77d5d7d6/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java
----------------------------------------------------------------------
diff --git a/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java b/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java
new file mode 100644
index 0000000..15bd29c
--- /dev/null
+++ b/core-metadata/src/test/java/org/apache/kylin/metadata/model/DataModelDescTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.metadata.model;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.kylin.common.util.JsonUtil;
+import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.apache.kylin.metadata.MetadataManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+public class DataModelDescTest extends LocalFileMetadataTestCase {
+    @Before
+    public void setUp() throws Exception {
+        this.createTestMetadata();
+    }
+
+    @After
+    public void after() throws Exception {
+        this.cleanupTestMetadata();
+    }
+
+    @Test
+    public void testGetCopyOf() throws JsonProcessingException {
+        DataModelDesc desc = MetadataManager.getInstance(getTestConfig()).getDataModelDesc("test_kylin_inner_join_model_desc");
+        DataModelDesc copyDesc = DataModelDesc.getCopyOf(desc);
+
+        // uuid is different, set to equals for json comparison
+        copyDesc.setUuid(desc.getUuid());
+
+        String descStr = JsonUtil.writeValueAsIndentString(desc);
+        String copyStr = JsonUtil.writeValueAsIndentString(copyDesc);
+
+        assertEquals(descStr, copyStr);
+    }
+
+    @Test
+    public void testPartitionDescCopyOf() throws JsonProcessingException {
+        PartitionDesc desc = MetadataManager.getInstance(getTestConfig()).getDataModelDesc("test_kylin_inner_join_model_desc").partitionDesc;
+        PartitionDesc copyDesc = PartitionDesc.getCopyOf(desc);
+
+        String descStr = JsonUtil.writeValueAsIndentString(desc);
+        String copyStr = JsonUtil.writeValueAsIndentString(copyDesc);
+
+        assertEquals(descStr, copyStr);
+    }
+}