|
@@ -33,6 +33,7 @@ import org.apache.hadoop.mapred.nativetask.NativeRuntime;
|
|
|
import org.apache.hadoop.mapred.nativetask.testutil.ResultVerifier;
|
|
|
import org.apache.hadoop.mapred.nativetask.testutil.ScenarioConfiguration;
|
|
|
import org.apache.hadoop.mapred.nativetask.testutil.TestConstants;
|
|
|
+import org.junit.AfterClass;
|
|
|
import org.apache.hadoop.util.NativeCodeLoader;
|
|
|
import org.junit.Assume;
|
|
|
import org.junit.Before;
|
|
@@ -47,97 +48,90 @@ public class LargeKVTest {
|
|
|
Assume.assumeTrue(NativeRuntime.isNativeLibraryLoaded());
|
|
|
}
|
|
|
|
|
|
+ private static Configuration nativeConf = ScenarioConfiguration.getNativeConfiguration();
|
|
|
+ private static Configuration normalConf = ScenarioConfiguration.getNormalConfiguration();
|
|
|
+ static {
|
|
|
+ nativeConf.addResource(TestConstants.KVTEST_CONF_PATH);
|
|
|
+ nativeConf.set(TestConstants.NATIVETASK_KVTEST_CREATEFILE, "true");
|
|
|
+ normalConf.addResource(TestConstants.KVTEST_CONF_PATH);
|
|
|
+ normalConf.set(TestConstants.NATIVETASK_KVTEST_CREATEFILE, "false");
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
- public void testKeySize() {
|
|
|
+ public void testKeySize() throws Exception {
|
|
|
runKVSizeTests(Text.class, IntWritable.class);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void testValueSize() {
|
|
|
+ public void testValueSize() throws Exception {
|
|
|
runKVSizeTests(IntWritable.class, Text.class);
|
|
|
}
|
|
|
|
|
|
- private static Configuration nativeConf = ScenarioConfiguration.getNativeConfiguration();
|
|
|
- private static Configuration normalConf = ScenarioConfiguration.getNormalConfiguration();
|
|
|
- static {
|
|
|
- nativeConf.addResource(TestConstants.KVTEST_CONF_PATH);
|
|
|
- nativeConf.set(TestConstants.NATIVETASK_KVTEST_CREATEFILE, "true");
|
|
|
- normalConf.addResource(TestConstants.KVTEST_CONF_PATH);
|
|
|
- normalConf.set(TestConstants.NATIVETASK_KVTEST_CREATEFILE, "false");
|
|
|
+ @AfterClass
|
|
|
+ public static void cleanUp() throws IOException {
|
|
|
+ final FileSystem fs = FileSystem.get(new ScenarioConfiguration());
|
|
|
+ fs.delete(new Path(TestConstants.NATIVETASK_KVTEST_DIR), true);
|
|
|
+ fs.close();
|
|
|
}
|
|
|
|
|
|
- public void runKVSizeTests(Class<?> keyClass, Class<?> valueClass) {
|
|
|
+ public void runKVSizeTests(Class<?> keyClass, Class<?> valueClass) throws Exception {
|
|
|
if (!keyClass.equals(Text.class) && !valueClass.equals(Text.class)) {
|
|
|
return;
|
|
|
}
|
|
|
final int deafult_KVSize_Maximum = 1 << 22; // 4M
|
|
|
final int KVSize_Maximu = normalConf.getInt(TestConstants.NATIVETASK_KVSIZE_MAX_LARGEKV_TEST,
|
|
|
deafult_KVSize_Maximum);
|
|
|
- try {
|
|
|
|
|
|
- for (int i = 65536; i <= KVSize_Maximu; i *= 4) {
|
|
|
- int min = i / 4;
|
|
|
- int max = i;
|
|
|
- nativeConf.set(TestConstants.NATIVETASK_KVSIZE_MIN, String.valueOf(min));
|
|
|
- nativeConf.set(TestConstants.NATIVETASK_KVSIZE_MAX, String.valueOf(max));
|
|
|
- normalConf.set(TestConstants.NATIVETASK_KVSIZE_MIN, String.valueOf(min));
|
|
|
- normalConf.set(TestConstants.NATIVETASK_KVSIZE_MAX, String.valueOf(max));
|
|
|
+ for (int i = 65536; i <= KVSize_Maximu; i *= 4) {
|
|
|
+ int min = i / 4;
|
|
|
+ int max = i;
|
|
|
+ nativeConf.set(TestConstants.NATIVETASK_KVSIZE_MIN, String.valueOf(min));
|
|
|
+ nativeConf.set(TestConstants.NATIVETASK_KVSIZE_MAX, String.valueOf(max));
|
|
|
+ normalConf.set(TestConstants.NATIVETASK_KVSIZE_MIN, String.valueOf(min));
|
|
|
+ normalConf.set(TestConstants.NATIVETASK_KVSIZE_MAX, String.valueOf(max));
|
|
|
|
|
|
- LOG.info("===KV Size Test: min size: " + min + ", max size: " + max + ", keyClass: "
|
|
|
- + keyClass.getName() + ", valueClass: " + valueClass.getName());
|
|
|
+ LOG.info("===KV Size Test: min size: " + min + ", max size: " + max + ", keyClass: "
|
|
|
+ + keyClass.getName() + ", valueClass: " + valueClass.getName());
|
|
|
|
|
|
- final String nativeOutPut = runNativeLargeKVTest("Test Large Value Size:" + String.valueOf(i), keyClass,
|
|
|
- valueClass, nativeConf);
|
|
|
- final String normalOutPut = this.runNormalLargeKVTest("Test Large Key Size:" + String.valueOf(i), keyClass,
|
|
|
- valueClass, normalConf);
|
|
|
- final boolean compareRet = ResultVerifier.verify(normalOutPut, nativeOutPut);
|
|
|
- final String reason = "keytype: " + keyClass.getName() + ", valuetype: " + valueClass.getName()
|
|
|
- + ", failed with " + (keyClass.equals(Text.class) ? "key" : "value") + ", min size: " + min
|
|
|
- + ", max size: " + max + ", normal out: " + normalOutPut + ", native Out: " + nativeOutPut;
|
|
|
- assertEquals(reason, true, compareRet);
|
|
|
- }
|
|
|
- } catch (final Exception e) {
|
|
|
- // TODO: handle exception
|
|
|
- // assertEquals("test run exception:", null, e);
|
|
|
- e.printStackTrace();
|
|
|
+ final String nativeOutPut = runNativeLargeKVTest("Test Large Value Size:" + String.valueOf(i), keyClass,
|
|
|
+ valueClass, nativeConf);
|
|
|
+ final String normalOutPut = this.runNormalLargeKVTest("Test Large Key Size:" + String.valueOf(i), keyClass,
|
|
|
+ valueClass, normalConf);
|
|
|
+ final boolean compareRet = ResultVerifier.verify(normalOutPut, nativeOutPut);
|
|
|
+ final String reason = "keytype: " + keyClass.getName() + ", valuetype: " + valueClass.getName()
|
|
|
+ + ", failed with " + (keyClass.equals(Text.class) ? "key" : "value") + ", min size: " + min
|
|
|
+ + ", max size: " + max + ", normal out: " + normalOutPut + ", native Out: " + nativeOutPut;
|
|
|
+ assertEquals(reason, true, compareRet);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private String runNativeLargeKVTest(String jobname, Class<?> keyclass, Class<?> valueclass, Configuration conf)
|
|
|
throws Exception {
|
|
|
- final String inputpath = conf.get(TestConstants.NATIVETASK_KVTEST_INPUTDIR) + "/LargeKV/" + keyclass.getName()
|
|
|
- + "/" + valueclass.getName();
|
|
|
- final String outputpath = conf.get(TestConstants.NATIVETASK_KVTEST_OUTPUTDIR) + "/LargeKV/" + keyclass.getName()
|
|
|
- + "/" + valueclass.getName();
|
|
|
+ final String inputpath = TestConstants.NATIVETASK_KVTEST_INPUTDIR + "/LargeKV/"
|
|
|
+ + keyclass.getName() + "/" + valueclass.getName();
|
|
|
+ final String outputpath = TestConstants.NATIVETASK_KVTEST_NATIVE_OUTPUTDIR + "/LargeKV/"
|
|
|
+ + keyclass.getName() + "/" + valueclass.getName();
|
|
|
// if output file exists ,then delete it
|
|
|
final FileSystem fs = FileSystem.get(conf);
|
|
|
fs.delete(new Path(outputpath), true);
|
|
|
fs.close();
|
|
|
- try {
|
|
|
- final KVJob keyJob = new KVJob(jobname, conf, keyclass, valueclass, inputpath, outputpath);
|
|
|
- assertTrue("job should complete successfully", keyJob.runJob());
|
|
|
- } catch (final Exception e) {
|
|
|
- return "normal testcase run time error.";
|
|
|
- }
|
|
|
+ final KVJob keyJob = new KVJob(jobname, conf, keyclass, valueclass, inputpath, outputpath);
|
|
|
+ assertTrue("job should complete successfully", keyJob.runJob());
|
|
|
return outputpath;
|
|
|
}
|
|
|
|
|
|
private String runNormalLargeKVTest(String jobname, Class<?> keyclass, Class<?> valueclass, Configuration conf)
|
|
|
- throws IOException {
|
|
|
- final String inputpath = conf.get(TestConstants.NATIVETASK_KVTEST_INPUTDIR) + "/LargeKV/" + keyclass.getName()
|
|
|
- + "/" + valueclass.getName();
|
|
|
- final String outputpath = conf.get(TestConstants.NATIVETASK_KVTEST_NORMAL_OUTPUTDIR) + "/LargeKV/"
|
|
|
- + keyclass.getName() + "/" + valueclass.getName();
|
|
|
+ throws Exception {
|
|
|
+ final String inputpath = TestConstants.NATIVETASK_KVTEST_INPUTDIR + "/LargeKV/"
|
|
|
+ + keyclass.getName() + "/" + valueclass.getName();
|
|
|
+ final String outputpath = TestConstants.NATIVETASK_KVTEST_NORMAL_OUTPUTDIR + "/LargeKV/"
|
|
|
+ + keyclass.getName() + "/" + valueclass.getName();
|
|
|
// if output file exists ,then delete it
|
|
|
final FileSystem fs = FileSystem.get(conf);
|
|
|
fs.delete(new Path(outputpath), true);
|
|
|
fs.close();
|
|
|
- try {
|
|
|
- final KVJob keyJob = new KVJob(jobname, conf, keyclass, valueclass, inputpath, outputpath);
|
|
|
- assertTrue("job should complete successfully", keyJob.runJob());
|
|
|
- } catch (final Exception e) {
|
|
|
- return "normal testcase run time error.";
|
|
|
- }
|
|
|
+ final KVJob keyJob = new KVJob(jobname, conf, keyclass, valueclass, inputpath, outputpath);
|
|
|
+ assertTrue("job should complete successfully", keyJob.runJob());
|
|
|
return outputpath;
|
|
|
}
|
|
|
}
|