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: added test cases for core.reader module
Date Mon, 12 Dec 2016 12:42:26 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master edcea9bd2 -> e478cf74c


added test cases for core.reader module

formated the code

changed in assertion imports

corrected the package name


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

Branch: refs/heads/master
Commit: 104412eea9d79fba4cf188665da049e91470c97e
Parents: edcea9b
Author: anubhav100 <anubhav.tarar@knoldus.in>
Authored: Fri Nov 25 16:37:41 2016 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Mon Dec 12 18:11:27 2016 +0530

----------------------------------------------------------------------
 .../reader/CarbonDictionaryReaderImplTest.java  | 117 +++++++++++++++++++
 .../core/reader/CarbonIndexFileReaderTest.java  |  90 ++++++++++++++
 .../core/reader/ThriftReaderTest.java           |  97 +++++++++++++++
 3 files changed, 304 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/104412ee/core/src/test/java/org/apache/carbondata/core/reader/CarbonDictionaryReaderImplTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/reader/CarbonDictionaryReaderImplTest.java
b/core/src/test/java/org/apache/carbondata/core/reader/CarbonDictionaryReaderImplTest.java
new file mode 100644
index 0000000..452e0d1
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/reader/CarbonDictionaryReaderImplTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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.reader;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.carbondata.common.ext.PathFactory;
+import org.apache.carbondata.common.factory.CarbonCommonFactory;
+import org.apache.carbondata.core.carbon.CarbonTableIdentifier;
+import org.apache.carbondata.core.carbon.ColumnIdentifier;
+import org.apache.carbondata.core.reader.CarbonDictionaryColumnMetaChunk;
+import org.apache.carbondata.core.reader.CarbonDictionaryMetadataReaderImpl;
+import org.apache.carbondata.core.reader.CarbonDictionaryReaderImpl;
+import org.apache.carbondata.core.reader.ThriftReader;
+import org.apache.carbondata.core.service.PathService;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.thrift.TBase;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class CarbonDictionaryReaderImplTest {
+  private static CarbonTableIdentifier carbonTableIdentifier = null;
+  private static ColumnIdentifier columnIdentifier = null;
+
+  private static CarbonDictionaryReaderImpl carbonDictionaryReaderImpl = null;
+
+  @BeforeClass public static void setUp() throws Exception {
+    columnIdentifier = new ColumnIdentifier("1", null, null);
+    carbonTableIdentifier =
+        new CarbonTableIdentifier("dbName", "tableName", UUID.randomUUID().toString());
+    carbonDictionaryReaderImpl =
+        new CarbonDictionaryReaderImpl("storePath", carbonTableIdentifier, columnIdentifier);
+  }
+
+  @Test public void testRead() throws Exception {
+    new MockUp<CarbonCommonFactory>() {
+      @Mock public PathService getPathService() {
+
+        return new PathFactory();
+      }
+    };
+    new MockUp<CarbonDictionaryMetadataReaderImpl>() {
+      @Mock public List<CarbonDictionaryColumnMetaChunk> read() throws IOException
{
+        CarbonDictionaryColumnMetaChunk carbonDictionaryColumnMetaChunks =
+            new CarbonDictionaryColumnMetaChunk(1, 8, 60L, 120L, 20);
+        List<CarbonDictionaryColumnMetaChunk> carbonDictionaryColumnMetaChunksList
=
+            new ArrayList<CarbonDictionaryColumnMetaChunk>();
+        carbonDictionaryColumnMetaChunksList.add(carbonDictionaryColumnMetaChunks);
+        return carbonDictionaryColumnMetaChunksList;
+      }
+
+    };
+
+    new MockUp<ThriftReader>() {
+      @Mock public void setReadOffset(long bytesToSkip) throws IOException {
+
+      }
+
+    };
+    new MockUp<ThriftReader>() {
+      @Mock public void open() throws IOException {
+      }
+
+    };
+    new MockUp<ThriftReader>() {
+      @Mock public boolean hasNext() throws IOException {
+        return true;
+      }
+
+    };
+    new MockUp<CarbonDictionaryColumnMetaChunk>() {
+      @Mock public long getStart_offset() {
+        return 0L;
+      }
+    };
+    new MockUp<ThriftReader>() {
+      @Mock public TBase read() throws IOException {
+        List<ByteBuffer> byteBufferList = new ArrayList<ByteBuffer>();
+        ByteBuffer buf = ByteBuffer.allocate(2);
+        byteBufferList.add(buf);
+        return new org.apache.carbondata.format.ColumnDictionaryChunk(byteBufferList);
+
+      }
+
+    };
+    int expectedResult = 20;
+    int actualResult = carbonDictionaryReaderImpl.read().size();
+    assertTrue(actualResult == expectedResult);
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/104412ee/core/src/test/java/org/apache/carbondata/core/reader/CarbonIndexFileReaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/reader/CarbonIndexFileReaderTest.java
b/core/src/test/java/org/apache/carbondata/core/reader/CarbonIndexFileReaderTest.java
new file mode 100644
index 0000000..7990497
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/reader/CarbonIndexFileReaderTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.reader;
+
+import java.io.IOException;
+
+import org.apache.carbondata.core.reader.CarbonIndexFileReader;
+import org.apache.carbondata.core.reader.ThriftReader;
+import org.apache.carbondata.format.IndexHeader;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.thrift.TBase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class CarbonIndexFileReaderTest {
+  private static CarbonIndexFileReader carbonIndexFileReader = null;
+
+  @BeforeClass public static void setUp() throws IOException {
+    carbonIndexFileReader = new CarbonIndexFileReader();
+    new MockUp<ThriftReader>() {
+      @Mock public void open() throws IOException {
+
+      }
+
+    };
+    carbonIndexFileReader.openThriftReader("TestFile.Carbon");
+  }
+
+  @AfterClass public static void cleanUp() {
+    carbonIndexFileReader.closeThriftReader();
+  }
+
+  @Test public void testreadIndexHeader() throws IOException {
+    new MockUp<ThriftReader>() {
+      @Mock public TBase read(ThriftReader.TBaseCreator creator) throws IOException {
+        return new IndexHeader();
+
+      }
+
+    };
+
+    assertNotNull(carbonIndexFileReader.readIndexHeader());
+  }
+
+  @Test public void testHasNext() throws IOException {
+    new MockUp<ThriftReader>() {
+      @Mock public boolean hasNext() throws IOException {
+
+        return true;
+
+      }
+
+    };
+    assertTrue(carbonIndexFileReader.hasNext());
+  }
+
+  @Test public void testReadBlockInfo() throws IOException {
+    new MockUp<ThriftReader>() {
+      @Mock public TBase read(ThriftReader.TBaseCreator creator) throws IOException {
+        return new org.apache.carbondata.format.BlockIndex();
+
+      }
+
+    };
+    assertNotNull(carbonIndexFileReader.readBlockIndexInfo());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/104412ee/core/src/test/java/org/apache/carbondata/core/reader/ThriftReaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/reader/ThriftReaderTest.java b/core/src/test/java/org/apache/carbondata/core/reader/ThriftReaderTest.java
new file mode 100644
index 0000000..3fa41f8
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/reader/ThriftReaderTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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.reader;
+
+import java.io.IOException;
+
+import org.apache.carbondata.core.reader.ThriftReader;
+import org.apache.carbondata.format.ColumnDictionaryChunkMeta;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertNotNull;
+
+public class ThriftReaderTest {
+
+  private static ThriftReader thriftReader = null;
+
+  @BeforeClass public static void setup() {
+    thriftReader = new ThriftReader("TestFile.carbon");
+  }
+
+  @Test(expected = java.io.IOException.class) public void testReadForException()
+      throws IOException {
+    ThriftReader.TBaseCreator tBaseCreator = new ThriftReader.TBaseCreator() {
+      @Override public TBase create() {
+        return new ColumnDictionaryChunkMeta();
+      }
+
+    };
+    new MockUp<ColumnDictionaryChunkMeta>() {
+      @Mock public void read(org.apache.thrift.protocol.TProtocol iprot)
+          throws org.apache.thrift.TException {
+        throw new TException("TException Occur");
+      }
+
+    };
+    thriftReader = new ThriftReader("TestFile.carbon", tBaseCreator);
+    thriftReader.read();
+  }
+
+  @Test public void testReadWithTBaseCreator() throws IOException {
+    ThriftReader.TBaseCreator tBaseCreator = new ThriftReader.TBaseCreator() {
+      @Override public TBase create() {
+        return new ColumnDictionaryChunkMeta();
+      }
+    };
+    new MockUp<ColumnDictionaryChunkMeta>() {
+      @Mock public void read(org.apache.thrift.protocol.TProtocol iprot)
+          throws org.apache.thrift.TException {
+
+      }
+
+    };
+    assertNotNull(thriftReader.read(tBaseCreator));
+
+  }
+
+  @Test(expected = java.io.IOException.class) public void testReadWithTBaseCreatorForException()
+      throws IOException {
+    ThriftReader.TBaseCreator tBaseCreator = new ThriftReader.TBaseCreator() {
+      @Override public TBase create() {
+        return new ColumnDictionaryChunkMeta();
+      }
+    };
+    new MockUp<ColumnDictionaryChunkMeta>() {
+      @Mock public void read(org.apache.thrift.protocol.TProtocol iprot)
+          throws org.apache.thrift.TException {
+        throw new TException("TException Occur");
+      }
+
+    };
+    thriftReader.read(tBaseCreator);
+  }
+
+}


Mime
View raw message