accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From medi...@apache.org
Subject svn commit: r1383248 - /accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java
Date Tue, 11 Sep 2012 05:33:15 GMT
Author: medined
Date: Tue Sep 11 05:33:14 2012
New Revision: 1383248

URL: http://svn.apache.org/viewvc?rev=1383248&view=rev
Log:
resolve PMD messages. Is sprinking the code with NOPMD comments bad? I think so but this was
an experiment. Comments?

Modified:
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java?rev=1383248&r1=1383247&r2=1383248&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java
(original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mapreduce/AccumuloRowInputFormatTest.java
Tue Sep 11 05:33:14 2012
@@ -20,13 +20,19 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map.Entry;
 
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.TableExistsException;
+import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.client.mapreduce.InputFormatBase.RangeInputSplit;
 import org.apache.accumulo.core.client.mock.MockInstance;
 import org.apache.accumulo.core.data.Key;
@@ -44,78 +50,87 @@ import org.apache.hadoop.mapreduce.TaskA
 import org.junit.Test;
 
 public class AccumuloRowInputFormatTest {
-  List<Entry<Key,Value>> row1;
-  List<Entry<Key,Value>> row2;
-  List<Entry<Key,Value>> row3;
+  private static final String ROW1 = "row1";
+  private static final String ROW2 = "row2";
+  private static final String ROW3 = "row3";
+  private static final String COLF1 = "colf1";
+  private transient final List<Entry<Key,Value>> row1;
+  private transient final List<Entry<Key,Value>> row2;
+  private transient final List<Entry<Key,Value>> row3;
   
-  {
+  public AccumuloRowInputFormatTest() {
     row1 = new ArrayList<Entry<Key,Value>>();
-    row1.add(new KeyValue(new Key("row1", "colf1", "colq1"), "v1".getBytes()));
-    row1.add(new KeyValue(new Key("row1", "colf1", "colq2"), "v2".getBytes()));
-    row1.add(new KeyValue(new Key("row1", "colf2", "colq3"), "v3".getBytes()));
+    row1.add(new KeyValue(new Key(ROW1, COLF1, "colq1"), "v1".getBytes()));
+    row1.add(new KeyValue(new Key(ROW1, COLF1, "colq2"), "v2".getBytes()));
+    row1.add(new KeyValue(new Key(ROW1, "colf2", "colq3"), "v3".getBytes()));
     row2 = new ArrayList<Entry<Key,Value>>();
-    row2.add(new KeyValue(new Key("row2", "colf1", "colq4"), "v4".getBytes()));
+    row2.add(new KeyValue(new Key(ROW2, COLF1, "colq4"), "v4".getBytes()));
     row3 = new ArrayList<Entry<Key,Value>>();
-    row3.add(new KeyValue(new Key("row3", "colf1", "colq5"), "v5".getBytes()));
+    row3.add(new KeyValue(new Key(ROW3, COLF1, "colq5"), "v5".getBytes()));
   }
-  
-  public static void checkLists(List<Entry<Key,Value>> a, List<Entry<Key,Value>>
b) {
-    assertEquals(a.size(), b.size());
-    for (int i = 0; i < a.size(); i++) {
-      assertEquals(a.get(i).getKey(), b.get(i).getKey());
-      assertEquals(a.get(i).getValue(), b.get(i).getValue());
+
+  public static void checkLists(final List<Entry<Key,Value>> first, final List<Entry<Key,Value>>
second) {
+    assertEquals("Sizes should be the same.", first.size(), second.size());
+    for (int i = 0; i < first.size(); i++) {
+      assertEquals("Keys should be equal.", first.get(i).getKey(), second.get(i).getKey());
+      assertEquals("Values should be equal.", first.get(i).getValue(), second.get(i).getValue());
     }
   }
   
-  public static void checkLists(List<Entry<Key,Value>> a, Iterator<Entry<Key,Value>>
b) {
-    int i = 0;
-    while (b.hasNext()) {
-      Entry<Key,Value> e = b.next();
-      assertEquals(a.get(i).getKey(), e.getKey());
-      assertEquals(a.get(i).getValue(), e.getValue());
-      i++;
+  public static void checkLists(final List<Entry<Key,Value>> first, final Iterator<Entry<Key,Value>>
second) {
+    int entryIndex = 0; // NOPMD
+    while (second.hasNext()) {
+      final Entry<Key,Value> entry = second.next();
+      assertEquals("Keys should be equal", first.get(entryIndex).getKey(), entry.getKey());
+      assertEquals("Values should be equal", first.get(entryIndex).getValue(), entry.getValue());
+      entryIndex++; // NOPMD
     }
   }
   
-  public static void insertList(BatchWriter bw, List<Entry<Key,Value>> list)
throws Exception {
+  public static void insertList(final BatchWriter writer, final List<Entry<Key,Value>>
list) throws MutationsRejectedException {
     for (Entry<Key,Value> e : list) {
-      Key k = e.getKey();
-      Mutation m = new Mutation(k.getRow());
-      m.put(k.getColumnFamily(), k.getColumnQualifier(), new ColumnVisibility(k.getColumnVisibility()),
k.getTimestamp(), e.getValue());
-      bw.addMutation(m);
+      final Key key = e.getKey();
+      final Mutation mutation = new Mutation(key.getRow());  // NOPMD
+      ColumnVisibility colVisibility = new ColumnVisibility(key.getColumnVisibility()); //
NOPMD
+      mutation.put(key.getColumnFamily(), key.getColumnQualifier(), colVisibility, key.getTimestamp(),
e.getValue());
+      writer.addMutation(mutation);
     }
   }
   
   @Test
-  public void test() throws Exception {
-    MockInstance instance = new MockInstance("instance1");
-    Connector conn = instance.getConnector("root", "".getBytes());
+  public void test() throws AccumuloException, AccumuloSecurityException, TableExistsException,
TableNotFoundException, IOException, InterruptedException {
+    final MockInstance instance = new MockInstance("instance1");
+    final Connector conn = instance.getConnector("root", "".getBytes());
     conn.tableOperations().create("test");
-    BatchWriter bw = conn.createBatchWriter("test", 100000l, 100l, 5);
-    
-    insertList(bw, row1);
-    insertList(bw, row2);
-    insertList(bw, row3);
-    bw.close();
-    
-    JobContext job = ContextFactory.createJobContext();
+    BatchWriter writer = null; // NOPMD
+    try {
+    	writer = conn.createBatchWriter("test", 100000l, 100l, 5);
+        insertList(writer, row1);
+        insertList(writer, row2);
+        insertList(writer, row3);
+    } finally {
+      if (writer != null) {
+    	  writer.close();
+      }
+    }
+    final JobContext job = ContextFactory.createJobContext();
     AccumuloRowInputFormat.setInputInfo(job.getConfiguration(), "root", "".getBytes(), "test",
new Authorizations());
     AccumuloRowInputFormat.setMockInstance(job.getConfiguration(), "instance1");
-    AccumuloRowInputFormat crif = new AccumuloRowInputFormat();
-    RangeInputSplit ris = new RangeInputSplit();
-    TaskAttemptContext tac = ContextFactory.createTaskAttemptContext(job);
-    RecordReader<Text,PeekingIterator<Entry<Key,Value>>> rr = crif.createRecordReader(ris,
tac);
-    rr.initialize(ris, tac);
+    final AccumuloRowInputFormat crif = new AccumuloRowInputFormat();
+    final RangeInputSplit ris = new RangeInputSplit();
+    final TaskAttemptContext tac = ContextFactory.createTaskAttemptContext(job);
+    final RecordReader<Text,PeekingIterator<Entry<Key,Value>>> recReader
= crif.createRecordReader(ris, tac);
+    recReader.initialize(ris, tac);
     
-    assertTrue(rr.nextKeyValue());
-    assertEquals(new Text("row1"), rr.getCurrentKey());
-    checkLists(row1, rr.getCurrentValue());
-    assertTrue(rr.nextKeyValue());
-    assertEquals(new Text("row2"), rr.getCurrentKey());
-    checkLists(row2, rr.getCurrentValue());
-    assertTrue(rr.nextKeyValue());
-    assertEquals(new Text("row3"), rr.getCurrentKey());
-    checkLists(row3, rr.getCurrentValue());
-    assertFalse(rr.nextKeyValue());
+    assertTrue("Next key value should be true.", recReader.nextKeyValue());
+    assertEquals("Current key should be " + ROW1, new Text(ROW1), recReader.getCurrentKey());
+    checkLists(row1, recReader.getCurrentValue());
+    assertTrue("Next key value should be true.", recReader.nextKeyValue());
+    assertEquals("Current key should be " + ROW2, new Text(ROW2), recReader.getCurrentKey());
+    checkLists(row2, recReader.getCurrentValue());
+    assertTrue("Next key value should be true.", recReader.nextKeyValue());
+    assertEquals("Current key should be " + ROW3, new Text(ROW3), recReader.getCurrentKey());
+    checkLists(row3, recReader.getCurrentValue());
+    assertFalse("Next key value should be false.", recReader.nextKeyValue());
   }
 }



Mime
View raw message