|
@@ -38,12 +38,12 @@ public class TestMapFile extends TestCase {
|
|
|
getName() + ".mapfile");
|
|
|
FileSystem fs = FileSystem.getLocal(conf);
|
|
|
Path qualifiedDirName = fs.makeQualified(dirName);
|
|
|
- // Make an index entry for each insertion.
|
|
|
- MapFile.Writer.setIndexInterval(conf, 1);
|
|
|
+ // Make an index entry for every third insertion.
|
|
|
+ MapFile.Writer.setIndexInterval(conf, 3);
|
|
|
MapFile.Writer writer = new MapFile.Writer(conf, fs,
|
|
|
qualifiedDirName.toString(), Text.class, Text.class);
|
|
|
// Assert that the index interval is 1
|
|
|
- assertEquals(1, writer.getIndexInterval());
|
|
|
+ assertEquals(3, writer.getIndexInterval());
|
|
|
// Add entries up to 100 in intervals of ten.
|
|
|
final int FIRST_KEY = 10;
|
|
|
for (int i = FIRST_KEY; i < 100; i += 10) {
|
|
@@ -59,28 +59,34 @@ public class TestMapFile extends TestCase {
|
|
|
Text value = new Text();
|
|
|
Text closest = (Text)reader.getClosest(key, value);
|
|
|
// Assert that closest after 55 is 60
|
|
|
- assertTrue(closest.equals(new Text("60")));
|
|
|
+ assertEquals(new Text("60"), closest);
|
|
|
// Get closest that falls before the passed key: 50
|
|
|
closest = (Text)reader.getClosest(key, value, true);
|
|
|
- assertTrue(closest.equals(new Text("50")));
|
|
|
+ assertEquals(new Text("50"), closest);
|
|
|
// Test get closest when we pass explicit key
|
|
|
final Text TWENTY = new Text("20");
|
|
|
closest = (Text)reader.getClosest(TWENTY, value);
|
|
|
- assertTrue(closest.equals(new Text(TWENTY)));
|
|
|
+ assertEquals(TWENTY, closest);
|
|
|
closest = (Text)reader.getClosest(TWENTY, value, true);
|
|
|
- assertTrue(closest.equals(new Text(TWENTY)));
|
|
|
+ assertEquals(TWENTY, closest);
|
|
|
// Test what happens at boundaries. Assert if searching a key that is
|
|
|
// less than first key in the mapfile, that the first key is returned.
|
|
|
key = new Text("00");
|
|
|
closest = (Text)reader.getClosest(key, value);
|
|
|
- assertEquals(Integer.parseInt(closest.toString()), FIRST_KEY);
|
|
|
+ assertEquals(FIRST_KEY, Integer.parseInt(closest.toString()));
|
|
|
+
|
|
|
+ // If we're looking for the first key before, and we pass in a key before
|
|
|
+ // the first key in the file, we should get null
|
|
|
closest = (Text)reader.getClosest(key, value, true);
|
|
|
- assertEquals(Integer.parseInt(closest.toString()), FIRST_KEY);
|
|
|
+ assertNull(closest);
|
|
|
+
|
|
|
// Assert that null is returned if key is > last entry in mapfile.
|
|
|
key = new Text("99");
|
|
|
closest = (Text)reader.getClosest(key, value);
|
|
|
assertNull(closest);
|
|
|
+
|
|
|
+ // If we were looking for the key before, we should get the last key
|
|
|
closest = (Text)reader.getClosest(key, value, true);
|
|
|
- assertNull(closest);
|
|
|
+ assertEquals(new Text("90"), closest);
|
|
|
}
|
|
|
}
|