Hadoop下的程序测试及调试信息

2019-03-28 14:17|来源: 网络

主要介绍下0.20版本下Hadoop的调试、计数器、调试信息输出等内容。

Hadoop0.21.0源码流程分析 http://www.linuxidc.com/Linux/2011-11/47668.htm

使用VMware安装Hadoop全过程  http://www.linuxidc.com/Linux/2011-08/40153.htm

搭建Hadoop环境(在Winodws环境下用虚拟机虚拟两个Ubuntu系统进行搭建) http://www.linuxidc.com/Linux/2011-12/48894.htm

相信很多人学习hadoop都是从hadoop权威指南开始的,但权威指南使用的hadoop版本是0.19版本的,而有部分人(其中包括我)使用的0.20版本的。相信大家都知道0.20版本相对于0.19版本有了重大的改变。提供了一系列新的API。具体哪些我这里就不具体说了。其中一个跟测试、调试密切相关的就是在0.20版本出现了Context  object(上下文对象).所以本篇日志就记录一下我在0.20版本下的测试、调试程序。这里有要特别提示下,这些方法都是我自己摸索的,不敢保证一定效果最好或者最简洁,比如计数器那个我也见过其他实现方法。所以如果有错请大家指出。先谢谢了。

先来说说测试,老规矩直接上代码,注释在代码里:

  1. public class TestMapper {  
  2.     @Test  
  3.     public void processReduce() throws IOException{  
  4.         wordcountReduce reuder = new wordcountReduce();  //reduce测试   
  5.         LongWritable key = new LongWritable(1234);  
  6.         List<LongWritable> list = new ArrayList<LongWritable>();  
  7.         list.add(new LongWritable(10));  
  8.         list.add(new LongWritable(2));  
  9.         Iterable<LongWritable> values = list; //构造Iterable   
  10.         //OutputCollector<LongWritable, LongWritable> output = mock(OutputCollector.class); 老版本测试   
  11.         Reducer.Context context = mock(Reducer.Context.class); //这里要注明Reduce.context上下文对象   
  12.         try {  
  13.             //reude.reduce(key, values, output, null); 老版本测试   
  14.             reuder.reduce(key, values, context); //使用上下文对象代替上面的output   
  15.             verify(context).write(new LongWritable(12), new LongWritable(1234));  
  16.         }catch (InterruptedException e) {  
  17.             // TODO Auto-generated catch block   
  18.             e.printStackTrace();  
  19.         }  
  20.     }  
  21.     @Test  
  22.      public void processMap()throws IOException{  
  23.         wordcountMapper mapper = new wordcountMapper(); //map测试   
  24.          Text value = new Text("1234");  
  25.          LongWritable key = new LongWritable(1);  
  26.         //OutputCollector<LongWritable, Text> output = mock(OutputCollector.class); 老版本测试   
  27.          Mapper.Context context = mock(Mapper.Context.class);  
  28.         try{  
  29.                 //mapper.map(key, value, output, null); 老版本测试   
  30.                 mapper.map(key, value, context);  
  31.                 verify(context).write(new LongWritable(1234), new LongWritable(1));  
  32.             } catch (InterruptedException e) {  
  33.             // TODO Auto-generated catch block   
  34.             e.printStackTrace();  
  35.         }  
  36.      }  
  37.     public static  class wordcountMapper extends  
  38.     Mapper<LongWritable, Text, LongWritable, LongWritable>{  
  39.     public void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException{  
  40.             String one = value.toString();  
  41.             context.write(new LongWritable(Integer.parseInt(one)) , key);  
  42.         }  
  43.     }  
  44. public  class wordcountReduce extends  
  45.     Reducer<LongWritable, LongWritable, LongWritable, LongWritable>{  
  46.     public void reduce(LongWritable key, Iterable<LongWritable>values, Context context)throws IOException, InterruptedException{  
  47.         int sum = 0;  
  48.         for (LongWritable str : values){  
  49.             sum += str.get();  
  50.             }  
  51.             context.write(new LongWritable(sum), key );  
  52.         }  
  53.     }  
  54. }  

