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 06:35:26 UTC

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

Repository: incubator-carbondata
Updated Branches:
  refs/heads/master b1f4acad3 -> a13ee2392


Added unit test for cache package


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

Branch: refs/heads/master
Commit: 6828c4fc2f15e76e493e530f87bcb5aa7ebb69e5
Parents: b1f4aca
Author: kunal642 <ku...@knoldus.in>
Authored: Tue Nov 29 18:20:51 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 12:04:23 2016 +0530

----------------------------------------------------------------------
 .../core/cache/CarbonLRUCacheTest.java          | 70 ++++++++++++++
 .../ColumnDictionaryChunkIteratorTest.java      | 68 ++++++++++++++
 .../ColumnReverseDictionaryInfoTest.java        | 53 +++++++++++
 .../DictionaryCacheLoaderImplTest.java          | 98 ++++++++++++++++++++
 .../dictionary/DictionaryChunksWrapperTest.java |  7 +-
 5 files changed, 295 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6828c4fc/core/src/test/java/org/apache/carbondata/core/cache/CarbonLRUCacheTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/CarbonLRUCacheTest.java b/core/src/test/java/org/apache/carbondata/core/cache/CarbonLRUCacheTest.java
new file mode 100644
index 0000000..46297cb
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/CarbonLRUCacheTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+public class CarbonLRUCacheTest {
+
+  private static CarbonLRUCache carbonLRUCache;
+  private static Cacheable cacheable;
+
+  @BeforeClass public static void setUp() {
+    carbonLRUCache = new CarbonLRUCache("prop1", "2");
+    cacheable = new MockUp<Cacheable>() {
+      @SuppressWarnings("unused") @Mock long getMemorySize() {
+        return 15L;
+      }
+    }.getMockInstance();
+  }
+
+  @Test public void testPut() {
+    boolean result = carbonLRUCache.put("Column1", cacheable, 10L);
+    assertTrue(result);
+  }
+
+  @Test public void testPutWhenSizeIsNotAvailable() {
+    boolean result = carbonLRUCache.put("Column2", cacheable, 11111110L);
+    assertFalse(result);
+  }
+
+  @Test public void testPutWhenKeysHaveToBeRemoved() {
+    boolean result = carbonLRUCache.put("Column3", cacheable, 2097153L);
+    assertTrue(result);
+  }
+
+  @Test public void testRemove() {
+    carbonLRUCache.remove("Column2");
+    assertNull(carbonLRUCache.get("Column2"));
+  }
+
+  @AfterClass public static void cleanUp() {
+    carbonLRUCache.clear();
+    assertNull(carbonLRUCache.get("Column1"));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6828c4fc/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryChunkIteratorTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryChunkIteratorTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryChunkIteratorTest.java
new file mode 100644
index 0000000..ada36a7
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryChunkIteratorTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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 java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.carbondata.format.ColumnDictionaryChunk;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class ColumnDictionaryChunkIteratorTest {
+
+  private static ColumnDictionaryChunkIterator columnDictionaryChunkIterator;
+  private static List<byte[]> expectedResult;
+
+  @BeforeClass public static void setUp() {
+    ColumnDictionaryChunk columnDictionaryChunk1 = new ColumnDictionaryChunk();
+    ByteBuffer byteBuffer3 = ByteBuffer.wrap("c".getBytes());
+    ByteBuffer byteBuffer4 = ByteBuffer.wrap("d".getBytes());
+    columnDictionaryChunk1.setValues(new ArrayList<ByteBuffer>());
+    ColumnDictionaryChunk columnDictionaryChunk2 = new ColumnDictionaryChunk();
+    columnDictionaryChunk2.setValues(Arrays.asList(byteBuffer3, byteBuffer4));
+    expectedResult = prepareExpectedData();
+    columnDictionaryChunkIterator = new ColumnDictionaryChunkIterator(
+        Arrays.asList(columnDictionaryChunk1, columnDictionaryChunk2));
+  }
+
+  private static List<byte[]> prepareExpectedData() {
+    List<byte[]> chunks = new ArrayList<>();
+    chunks.add("c".getBytes());
+    chunks.add("d".getBytes());
+    return chunks;
+  }
+
+  @Test public void testNext() throws Exception {
+    List<byte[]> actual = new ArrayList<>();
+    while (columnDictionaryChunkIterator.hasNext()) {
+      actual.add(columnDictionaryChunkIterator.next());
+    }
+    for (int i = 0; i < actual.size(); i++) {
+      assertThat(expectedResult.get(i), is(equalTo(actual.get(i))));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6828c4fc/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnReverseDictionaryInfoTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnReverseDictionaryInfoTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnReverseDictionaryInfoTest.java
new file mode 100644
index 0000000..921aada
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/ColumnReverseDictionaryInfoTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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 java.util.Arrays;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class ColumnReverseDictionaryInfoTest {
+
+  private static ColumnReverseDictionaryInfo columnReverseDictionaryInfo;
+
+  @BeforeClass public static void setUp() {
+    columnReverseDictionaryInfo = new ColumnReverseDictionaryInfo();
+    columnReverseDictionaryInfo.addDictionaryChunk(Arrays.asList("a".getBytes()));
+    columnReverseDictionaryInfo.addDictionaryChunk(Arrays.asList("b".getBytes()));
+  }
+
+  @Test public void testToGetSurrogateKey() {
+    int key1 = columnReverseDictionaryInfo.getSurrogateKey("a".getBytes());
+    int key2 = columnReverseDictionaryInfo.getSurrogateKey("b".getBytes());
+    int[] surrogateKey = { key1, key2 };
+    int[] expectedKeys = { 1, 2 };
+    assertThat(surrogateKey, is(equalTo(expectedKeys)));
+  }
+
+  @Test public void testToGetSurrogateKeyForInvalidKey() {
+    int key = columnReverseDictionaryInfo.getSurrogateKey("c".getBytes());
+    int expectedKey = -1;
+    assertThat(key, is(equalTo(expectedKey)));
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6828c4fc/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryCacheLoaderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryCacheLoaderImplTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryCacheLoaderImplTest.java
new file mode 100644
index 0000000..0a63b2a
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryCacheLoaderImplTest.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 java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+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.apache.carbondata.core.reader.CarbonDictionaryReaderImpl;
+import org.apache.carbondata.core.reader.sortindex.CarbonDictionarySortIndexReaderImpl;
+import org.apache.carbondata.format.ColumnDictionaryChunk;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class DictionaryCacheLoaderImplTest {
+
+  private static DictionaryCacheLoaderImpl dictionaryCacheLoader;
+  private static DictionaryInfo dictionaryInfo;
+  private static ColumnIdentifier columnIdentifier;
+
+  @BeforeClass public static void setUp() {
+    CarbonTableIdentifier carbonTableIdentifier = new CarbonTableIdentifier("db", "table1", "1");
+    dictionaryCacheLoader = new DictionaryCacheLoaderImpl(carbonTableIdentifier, "/tmp/");
+    dictionaryInfo = new ColumnDictionaryInfo(DataType.STRING);
+    new MockUp<CarbonDictionaryReaderImpl>() {
+      @Mock @SuppressWarnings("unused") Iterator<byte[]> read(long startOffset, long endOffset)
+          throws IOException {
+        ColumnDictionaryChunk columnDictionaryChunk = new ColumnDictionaryChunk();
+        ByteBuffer byteBuffer1 = ByteBuffer.wrap("c".getBytes());
+        ByteBuffer byteBuffer2 = ByteBuffer.wrap("d".getBytes());
+        columnDictionaryChunk.setValues(Arrays.asList(byteBuffer1, byteBuffer2));
+        return new ColumnDictionaryChunkIterator(Arrays.asList(columnDictionaryChunk));
+      }
+    };
+
+    new MockUp<CarbonDictionarySortIndexReaderImpl>() {
+      @Mock @SuppressWarnings("unused") List<Integer> readSortIndex() throws IOException {
+        return Arrays.asList(1, 2);
+      }
+
+      @Mock @SuppressWarnings("unused") List<Integer> readInvertedSortIndex() throws IOException {
+        return Arrays.asList(1, 2);
+      }
+    };
+    Map<String, String> columnProperties = new HashMap<>();
+    columnProperties.put("prop1", "value1");
+    columnProperties.put("prop2", "value2");
+    columnIdentifier = new ColumnIdentifier("1", columnProperties, DataType.STRING);
+  }
+
+  @Test public void testToLoad() throws IOException {
+    new MockUp<ColumnDictionaryInfo>() {
+      @Mock @SuppressWarnings("unused") int getSizeOfLastDictionaryChunk() {
+        return 9999;
+      }
+    };
+    dictionaryCacheLoader.load(dictionaryInfo, columnIdentifier, 0L, 2L, true);
+    assertEquals(dictionaryInfo.getDictionaryChunks().getSize(), 4);
+  }
+
+  @Test public void testToLoadWithsizeOfOneDictionaryChunkLessThanZero() throws IOException {
+    new MockUp<ColumnDictionaryInfo>() {
+      @Mock @SuppressWarnings("unused") int getSizeOfLastDictionaryChunk() {
+        return 10000;
+      }
+    };
+    dictionaryCacheLoader.load(dictionaryInfo, columnIdentifier, 0L, 2L, true);
+    assertEquals(dictionaryInfo.getDictionaryChunks().getSize(), 2);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/6828c4fc/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryChunksWrapperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryChunksWrapperTest.java b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryChunksWrapperTest.java
index 6f9e2db..c8fb32e 100644
--- a/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryChunksWrapperTest.java
+++ b/core/src/test/java/org/apache/carbondata/core/cache/dictionary/DictionaryChunksWrapperTest.java
@@ -58,6 +58,7 @@ public class DictionaryChunksWrapperTest {
     chunks.add("b".getBytes());
     chunks.add("c".getBytes());
     chunks.add("a".getBytes());
+    dictionaryChunks.add(new ArrayList<byte[]>());
     dictionaryChunks.add(chunks);
     return dictionaryChunks;
   }
@@ -105,6 +106,10 @@ public class DictionaryChunksWrapperTest {
    */
   @Test public void getSize() throws Exception {
     int size = dictionaryChunksWrapper.getSize();
-    Assert.assertEquals("", 4, size);
+    Assert.assertEquals(4, size);
+  }
+
+  @Test(expected = UnsupportedOperationException.class) public void testRemove() {
+    dictionaryChunksWrapper.remove();
   }
 }
\ No newline at end of file


[2/2] incubator-carbondata git commit: [CARBONDATA-472] Added unit test for cache package This closes #371

Posted by ra...@apache.org.
[CARBONDATA-472] Added unit test for cache package This closes #371


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

Branch: refs/heads/master
Commit: a13ee23920d9d32d43def566d78c76325805fbe3
Parents: b1f4aca 6828c4f
Author: ravipesala <ra...@gmail.com>
Authored: Mon Dec 12 12:04:55 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 12:04:55 2016 +0530

----------------------------------------------------------------------
 .../core/cache/CarbonLRUCacheTest.java          | 70 ++++++++++++++
 .../ColumnDictionaryChunkIteratorTest.java      | 68 ++++++++++++++
 .../ColumnReverseDictionaryInfoTest.java        | 53 +++++++++++
 .../DictionaryCacheLoaderImplTest.java          | 98 ++++++++++++++++++++
 .../dictionary/DictionaryChunksWrapperTest.java |  7 +-
 5 files changed, 295 insertions(+), 1 deletion(-)
----------------------------------------------------------------------