carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [1/2] incubator-carbondata git commit: created the unit test cases for carbon datastore
Date Fri, 09 Dec 2016 05:40:47 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master d700ab544 -> 38bf8ae3c


created the unit test cases for carbon datastore

created the unit test cases for carbon datastore


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

Branch: refs/heads/master
Commit: 838885bd3b2b6e49d4da41d4f67a25cc3f3050f6
Parents: d700ab5
Author: Harsh Sharma <harsh@knoldus.com>
Authored: Tue Dec 6 12:48:21 2016 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Fri Dec 9 11:09:44 2016 +0530

----------------------------------------------------------------------
 .../datastore/SegmentTaskIndexStoreTest.java    | 120 +++++++++++++++++++
 .../carbon/datastore/block/BlockIndexTest.java  |  79 ++++++++++++
 .../datastore/block/SegmentTaskIndexTest.java   |  78 ++++++++++++
 3 files changed, 277 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/838885bd/core/src/test/java/org/apache/carbondata/core/carbon/datastore/SegmentTaskIndexStoreTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/SegmentTaskIndexStoreTest.java
b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/SegmentTaskIndexStoreTest.java
new file mode 100644
index 0000000..7cb213c
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/SegmentTaskIndexStoreTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.carbon.datastore;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.carbondata.core.carbon.AbsoluteTableIdentifier;
+import org.apache.carbondata.core.carbon.CarbonTableIdentifier;
+import org.apache.carbondata.core.carbon.ColumnarFormatVersion;
+import org.apache.carbondata.core.carbon.datastore.block.AbstractIndex;
+import org.apache.carbondata.core.carbon.datastore.block.SegmentTaskIndex;
+import org.apache.carbondata.core.carbon.datastore.block.TableBlockInfo;
+import org.apache.carbondata.core.carbon.datastore.exception.IndexBuilderException;
+import org.apache.carbondata.core.carbon.metadata.blocklet.BlockletInfo;
+import org.apache.carbondata.core.carbon.metadata.blocklet.DataFileFooter;
+import org.apache.carbondata.core.carbon.metadata.blocklet.SegmentInfo;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema;
+import org.apache.carbondata.core.carbon.path.CarbonTablePath;
+import org.apache.carbondata.core.util.CarbonUtil;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertNull;
+
+public class SegmentTaskIndexStoreTest {
+
+  private static short version = 1;
+  private static String locations[] = { "/tmp" };
+  private static SegmentTaskIndexStore taskIndexStore;
+  private static TableBlockInfo tableBlockInfo;
+  private static AbsoluteTableIdentifier absoluteTableIdentifier;
+
+  @BeforeClass public static void setUp() {
+    taskIndexStore = SegmentTaskIndexStore.getInstance();
+    tableBlockInfo = new TableBlockInfo("file", 0L, "SG100", locations, 10L,
+        ColumnarFormatVersion.valueOf(version));
+    absoluteTableIdentifier = new AbsoluteTableIdentifier("/tmp",
+        new CarbonTableIdentifier("testdatabase", "testtable", "TB100"));
+  }
+
+  private List<DataFileFooter> getDataFileFooters() {
+    SegmentInfo segmentInfo = new SegmentInfo();
+    DataFileFooter footer = new DataFileFooter();
+    ColumnSchema columnSchema = new ColumnSchema();
+    BlockletInfo blockletInfo = new BlockletInfo();
+    List<DataFileFooter> footerList = new ArrayList<DataFileFooter>();
+    List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
+
+    columnSchema.setColumnName("employeeName");
+    columnSchemaList.add(new ColumnSchema());
+
+    footer.setSegmentInfo(segmentInfo);
+    footer.setColumnInTable(columnSchemaList);
+    footer.setBlockletList(Arrays.asList(blockletInfo));
+    footerList.add(footer);
+    return footerList;
+  }
+
+  @Test public void loadAndGetTaskIdToSegmentsMap() throws IndexBuilderException {
+    new MockUp<CarbonTablePath.DataFileUtil>() {
+      @Mock String getTaskNo(String carbonDataFileName) {
+        return "100";
+      }
+    };
+
+    new MockUp<CarbonUtil>() {
+      @Mock List<DataFileFooter> readCarbonIndexFile(String taskId,
+          List<TableBlockInfo> tableBlockInfoList,
+          AbsoluteTableIdentifier absoluteTableIdentifier) {
+        return getDataFileFooters();
+      }
+    };
+
+    new MockUp<SegmentTaskIndex>() {
+      @Mock void buildIndex(List<DataFileFooter> footerList) {
+      }
+    };
+
+    Map<String, AbstractIndex> result =
+        taskIndexStore.loadAndGetTaskIdToSegmentsMap(new HashMap<String, List<TableBlockInfo>>()
{{
+          put("SG100", Arrays.asList(tableBlockInfo));
+        }}, absoluteTableIdentifier);
+
+    assertEquals(result.size(), 1);
+    assertTrue(result.containsKey(new String("100")));
+
+  }
+
+  @Test public void checkExistenceOfSegmentBTree() {
+    Map<String, AbstractIndex> result =
+        taskIndexStore.getSegmentBTreeIfExists(absoluteTableIdentifier, "SG100");
+    assertNull(result);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/838885bd/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/BlockIndexTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/BlockIndexTest.java
b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/BlockIndexTest.java
new file mode 100644
index 0000000..2be49ab
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/BlockIndexTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.carbon.datastore.block;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.carbondata.core.carbon.datastore.BTreeBuilderInfo;
+import org.apache.carbondata.core.carbon.datastore.impl.btree.BlockletBTreeBuilder;
+import org.apache.carbondata.core.carbon.metadata.blocklet.BlockletInfo;
+import org.apache.carbondata.core.carbon.metadata.blocklet.DataFileFooter;
+import org.apache.carbondata.core.carbon.metadata.blocklet.SegmentInfo;
+import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletIndex;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class BlockIndexTest {
+
+  private static SegmentInfo segmentInfo;
+  private static DataFileFooter footer;
+  private static ColumnSchema columnSchema;
+  private static BlockletInfo blockletInfo;
+  private static BlockletIndex blockletIndex;
+  private static List<DataFileFooter> footerList = new ArrayList<DataFileFooter>();
+  private static List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
+
+  @BeforeClass public static void setUp() {
+    segmentInfo = new SegmentInfo();
+    footer = new DataFileFooter();
+    columnSchema = new ColumnSchema();
+    blockletInfo = new BlockletInfo();
+    blockletIndex = new BlockletIndex();
+  }
+
+  @Test public void testBuild() {
+    segmentInfo = new SegmentInfo();
+    new MockUp<BlockletBTreeBuilder>() {
+      @Mock public void build(BTreeBuilderInfo segmentBuilderInfos) {
+      }
+    };
+    int expectedValue = 0;
+    BlockIndex blockIndex = new BlockIndex();
+    columnSchema.setColumnName("employeeName");
+    columnSchemaList.add(new ColumnSchema());
+
+    footer.setSegmentInfo(segmentInfo);
+    footer.setColumnInTable(columnSchemaList);
+    footer.setBlockletList(Arrays.asList(blockletInfo));
+    footerList.add(footer);
+
+    blockIndex.buildIndex(footerList);
+    assertEquals(footerList.get(0).getNumberOfRows(), expectedValue);
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/838885bd/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java
b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java
new file mode 100644
index 0000000..8a08fc4
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastore/block/SegmentTaskIndexTest.java
@@ -0,0 +1,78 @@
+/*
+ * 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.carbon.datastore.block;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.carbondata.core.carbon.datastore.BTreeBuilderInfo;
+import org.apache.carbondata.core.carbon.datastore.impl.btree.BlockBTreeBuilder;
+import org.apache.carbondata.core.carbon.metadata.blocklet.BlockletInfo;
+import org.apache.carbondata.core.carbon.metadata.blocklet.DataFileFooter;
+import org.apache.carbondata.core.carbon.metadata.blocklet.SegmentInfo;
+import org.apache.carbondata.core.carbon.metadata.blocklet.index.BlockletIndex;
+import org.apache.carbondata.core.carbon.metadata.schema.table.column.ColumnSchema;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class SegmentTaskIndexTest {
+
+  private static SegmentInfo segmentInfo;
+  private static DataFileFooter footer;
+  private static ColumnSchema columnSchema;
+  private static BlockletInfo blockletInfo;
+  private static BlockletIndex blockletIndex;
+  private static List<DataFileFooter> footerList = new ArrayList<DataFileFooter>();
+  private static List<ColumnSchema> columnSchemaList = new ArrayList<ColumnSchema>();
+
+  @BeforeClass public static void setUp() {
+    segmentInfo = new SegmentInfo();
+    footer = new DataFileFooter();
+    columnSchema = new ColumnSchema();
+    blockletInfo = new BlockletInfo();
+    blockletIndex = new BlockletIndex();
+  }
+
+  @Test public void testBuild() {
+    new MockUp<BlockBTreeBuilder>() {
+      @Mock public void build(BTreeBuilderInfo segmentBuilderInfos) {}
+    };
+    long numberOfRows = 100;
+    SegmentTaskIndex segmentTaskIndex = new SegmentTaskIndex();
+    columnSchema.setColumnName("employeeName");
+    columnSchemaList.add(new ColumnSchema());
+
+    footer.setSegmentInfo(segmentInfo);
+    footer.setColumnInTable(columnSchemaList);
+    footer.setBlockletList(Arrays.asList(blockletInfo));
+    footer.setNumberOfRows(numberOfRows);
+    footerList.add(footer);
+
+    segmentTaskIndex.buildIndex(footerList);
+    assertEquals(footerList.get(0).getNumberOfRows(), numberOfRows);
+
+  }
+}


Mime
View raw message