Add unit tests for sortedIndexReader
diff --git a/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedForwardIndexReaderTest.java b/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedForwardIndexReaderTest.java
deleted file mode 100644
index f8cb677..0000000
--- a/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedForwardIndexReaderTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/**
- * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
- *
- * Licensed 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 com.linkedin.pinot.index.reader;
-
-import com.linkedin.pinot.common.segment.ReadMode;
-import com.linkedin.pinot.core.io.reader.impl.v1.SortedIndexReader;
-import com.linkedin.pinot.core.io.writer.impl.FixedByteSingleValueMultiColWriter;
-import com.linkedin.pinot.core.segment.memory.PinotDataBuffer;
-import java.io.File;
-import java.nio.channels.FileChannel;
-import java.util.Random;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-@Test
-public class SortedForwardIndexReaderTest {
-  private static Logger LOGGER = LoggerFactory.getLogger(SortedForwardIndexReaderTest.class);
-  public void testSimple() throws Exception {
-
-    int maxLength = 1000;
-    int cardinality = 100000;
-    File file = new File("test_sortef_fwd_index.dat");
-    file.delete();
-    int[] columnSizes = new int[] {
-        4, 4
-    };
-    FixedByteSingleValueMultiColWriter writer =
-        new FixedByteSingleValueMultiColWriter(file, cardinality, columnSizes.length, columnSizes);
-    Random random = new Random();
-    int[] startDocIdArray = new int[cardinality];
-    int[] endDocIdArray = new int[cardinality];
-    int prevEnd = -1;
-    int totalDocs = 0;
-    for (int i = 0; i < cardinality; i++) {
-      int length = random.nextInt(maxLength);
-      int start = prevEnd + 1;
-      int end = start + length;
-      startDocIdArray[i] = start;
-      endDocIdArray[i] = end;
-      writer.setInt(i, 0, start);
-      writer.setInt(i, 1, end);
-      prevEnd = end;
-      totalDocs += length;
-    }
-    writer.close();
-    PinotDataBuffer heapBuffer =
-        PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
-    SortedIndexReader reader = new SortedIndexReader(heapBuffer, cardinality);
-    // without using context
-    long start, end;
-    start = System.currentTimeMillis();
-    for (int i = 0; i < cardinality; i++) {
-      for (int docId = startDocIdArray[i]; docId <= endDocIdArray[i]; docId++) {
-        Assert.assertEquals(reader.getInt(docId), i);
-      }
-    }
-    end = System.currentTimeMillis();
-    System.out
-        .println("Took " + (end - start) + " to scan " + totalDocs + " docs without using context");
-    // with context
-    SortedIndexReader.Context context = reader.createContext();
-    start = System.currentTimeMillis();
-    for (int i = 0; i < cardinality; i++) {
-      for (int docId = startDocIdArray[i]; docId <= endDocIdArray[i]; docId++) {
-        Assert.assertEquals(reader.getInt(docId, context), i);
-      }
-    }
-    end = System.currentTimeMillis();
-    LOGGER.debug("Took " + (end - start) + " to scan " + totalDocs + " with context");
-
-    reader.close();
-    file.delete();
-    heapBuffer.close();
-  }
-}
diff --git a/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedIndexReaderTest.java b/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedIndexReaderTest.java
new file mode 100644
index 0000000..bca8b7b
--- /dev/null
+++ b/pinot-core/src/test/java/com/linkedin/pinot/index/reader/SortedIndexReaderTest.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright (C) 2014-2016 LinkedIn Corp. (pinot-core@linkedin.com)
+ *
+ * Licensed 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 com.linkedin.pinot.index.reader;
+
+import com.linkedin.pinot.common.segment.ReadMode;
+import com.linkedin.pinot.common.utils.Pairs;
+import com.linkedin.pinot.core.io.reader.impl.v1.SortedIndexReader;
+import com.linkedin.pinot.core.io.writer.impl.FixedByteSingleValueMultiColWriter;
+import com.linkedin.pinot.core.segment.memory.PinotDataBuffer;
+import java.io.File;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.util.Random;
+import org.apache.commons.io.FileUtils;
+import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+public class SortedIndexReaderTest {
+
+  private int _cardinality = 100000;
+  private final static File file  = new File(FileUtils.getTempDirectory(), "SortedIndex");
+  private int[] startDocIdArray;
+  private int[] endDocIdArray;
+
+  @BeforeClass
+  public void setUp() throws IOException {
+    int maxLength = 1000;
+    FileUtils.deleteQuietly(file);
+    int[] columnSizes = new int[] {
+        4, 4
+    };
+    FixedByteSingleValueMultiColWriter writer =
+        new FixedByteSingleValueMultiColWriter(file, _cardinality, columnSizes.length, columnSizes);
+    Random random = new Random();
+    startDocIdArray = new int[_cardinality];
+    endDocIdArray = new int[_cardinality];
+    int prevEnd = -1;
+    for (int i = 0; i < _cardinality; i++) {
+      int length = random.nextInt(maxLength);
+      int start = prevEnd + 1;
+      int end = start + length;
+      startDocIdArray[i] = start;
+      endDocIdArray[i] = end;
+      writer.setInt(i, 0, start);
+      writer.setInt(i, 1, end);
+      prevEnd = end;
+    }
+    writer.close();
+  }
+
+  @AfterClass
+  public void tearDown() {
+    FileUtils.deleteQuietly(file);
+  }
+
+  @Test
+  public void testSortedForwardIndex() throws Exception {
+    try (PinotDataBuffer heapBuffer =
+        PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
+        SortedIndexReader reader = new SortedIndexReader(heapBuffer, _cardinality)) {
+      // without using context
+      for (int i = 0; i < _cardinality; i++) {
+        for (int docId = startDocIdArray[i]; docId <= endDocIdArray[i]; docId++) {
+          Assert.assertEquals(reader.getInt(docId), i);
+        }
+      }
+      // with context
+      SortedIndexReader.Context context = reader.createContext();
+      for (int i = 0; i < _cardinality; i++) {
+        for (int docId = startDocIdArray[i]; docId <= endDocIdArray[i]; docId++) {
+          Assert.assertEquals(reader.getInt(docId, context), i);
+        }
+      }
+    }
+  }
+
+  @Test
+  public void testSortedInvertedIndex() throws IOException {
+    try (PinotDataBuffer heapBuffer =
+        PinotDataBuffer.fromFile(file, ReadMode.heap, FileChannel.MapMode.READ_ONLY, "testing");
+        SortedIndexReader reader = new SortedIndexReader(heapBuffer, _cardinality)) {
+      for (int i = 0; i < _cardinality; i++) {
+        Pairs.IntPair intPair = reader.getDocIds(i);
+        Assert.assertEquals(intPair.getLeft(), startDocIdArray[i]);
+        Assert.assertEquals(intPair.getRight(), endDocIdArray[i]);
+      }
+    }
+  }
+}
diff --git a/pinot-core/src/test/java/com/linkedin/pinot/operator/filter/SortedInvertedIndexBasedFilterOperatorTest.java b/pinot-core/src/test/java/com/linkedin/pinot/operator/filter/SortedInvertedIndexBasedFilterOperatorTest.java
index 582aa66..dd1e635 100644
--- a/pinot-core/src/test/java/com/linkedin/pinot/operator/filter/SortedInvertedIndexBasedFilterOperatorTest.java
+++ b/pinot-core/src/test/java/com/linkedin/pinot/operator/filter/SortedInvertedIndexBasedFilterOperatorTest.java
@@ -60,7 +60,7 @@
         new SortedInvertedIndexBasedFilterOperator(predicateEvaluator, ds, startDocId, endDocId);
 
 
-    Assert.assertEquals(sortedInvertedIndexBasedFilterOperator.isResultEmpty(), false);
+    Assert.assertFalse(sortedInvertedIndexBasedFilterOperator.isResultEmpty());
 
     BaseFilterBlock baseFilterBlock = sortedInvertedIndexBasedFilterOperator.nextBlock();
     FilterBlockDocIdSet filterBlockDocIdSet = baseFilterBlock.getFilteredBlockDocIdSet();
@@ -76,7 +76,7 @@
       num = blockDocIdIterator.next();
     }
     Assert.assertEquals(filterBlockDocIdSet.toString(), "[[1,5], [8,12]]");
-    Assert.assertTrue(expectedDocIds.equals(actualDocIds));
+    Assert.assertEquals(actualDocIds, expectedDocIds);
   }
 
   @Test
@@ -102,7 +102,7 @@
         new SortedInvertedIndexBasedFilterOperator(predicateEvaluator, ds, startDocId, endDocId);
 
 
-    Assert.assertEquals(sortedInvertedIndexBasedFilterOperator.isResultEmpty(), false);
+    Assert.assertFalse(sortedInvertedIndexBasedFilterOperator.isResultEmpty());
 
     BaseFilterBlock baseFilterBlock = sortedInvertedIndexBasedFilterOperator.nextBlock();
     FilterBlockDocIdSet filterBlockDocIdSet = baseFilterBlock.getFilteredBlockDocIdSet();
@@ -118,6 +118,6 @@
       num = blockDocIdIterator.next();
     }
     Assert.assertEquals(filterBlockDocIdSet.toString(), "[[0,0], [6,7], [13,15]]");
-    Assert.assertTrue(expectedDocIds.equals(actualDocIds));
+    Assert.assertEquals(actualDocIds, expectedDocIds);
   }
 }