accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject svn commit: r1484908 - /accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java
Date Tue, 21 May 2013 19:13:43 GMT
Author: ecn
Date: Tue May 21 19:13:43 2013
New Revision: 1484908

URL: http://svn.apache.org/r1484908
Log:
ACCUMULO-1421 use reflection to work around class/interface change in Counter

Modified:
    accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java

Modified: accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java?rev=1484908&r1=1484907&r2=1484908&view=diff
==============================================================================
--- accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java
(original)
+++ accumulo/branches/1.5/test/src/main/java/org/apache/accumulo/test/continuous/ContinuousVerify.java
Tue May 21 19:13:43 2013
@@ -17,6 +17,7 @@
 package org.apache.accumulo.test.continuous;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -36,6 +37,7 @@ import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.io.VLongWritable;
+import org.apache.hadoop.mapred.Counters.Counter;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.Mapper;
 import org.apache.hadoop.mapreduce.Reducer;
@@ -52,6 +54,24 @@ import com.beust.jcommander.validators.P
 
 public class ContinuousVerify extends Configured implements Tool {
   
+  // work around hadoop-1/hadoop-2 runtime incompatibility
+  static private Method INCREMENT;
+  static {
+    try {
+      INCREMENT = Counter.class.getMethod("increment", Long.TYPE);
+    } catch (Exception ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+  
+  private static void increment(Object obj) {
+    try {
+      INCREMENT.invoke(obj, 1L);
+    } catch (Exception ex) {
+      throw new RuntimeException(ex);
+    }
+  }
+  
   public static final VLongWritable DEF = new VLongWritable(-1);
   
   public static class CMapper extends Mapper<Key,Value,LongWritable,VLongWritable>
{
@@ -59,7 +79,7 @@ public class ContinuousVerify extends Co
     private LongWritable row = new LongWritable();
     private LongWritable ref = new LongWritable();
     private VLongWritable vrow = new VLongWritable();
-    
+
     private long corrupt = 0;
     
     @Override
@@ -71,7 +91,7 @@ public class ContinuousVerify extends Co
       try {
         ContinuousWalk.validate(key, data);
       } catch (BadChecksumException bce) {
-        context.getCounter(Counts.CORRUPT).increment(1);
+        increment(context.getCounter(Counts.CORRUPT));
         if (corrupt < 1000) {
           System.out.println("ERROR Bad checksum : " + key);
         } else if (corrupt == 1000) {
@@ -126,12 +146,12 @@ public class ContinuousVerify extends Co
         }
         
         context.write(new Text(ContinuousIngest.genRow(key.get())), new Text(sb.toString()));
-        context.getCounter(Counts.UNDEFINED).increment(1);
+        increment(context.getCounter(Counts.UNDEFINED));
         
       } else if (defCount > 0 && refs.size() == 0) {
-        context.getCounter(Counts.UNREFERENCED).increment(1);
+        increment(context.getCounter(Counts.UNREFERENCED));
       } else {
-        context.getCounter(Counts.REFERENCED).increment(1);
+        increment(context.getCounter(Counts.REFERENCED));
       }
       
     }



Mime
View raw message