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:16:34 UTC

[1/2] incubator-carbondata git commit: added test cases for datastorage.impl module

Repository: incubator-carbondata
Updated Branches:
  refs/heads/master ddeb5e121 -> 9e0982ad0


added test cases for datastorage.impl module

minor changes

refactored the test code


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

Branch: refs/heads/master
Commit: 9e66ff7e9bb571de5e73f3ff5579d629d22f83fc
Parents: ddeb5e1
Author: anubhav100 <an...@knoldus.in>
Authored: Mon Dec 5 12:40:52 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 11:45:31 2016 +0530

----------------------------------------------------------------------
 .../impl/CompressedDataMeasureWrapperTest.java  |  47 ++++++
 .../store/impl/DFSFileHolderImplUnitTest.java   | 157 ++++++++++++++++++
 .../store/impl/FileFactoryImplUnitTest.java     | 147 +++++++++++++++++
 .../store/impl/FileHolderImplUnitTest.java      | 158 +++++++++++++++++++
 .../MemoryMappedFileHolderImplUnitTest.java     | 137 ++++++++++++++++
 5 files changed, 646 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/9e66ff7e/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/CompressedDataMeasureWrapperTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/CompressedDataMeasureWrapperTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/CompressedDataMeasureWrapperTest.java
new file mode 100644
index 0000000..2bd99eb
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/CompressedDataMeasureWrapperTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.datastorage.filesystem.store.impl;
+
+import org.apache.carbondata.core.datastorage.store.dataholder.CarbonReadDataHolder;
+import org.apache.carbondata.core.datastorage.store.impl.CompressedDataMeasureDataWrapper;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+
+public class CompressedDataMeasureWrapperTest {
+  private static CompressedDataMeasureDataWrapper compressedDataMeasureDataWrapper;
+  private static CarbonReadDataHolder carbonReadDataHolder;
+  private static CarbonReadDataHolder[] carbonReadDataHolders;
+
+  @BeforeClass public static void setUp() {
+    carbonReadDataHolder = new CarbonReadDataHolder();
+    carbonReadDataHolders = new CarbonReadDataHolder[] { carbonReadDataHolder };
+
+  }
+
+  @Test public void testGetValues() {
+    compressedDataMeasureDataWrapper = new CompressedDataMeasureDataWrapper(carbonReadDataHolders);
+    int expected = 1;
+    int actual = compressedDataMeasureDataWrapper.getValues().length;
+    assertEquals(expected, actual);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/9e66ff7e/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/DFSFileHolderImplUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/DFSFileHolderImplUnitTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/DFSFileHolderImplUnitTest.java
new file mode 100644
index 0000000..38d9f44
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/DFSFileHolderImplUnitTest.java
@@ -0,0 +1,157 @@
+/*
+ * 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.datastorage.filesystem.store.impl;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.apache.carbondata.core.datastorage.store.impl.DFSFileHolderImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.pentaho.di.core.util.Assert.assertNull;
+
+public class DFSFileHolderImplUnitTest {
+
+  private static DFSFileHolderImpl dfsFileHolder;
+  private static String fileName;
+  private static String fileNameWithEmptyContent;
+  private static File file;
+  private static File fileWithEmptyContent;
+
+  @BeforeClass public static void setup() {
+    dfsFileHolder = new DFSFileHolderImpl();
+    file = new File("Test.carbondata");
+    fileWithEmptyContent = new File("TestEXception.carbondata");
+
+    if (!file.exists()) try {
+      file.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    if (!fileWithEmptyContent.exists()) try {
+      fileWithEmptyContent.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    try {
+      FileOutputStream of = new FileOutputStream(file, true);
+      BufferedWriter br = new BufferedWriter(new OutputStreamWriter(of, "UTF-8"));
+      br.write("Hello World");
+      br.close();
+    } catch (Exception e) {
+      e.getMessage();
+    }
+    fileName = file.getAbsolutePath();
+    fileNameWithEmptyContent = fileWithEmptyContent.getAbsolutePath();
+  }
+
+  @AfterClass public static void tearDown() {
+    file.delete();
+    fileWithEmptyContent.delete();
+    dfsFileHolder.finish();
+  }
+
+  @Test public void testReadByteArray() {
+    byte[] result = dfsFileHolder.readByteArray(fileName, 1);
+    byte[] expected_result = new byte[] { 72 };
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadByteArrayWithFilePath() {
+    byte[] result = dfsFileHolder.readByteArray(fileName, 2L, 2);
+    byte[] expected_result = { 108, 108 };
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadLong() {
+    long actualResult = dfsFileHolder.readLong(fileName, 1L);
+    long expectedResult = 7308335519855243122L;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadLongForIoException() throws IOException {
+    dfsFileHolder.readLong(fileNameWithEmptyContent, 1L);
+
+  }
+
+  @Test public void testReadIntForIoException() throws IOException {
+    dfsFileHolder.readInt(fileNameWithEmptyContent, 1L);
+  }
+
+  @Test public void testReadInt() {
+    int actualResult = dfsFileHolder.readInt(fileName, 1L);
+    int expectedResult = 1701604463;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadIntWithFileName() {
+    int actualResult = dfsFileHolder.readInt(fileName);
+    int expectedResult = 1701604463;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadIntWithFileNameForIOException() {
+    dfsFileHolder.readInt(fileNameWithEmptyContent);
+
+  }
+
+  @Test public void testDouble() {
+    double actualResult = dfsFileHolder.readDouble(fileName, 1L);
+    double expectedResult = 7.3083355198552433E18;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testDoubleForIoException() throws IOException {
+    dfsFileHolder.readDouble(fileNameWithEmptyContent, 1L);
+
+  }
+
+  @Test public void testDoubleForIoExceptionwithUpdateCache() throws Exception {
+    new MockUp<FileSystem>() {
+      @SuppressWarnings("unused") @Mock public FSDataInputStream open(Path file)
+          throws IOException {
+        throw new IOException();
+      }
+
+    };
+    String expected = null;
+    try {
+      dfsFileHolder.readDouble(fileName, 1L);
+    } catch (Exception e) {
+      assertNull(e.getMessage());
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/9e66ff7e/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileFactoryImplUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileFactoryImplUnitTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileFactoryImplUnitTest.java
new file mode 100644
index 0000000..62de46b
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileFactoryImplUnitTest.java
@@ -0,0 +1,147 @@
+/*
+ * 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.datastorage.filesystem.store.impl;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.carbondata.core.datastorage.store.impl.FileFactory;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class FileFactoryImplUnitTest {
+
+  private static String filePath;
+
+  @AfterClass public static void tearDown() {
+    File file = new File(filePath);
+    if (file.exists()) {
+      file.delete();
+    }
+  }
+
+  @BeforeClass public static void setUp() {
+    filePath = "TestFileFactory.carbondata";
+  }
+
+  @Test public void testFileExistsForVIEWFSType() throws IOException {
+    FileFactory.isFileExist("fakefilePath", FileFactory.FileType.VIEWFS);
+  }
+
+  @Test public void testFileExistsForDefaultType() throws IOException {
+    FileFactory.isFileExist("fakefilePath", FileFactory.FileType.LOCAL);
+  }
+
+  @Test public void testFileExistsForDefaultTypeWithPerformFileCheck() throws IOException {
+    assertTrue(FileFactory.isFileExist(filePath, FileFactory.FileType.LOCAL, true));
+  }
+
+  @Test public void testFileExistsForDefaultTypeWithOutPerformFileCheck() throws IOException {
+    assertFalse(FileFactory.isFileExist("fakefilePath", FileFactory.FileType.LOCAL, false));
+  }
+
+  @Test public void testFileExistsForVIEWFSTypeWithPerformFileCheck() throws IOException {
+    assertTrue(FileFactory.isFileExist(filePath, FileFactory.FileType.VIEWFS, true));
+  }
+
+  @Test public void testFileExistsForVIEWFSTypeWithOutPerformFileCheck() throws IOException {
+    assertFalse(FileFactory.isFileExist("fakefilePath", FileFactory.FileType.VIEWFS, false));
+  }
+
+  @Test public void testCreateNewFileWithDefaultFileType() throws IOException {
+    tearDown();
+    assertTrue(FileFactory.createNewFile(filePath, FileFactory.FileType.LOCAL));
+  }
+
+  @Test public void testCreateNewLockFileWithDefaultFileType() throws IOException {
+    tearDown();
+    assertTrue(FileFactory.createNewLockFile(filePath, FileFactory.FileType.LOCAL));
+  }
+
+  @Test public void testCreateNewLockFileWithViewFsFileType() throws IOException {
+    tearDown();
+    assertTrue(FileFactory.createNewLockFile(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void testCreateNewLockFileWithViewFsFileTypeWhenFileExists() throws IOException {
+    assertFalse(FileFactory.createNewLockFile(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void testCreateNewFileWithDefaultFileTypeWhenFileExists() throws IOException {
+    assertFalse(FileFactory.createNewFile(filePath, FileFactory.FileType.LOCAL));
+  }
+
+  @Test public void testCreateNewFileWithVIEWFSFileType() throws IOException {
+    File file = new File(filePath);
+    if (file.exists()) {
+      file.delete();
+    }
+    assertTrue(FileFactory.createNewFile(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void testCreateNewFileWithVIEWFSFileTypeWhenFileExists() throws IOException {
+    assertFalse(FileFactory.createNewFile(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void testMkDirWithVIEWFSFileType() throws IOException {
+    new MockUp<FileSystem>() {
+      @SuppressWarnings("unused") @Mock public boolean mkdirs(Path file) throws IOException {
+        {
+          return true;
+        }
+      }
+    };
+    tearDown();
+    assertTrue(FileFactory.mkdirs(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void testGetDataOutputStreamUsingAppendeForException() {
+    try {
+      FileFactory.getDataOutputStreamUsingAppend(filePath, FileFactory.FileType.VIEWFS);
+    } catch (Exception exception) {
+      assertEquals("Not supported", exception.getMessage());
+    }
+  }
+
+  @Test public void getDataOutputStreamForVIEWFSType() throws IOException {
+    assertNotNull(FileFactory.getDataOutputStream(filePath, FileFactory.FileType.VIEWFS));
+  }
+
+  @Test public void getDataOutputStreamForLocalType() throws IOException {
+    assertNotNull(FileFactory.getDataOutputStream(filePath, FileFactory.FileType.LOCAL));
+  }
+
+  @Test public void testGetCarbonFile() throws IOException {
+    FileFactory.getDataOutputStream(filePath, FileFactory.FileType.VIEWFS);
+    assertNotNull(FileFactory.getCarbonFile(filePath, FileFactory.FileType.HDFS));
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/9e66ff7e/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileHolderImplUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileHolderImplUnitTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileHolderImplUnitTest.java
new file mode 100644
index 0000000..127f2e0
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/FileHolderImplUnitTest.java
@@ -0,0 +1,158 @@
+/*
+ * 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.datastorage.filesystem.store.impl;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.apache.carbondata.core.datastorage.store.impl.FileHolderImpl;
+
+import mockit.Mock;
+import mockit.MockUp;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.pentaho.di.core.util.Assert.assertNull;
+
+public class FileHolderImplUnitTest {
+
+  private static FileHolderImpl fileHolder;
+  private static FileHolderImpl fileHolderWithCapacity;
+  private static String fileName;
+  private static String fileNameWithEmptyContent;
+  private static File file;
+  private static File fileWithEmptyContent;
+
+  @BeforeClass public static void setup() {
+    fileHolder = new FileHolderImpl();
+    fileHolderWithCapacity = new FileHolderImpl(50);
+    file = new File("Test.carbondata");
+    fileWithEmptyContent = new File("TestEXception.carbondata");
+
+    if (!file.exists()) try {
+      file.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    if (!fileWithEmptyContent.exists()) try {
+      fileWithEmptyContent.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    try {
+      FileOutputStream of = new FileOutputStream(file, true);
+      BufferedWriter br = new BufferedWriter(new OutputStreamWriter(of, "UTF-8"));
+      br.write("Hello World");
+      br.close();
+    } catch (Exception e) {
+      e.getMessage();
+    }
+    fileName = file.getAbsolutePath();
+    fileNameWithEmptyContent = fileWithEmptyContent.getAbsolutePath();
+  }
+
+  @AfterClass public static void tearDown() {
+    file.delete();
+    fileWithEmptyContent.delete();
+    fileHolder.finish();
+  }
+
+  @Test public void testReadByteArray() {
+    byte[] result = fileHolder.readByteArray(fileName, 1);
+    byte[] expected_result = new byte[] { 72 };
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadByteArrayWithFilePath() {
+    byte[] result = fileHolder.readByteArray(fileName, 2L, 2);
+    byte[] expected_result = { 108, 108 };
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadLong() {
+    long actualResult = fileHolder.readLong(fileName, 1L);
+    long expectedResult = 7308335519855243122L;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadLongForIoException() throws IOException {
+    fileHolder.readLong(fileNameWithEmptyContent, 1L);
+
+  }
+
+  @Test public void testReadIntForIoException() throws IOException {
+    fileHolder.readInt(fileNameWithEmptyContent, 1L);
+  }
+
+  @Test public void testReadInt() {
+    int actualResult = fileHolder.readInt(fileName, 1L);
+    int expectedResult = 1701604463;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadIntWithFileName() {
+    int actualResult = fileHolder.readInt(fileName);
+    int expectedResult = 1701604463;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadIntWithFileNameForIOException() {
+    fileHolder.readInt(fileNameWithEmptyContent);
+
+  }
+
+  @Test public void testDouble() {
+    double actualResult = fileHolder.readDouble(fileName, 1L);
+    double expectedResult = 7.3083355198552433E18;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testDoubleForIoException() throws IOException {
+    fileHolder.readDouble(fileNameWithEmptyContent, 1L);
+
+  }
+
+  @Test public void testDoubleForIoExceptionwithUpdateCache() throws Exception {
+    new MockUp<FileSystem>() {
+      @SuppressWarnings("unused") @Mock public FSDataInputStream open(Path file)
+          throws IOException {
+        throw new IOException();
+      }
+
+    };
+    try {
+      fileHolder.readDouble(fileName, 1L);
+    } catch (Exception e) {
+      assertNull(e.getMessage());
+    }
+
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/9e66ff7e/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/MemoryMappedFileHolderImplUnitTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/MemoryMappedFileHolderImplUnitTest.java b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/MemoryMappedFileHolderImplUnitTest.java
new file mode 100644
index 0000000..29ca475
--- /dev/null
+++ b/core/src/test/java/org/apache/carbondata/core/carbon/datastorage/filesystem/store/impl/MemoryMappedFileHolderImplUnitTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.datastorage.filesystem.store.impl;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+
+import org.apache.carbondata.core.datastorage.store.impl.MemoryMappedFileHolderImpl;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+public class MemoryMappedFileHolderImplUnitTest {
+
+  private static MemoryMappedFileHolderImpl memoryMappedFileHolder = null;
+  private static MemoryMappedFileHolderImpl memoryMappedFileHolderWithCapacity = null;
+  private static String fileName = null;
+  private static String fileWithEmptyContentName = null;
+  private static File file = null;
+  private static File fileWithEmptyContent = null;
+
+  @BeforeClass public static void setup() {
+    memoryMappedFileHolder = new MemoryMappedFileHolderImpl();
+    memoryMappedFileHolderWithCapacity = new MemoryMappedFileHolderImpl(50);
+    file = new File("Test.carbondata");
+    fileWithEmptyContent = new File("TestEXception.carbondata");
+
+    if (!file.exists()) try {
+      file.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    if (!fileWithEmptyContent.exists()) try {
+      fileWithEmptyContent.createNewFile();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    try {
+      FileOutputStream of = new FileOutputStream(file, true);
+      BufferedWriter br = new BufferedWriter(new OutputStreamWriter(of, "UTF-8"));
+      br.write("Hello World");
+      br.close();
+    } catch (Exception e) {
+      e.getMessage();
+    }
+    fileName = file.getAbsolutePath();
+    fileWithEmptyContentName = fileWithEmptyContent.getAbsolutePath();
+
+  }
+
+  @AfterClass public static void tearDown() {
+    file.delete();
+    fileWithEmptyContent.delete();
+    memoryMappedFileHolder.finish();
+  }
+
+  @Test public void testReadByteArray() {
+    byte[] result = memoryMappedFileHolder.readByteArray(fileName, 1);
+    byte[] expected_result = new byte[] { 72 };
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadByteArrayWithFilePath() {
+
+    final byte[] result = memoryMappedFileHolder.readByteArray(fileName, 0L, 6);
+    final byte[] expected_result = { 32, 87, 111, 114, 108, 100 };
+
+    assertThat(result, is(equalTo(expected_result)));
+  }
+
+  @Test public void testReadLong() {
+
+    long actualResult = memoryMappedFileHolderWithCapacity.readLong(fileName, 0L);
+    long expectedResult = 5216694956355245935L;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadInt() {
+    memoryMappedFileHolder = new MemoryMappedFileHolderImpl();
+
+    int actualResult = memoryMappedFileHolder.readInt(fileName, 0L);
+    int expectedResult = 1214606444;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testReadIntWithFileName() {
+
+    int actualResult = memoryMappedFileHolder.readInt(fileName);
+    int expectedResult = 1701604463;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testDouble() {
+    memoryMappedFileHolder = new MemoryMappedFileHolderImpl();
+
+    double actualResult = memoryMappedFileHolder.readDouble(fileName, 0L);
+    double expectedResult = 5.2166949563552461E18;
+    assertThat(actualResult, is(equalTo(expectedResult)));
+  }
+
+  @Test public void testDoubleForIoExceptionwithUpdateCache() throws Exception {
+
+    String expected = null;
+    try {
+      memoryMappedFileHolder.readDouble(fileName, 0L);
+    } catch (Exception e) {
+      assertEquals(e.getMessage(), expected);
+    }
+
+  }
+
+}


[2/2] incubator-carbondata git commit: [CARBONDATA-474] Added test Cases for Datastorage.Impl Module This closes #397

Posted by ra...@apache.org.
[CARBONDATA-474] Added test Cases for Datastorage.Impl Module This closes #397


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

Branch: refs/heads/master
Commit: 9e0982ad0458c3e716c534a5edbce2e62bb732d1
Parents: ddeb5e1 9e66ff7
Author: ravipesala <ra...@gmail.com>
Authored: Mon Dec 12 11:46:15 2016 +0530
Committer: ravipesala <ra...@gmail.com>
Committed: Mon Dec 12 11:46:15 2016 +0530

----------------------------------------------------------------------
 .../impl/CompressedDataMeasureWrapperTest.java  |  47 ++++++
 .../store/impl/DFSFileHolderImplUnitTest.java   | 157 ++++++++++++++++++
 .../store/impl/FileFactoryImplUnitTest.java     | 147 +++++++++++++++++
 .../store/impl/FileHolderImplUnitTest.java      | 158 +++++++++++++++++++
 .../MemoryMappedFileHolderImplUnitTest.java     | 137 ++++++++++++++++
 5 files changed, 646 insertions(+)
----------------------------------------------------------------------