相关问答

更多
  • 打印堆栈是调试的常用方法,一般在系统异常时,我们可以将异常情况下的堆栈打印出来,这样十分方便错误查找。实际上还有另外一个非常有用的功能:分析代码的行为。android代码太过庞大复杂了,完全的静态分析经常是无从下手,因此通过打印堆栈的动态分析也十分必要。 Android打印堆栈的方法,简单归类一下 1. zygote的堆栈dump 实际上这个可以同时dump java线程及native线程的堆栈,对于java线程,java堆栈和native堆栈都可以得到。 使用方法很简单,直接在adb shell或串口中输 ...
  • privatestaticStringcheckHadoopHome(){//firstchecktheDflaghadoop.home.dirwithJVMscope//System.setProperty("hadoop.home.dir","");Stringhome=System.getProperty("hadoop.home.dir");//fallbacktothesystem/user-globalenvvariableif(home==null){home=System.getenv("H ...
  • 都可以,简单的直接用txt打开java文件,写好后打包成class文件,就可以运行了。你看他原来在哪里放class文件的,你就放在那里
  • JobTracker Web UI为您提供了非常有用的报告,可以比较每个映射器和reducer的可用日志。 另请查看hadoop-test.jar存档中的mrbench类。 网上有大量有关Hadoop集群基准测试用法的信息,如本文所述 。 JobTracker web UI gives you very useful reports which allow to compare everything up to available logs for every mapper and reducer. Als ...
  • 使用ResourceManager的UI : 如果您在群集中运行YARN,那么您的群集中将不会运行JobTracker,因此您无法访问http://localhost:50030/jobtracker.jsp ,而是会运行ResourceManager并且您可以访问ResourceManager的Web页面访问http://RESOURCE_MANAGER_HOST:8088/cluster (用您的ResourceManager的IP地址替换RESOURCE_MANAGER_HOST)。 在Resourc ...
  • 原来这条消息可以忽略不计。 虽然主机进程确实没有调试信息,但应正确加载测试项目的PDB文件,以便测试代码中的断点将被命中。 Turns out this message can be ignored. While the host process is indeed without debug information, the test project's PDB file should be loaded correctly, so that breakpoints in the test code wi ...
  • 我怀疑Hadoop是否安装正确。 如果所有守护程序都在运行,请检查您的机器。如果没有,请考虑重新检查或重新安装您缺少的内容。 ERROR [main] util.Shell (Shell.java:getWinUtilsPath(373)) - Failed to locate the winutils binary in the hadoop binary path java.io.IOException: Could not locate executable I doubt if Hadoop ...
  • 也许。 但是他们中没有一个会在测试中接近hadoop的真实世界体验。 像Facebook和雅虎这样的公司正在付钱来规模hadoop,我也知道没有类似的开源项目值得期待。 Maybe. But none of them will have anywhere near the testing a real world experience that hadoop does. Companies like facebook and yahoo are paying to scale hadoop and I kn ...
  • 您应该检查mapred-site.xml并查看mapreduce.jobhistory.max-age-ms 。 如: https://hadoop.apache.org/docs/current/hadoop-mapreduce-client/hadoop-mapreduce-client-core/mapred-default.xml 运行历史记录清理程序时,将删除早于此毫秒的作业历史记录文件。 默认为604800000(1周)。 如果要读取资源使用情况,则应考虑使用作业历史记录服务器的Job API和 ...
  • 我通过以下方式在Eclipse中开发Cassandra / Hadoop应用程序: 使用maven(m2e)为我的Eclipse项目收集和配置依赖项(Hadoop,Cassandra,Pig等) 创建测试用例(src / test / java中的类)来测试我的映射器和缩减器。 诀窍是使用扩展RecordWriter和StatusReporter的内部类动态构建上下文对象。 如果执行此操作,则在调用setup / map / cleanup或setup / reduce / cleanup之后,您可以断言正 ...