You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by cj...@apache.org on 2013/10/16 02:22:11 UTC

[3/5] git commit: ACCUMULO-1751 Adding tests for autoAdjustRanges and offlineTable paths through getSplits().

ACCUMULO-1751 Adding tests for autoAdjustRanges and offlineTable paths through getSplits().


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/f8197677
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/f8197677
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/f8197677

Branch: refs/heads/master
Commit: f8197677aa482d8118f884f3ea3a08495a4344ed
Parents: 87b104d
Author: Corey J. Nolet <cj...@gmail.com>
Authored: Mon Oct 14 01:23:47 2013 -0400
Committer: Corey J. Nolet <cj...@gmail.com>
Committed: Tue Oct 15 20:22:07 2013 -0400

----------------------------------------------------------------------
 .../test/functional/AccumuloInputFormatIT.java  | 67 +++++++++++++++-----
 1 file changed, 51 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/f8197677/test/src/test/java/org/apache/accumulo/test/functional/AccumuloInputFormatIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/AccumuloInputFormatIT.java b/test/src/test/java/org/apache/accumulo/test/functional/AccumuloInputFormatIT.java
index b4258c5..77769a5 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/AccumuloInputFormatIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/AccumuloInputFormatIT.java
@@ -2,8 +2,10 @@ package org.apache.accumulo.test.functional;
 
 import static java.lang.System.currentTimeMillis;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.TreeSet;
@@ -16,48 +18,81 @@ import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat;
 import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
 import org.apache.accumulo.core.util.UtilWaitThread;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.InputSplit;
 import org.apache.hadoop.mapreduce.Job;
+import org.junit.Before;
 import org.junit.Test;
 
 public class AccumuloInputFormatIT extends SimpleMacIT {
 
+  AccumuloInputFormat inputFormat;
+
+  @Before
+  public void before() {
+    inputFormat = new AccumuloInputFormat();
+  }
+
+  /**
+   * Tests several different paths through the getSplits() method by setting different properties and verifying the results.
+   */
   @Test
   public void testGetSplits() throws IOException, AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
-
     String table = getTableNames(1)[0];
     getConnector().tableOperations().create(table);
-
-    // add data
-
-    // add splits
+    insertData(table, currentTimeMillis());
 
     Job job = new Job();
-
-    // set up the job here
     AccumuloInputFormat.setInputTableName(job, table);
     AccumuloInputFormat.setZooKeeperInstance(job, getConnector().getInstance().getInstanceName(), getConnector().getInstance().getZooKeepers());
     AccumuloInputFormat.setConnectorInfo(job, "root", new PasswordToken(ROOT_PASSWORD));
 
-    AccumuloInputFormat inputFormat = new AccumuloInputFormat();
-
-    insertData(table, currentTimeMillis());
-
+    // split table
     TreeSet<Text> splitsToAdd = new TreeSet<Text>();
     for (int i = 0; i < 10000; i += 1000)
       splitsToAdd.add(new Text(String.format("%09d", i)));
-
     getConnector().tableOperations().addSplits(table, splitsToAdd);
+    UtilWaitThread.sleep(500); // wait for splits to be propagated
 
-    UtilWaitThread.sleep(5000);
+    // get splits without setting any range
     Collection<Text> actualSplits = getConnector().tableOperations().listSplits(table);
-
     List<InputSplit> splits = inputFormat.getSplits(job);
-    assertEquals(actualSplits.size()+1, splits.size());
-
+    assertEquals(actualSplits.size() + 1, splits.size()); // No ranges set on the job so it'll start with -inf
+
+    // set ranges and get splits
+    List<Range> ranges = new ArrayList<Range>();
+    for (Text text : actualSplits)
+      ranges.add(new Range(text));
+    AccumuloInputFormat.setRanges(job, ranges);
+    splits = inputFormat.getSplits(job);
+    assertEquals(actualSplits.size(), splits.size());
+
+    // offline mode
+    AccumuloInputFormat.setOfflineTableScan(job, true);
+    try {
+      inputFormat.getSplits(job);
+      fail("An exception should have been thrown");
+    } catch (Exception e) {}
+
+    getConnector().tableOperations().offline(table);
+    splits = inputFormat.getSplits(job);
+    assertEquals(actualSplits.size(), splits.size());
+>>>>>>> ACCUMULO-1751 Adding tests for autoAdjustRanges and offlineTable paths through getSplits().
+
+    // auto adjust ranges
+    ranges = new ArrayList<Range>();
+    for (int i = 0; i < 5; i++) // overlapping ranges
+      ranges.add(new Range(String.format("%09d", i), String.format("%09d", i + 2)));
+    AccumuloInputFormat.setRanges(job, ranges);
+    splits = inputFormat.getSplits(job);
+    assertEquals(2, splits.size());
+
+    AccumuloInputFormat.setAutoAdjustRanges(job, false);
+    splits = inputFormat.getSplits(job);
+    assertEquals(ranges.size(), splits.size());
   }
 
   private void insertData(String tableName, long ts) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {