You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by ra...@apache.org on 2016/12/12 05:28:56 UTC

[1/2] incubator-carbondata git commit: Added unit test for DictionaryColumnUniqueIdentifierTest

Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 0cbb32586 -> 61fe6d462


Added unit test for DictionaryColumnUniqueIdentifierTest

Added unit test for ReverseDictionaryTest

Added unit test for ForwardDictionaryTest


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

Branch: refs/heads/master
Commit: cc288ff44331eefd3ee9749f43f95dceb712c1a7
Parents: 0cbb325
Author: kunal642 <ku...@knoldus.in>
Authored: Thu Nov 3 14:48:31 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 10:57:54 2016 +0530

----------------------------------------------------------------------
 .../DictionaryColumnUniqueIdentifierTest.java   |  98 ++++++++++++++
 .../cache/dictionary/ForwardDictionaryTest.java | 129 +++++++++++++++++++
 .../cache/dictionary/ReverseDictionaryTest.java |  98 ++++++++++++++
 3 files changed, 325 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/cc288ff4/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryColumnUniqueIdentifierTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryColumnUniqueIdentifierTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryColumnUniqueIdentifierTest.java
new file mode 100644
index 0000000..f4210c5
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryColumnUniqueIdentifierTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.carbondata.core.cache.dictionary;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+import org.apache.carbondata.core.carbon.CarbonTableIdentifier;
+import org.apache.carbondata.core.carbon.ColumnIdentifier;
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static junit.framework.TestCase.*;
+
+public class DictionaryColumnUniqueIdentifierTest {
+
+  private static DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier1;
+  private static DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier2;
+  private static DictionaryColumnUniqueIdentifier dictionaryColumnUniqueIdentifier3;
+
+  @BeforeClass public static void setUp() throws Exception {
+    CarbonTableIdentifier carbonTableIdentifier1 =
+        new CarbonTableIdentifier("testDatabase", "testTable", "1");
+    CarbonTableIdentifier carbonTableIdentifier2 =
+        new CarbonTableIdentifier("testDatabase", "testTable", "2");
+    Map<String, String> properties = new HashMap<>();
+    ColumnIdentifier columnIdentifier = new ColumnIdentifier("2", properties, DataType.STRING);
+    ColumnIdentifier columnIdentifier2 = new ColumnIdentifier("1", properties, DataType.INT);
+    dictionaryColumnUniqueIdentifier1 =
+        new DictionaryColumnUniqueIdentifier(carbonTableIdentifier1, columnIdentifier,
+            DataType.MAP);
+    dictionaryColumnUniqueIdentifier2 =
+        new DictionaryColumnUniqueIdentifier(carbonTableIdentifier2, columnIdentifier2,
+            DataType.MAP);
+    dictionaryColumnUniqueIdentifier3 =
+        new DictionaryColumnUniqueIdentifier(carbonTableIdentifier2, columnIdentifier,
+            DataType.MAP);
+  }
+
+  @Test public void testToGetDataType() {
+    assertEquals(dictionaryColumnUniqueIdentifier1.getDataType(), DataType.MAP);
+  }
+
+  @Test public void testForEqualsWithDifferentObjectsWithDifferentColumnIdentifier() {
+    assertTrue(!dictionaryColumnUniqueIdentifier1.equals(dictionaryColumnUniqueIdentifier2));
+  }
+
+  @Test public void testForEqualsWithDifferentObjectsWithSameCarbonTableIdentifier() {
+    assertTrue(!dictionaryColumnUniqueIdentifier3.equals(dictionaryColumnUniqueIdentifier2));
+  }
+
+  @Test public void testForEquals() {
+    assertTrue(dictionaryColumnUniqueIdentifier1.equals(dictionaryColumnUniqueIdentifier1));
+  }
+
+  @Test public void testForEqualsWithNull() {
+    assertNotNull(dictionaryColumnUniqueIdentifier1);
+  }
+
+  @Test public void testForEqualsWithDifferentClass() {
+    assertTrue(!dictionaryColumnUniqueIdentifier1.equals(""));
+  }
+
+  @Test public void testToGetHashCode() {
+    new MockUp<CarbonTableIdentifier>() {
+      @SuppressWarnings("unused") @Mock public int hashCode() {
+        return 1;
+      }
+    };
+    new MockUp<ColumnIdentifier>() {
+      @SuppressWarnings("unused") @Mock public int hashCode() {
+        return 2;
+      }
+    };
+    assertEquals(dictionaryColumnUniqueIdentifier1.hashCode(), 33);
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/cc288ff4/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ForwardDictionaryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ForwardDictionaryTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ForwardDictionaryTest.java
new file mode 100644
index 0000000..4812aa2
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ForwardDictionaryTest.java
@@ -0,0 +1,129 @@
+/*
+ * 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.carbondata.core.cache.dictionary;
+
+import mockit.Mock;
+import mockit.MockUp;
+
+import org.apache.carbondata.core.carbon.metadata.datatype.DataType;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static junit.framework.TestCase.*;
+
+public class ForwardDictionaryTest {
+
+  private static ForwardDictionary forwardDictionary;
+
+  @BeforeClass public static void setUp() {
+    ColumnDictionaryInfo columnDictionaryInfo = new ColumnDictionaryInfo(DataType.INT);
+    forwardDictionary = new ForwardDictionary(columnDictionaryInfo);
+  }
+
+  @Test public void testToGetSurrogateKeyForStringInput() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @Mock @SuppressWarnings("unused") public int getSurrogateKey(String value) {
+        return 123;
+      }
+    };
+    int expectedResult = 123;
+    assertEquals(forwardDictionary.getSurrogateKey("123"), expectedResult);
+  }
+
+  @Test public void testToGetSurrogateKeyForByteInput() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @Mock @SuppressWarnings("unused") public int getSurrogateKey(byte[] value) {
+        return 123;
+      }
+    };
+    int expectedResult = 123;
+    assertEquals(forwardDictionary.getSurrogateKey("123".getBytes()), expectedResult);
+  }
+
+  @Test public void testToGetDictionaryValueForKey() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @Mock @SuppressWarnings("unused") public String getDictionaryValueForKey(int surrogateKey) {
+        System.out.print("Mocked");
+        return "123";
+      }
+    };
+    String expectedResult = "123";
+    assertEquals(forwardDictionary.getDictionaryValueForKey(123), expectedResult);
+  }
+
+  @Test public void testToGetSortedIndex() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public int getSortedIndex(int surrogateKey) {
+        System.out.print("Mocked");
+        return 1;
+      }
+    };
+    int expectedResult = 1;
+    int sortedIndex = forwardDictionary.getSortedIndex(123);
+    assertEquals(sortedIndex, expectedResult);
+  }
+
+  @Test public void testToGetDictionaryValueFromSortedIndex() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock
+      public String getDictionaryValueFromSortedIndex(int sortedIndex) {
+        System.out.print("Mocked");
+        return "A";
+      }
+    };
+    String expectedResult = "A";
+    String dictionaryValue = forwardDictionary.getDictionaryValueFromSortedIndex(123);
+    assertEquals(dictionaryValue, expectedResult);
+  }
+
+  @Test public void testToGetDictionaryChunks() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public DictionaryChunksWrapper getDictionaryChunks() {
+        System.out.print("Mocked");
+        List<List<byte[]>> dictionaryChunks =
+            Arrays.asList(Arrays.asList("123".getBytes()), Arrays.asList("321".getBytes()));
+        return new DictionaryChunksWrapper(dictionaryChunks);
+      }
+    };
+    DictionaryChunksWrapper dictionaryValue = forwardDictionary.getDictionaryChunks();
+    int expectedResult = 2;
+    assertEquals(dictionaryValue.getSize(), expectedResult);
+  }
+
+  @Test public void testToGtSurrogateKeyByIncrementalSearch() {
+    new MockUp<ColumnDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock
+      public void getIncrementalSurrogateKeyFromDictionary(List<byte[]> byteValuesOfFilterMembers,
+          List<Integer> surrogates) {
+        surrogates.add(1);
+      }
+    };
+    List<String> evaluateResultList = Arrays.asList("1", "2");
+    List<Integer> surrogates = new ArrayList<>(1);
+    forwardDictionary.getSurrogateKeyByIncrementalSearch(evaluateResultList, surrogates);
+    Integer expectedResult = 1;
+    assertEquals(surrogates.get(0), expectedResult);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/cc288ff4/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ReverseDictionaryTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ReverseDictionaryTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ReverseDictionaryTest.java
new file mode 100644
index 0000000..c9a2143
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ReverseDictionaryTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.carbondata.core.cache.dictionary;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class ReverseDictionaryTest {
+
+  private static ReverseDictionary reverseDictionary;
+
+  @BeforeClass public static void setUp() throws Exception {
+    ColumnReverseDictionaryInfo columnReverseDictionaryInfo = new ColumnReverseDictionaryInfo();
+    reverseDictionary = new ReverseDictionary(columnReverseDictionaryInfo);
+  }
+
+  @Test public void testToGetSurrogateKey() {
+    new MockUp<ColumnReverseDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public int getSurrogateKey(byte[] value) {
+        return 123;
+      }
+    };
+    int surrogateKey = reverseDictionary.getSurrogateKey("123".getBytes());
+    int expectedResult = 123;
+    assertEquals(surrogateKey, expectedResult);
+  }
+
+  @Test public void testToGetDictionaryValueForKey() {
+    new MockUp<ColumnReverseDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public String getDictionaryValueForKey(int surrogateKey) {
+        return "123";
+      }
+    };
+    String dictionaryValue = reverseDictionary.getDictionaryValueForKey(123);
+    String expectedResult = "123";
+    assertEquals(dictionaryValue, expectedResult);
+  }
+
+  @Test public void testToGetSortedIndex() {
+    new MockUp<ColumnReverseDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public int getSortedIndex(int surrogateKey) {
+        return 1;
+      }
+    };
+    int sortedIndex = reverseDictionary.getSortedIndex(123);
+    int expectedResult = 1;
+    assertEquals(sortedIndex, expectedResult);
+  }
+
+  @Test public void testToGetDictionaryValueFromSortedIndex() {
+    new MockUp<ColumnReverseDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock
+      public String getDictionaryValueFromSortedIndex(int sortedIndex) {
+        return "A";
+      }
+    };
+    String dictionaryValue = reverseDictionary.getDictionaryValueFromSortedIndex(123);
+    String expectedResult = "A";
+    assertEquals(dictionaryValue, expectedResult);
+  }
+
+  @Test public void testToGetDictionaryChunks() {
+    new MockUp<ColumnReverseDictionaryInfo>() {
+      @SuppressWarnings("unused") @Mock public DictionaryChunksWrapper getDictionaryChunks() {
+        List<List<byte[]>> dictionaryChunks =
+            Arrays.asList(Arrays.asList("123".getBytes()), Arrays.asList("321".getBytes()));
+        return new DictionaryChunksWrapper(dictionaryChunks);
+      }
+    };
+    DictionaryChunksWrapper dictionaryValue = reverseDictionary.getDictionaryChunks();
+    int expectedResult = 2;
+    assertEquals(dictionaryValue.getSize(), expectedResult);
+  }
+
+}


[2/2] incubator-carbondata git commit: [CARBONDATA-377] Add unit test for core.cache.dictionary package This closes #346

Posted by ra...@apache.org.
[CARBONDATA-377] Add unit test for core.cache.dictionary package This closes #346


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

Branch: refs/heads/master
Commit: 61fe6d462e4bb9a2f305a495891b4c37d3fd3e87
Parents: 0cbb325 cc288ff
Author: ravipesala <ra...@gmail.com>
Authored: Mon Dec 12 10:58:26 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 10:58:26 2016 +0530

----------------------------------------------------------------------
 .../DictionaryColumnUniqueIdentifierTest.java   |  98 ++++++++++++++
 .../cache/dictionary/ForwardDictionaryTest.java | 129 +++++++++++++++++++
 .../cache/dictionary/ReverseDictionaryTest.java |  98 ++++++++++++++
 3 files changed, 325 insertions(+)
----------------------------------------------------------------------