accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ujustgotbi...@apache.org
Subject [06/50] git commit: ACCUMULO-375 added unit test for WikipediaInputSplit (and fixed problem it found)
Date Thu, 06 Feb 2014 05:39:45 GMT
ACCUMULO-375 added unit test for WikipediaInputSplit (and fixed problem it found)

git-svn-id: https://svn.apache.org/repos/asf/incubator/accumulo/branches/1.4@1241532 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/1.4.5-SNAPSHOT
Commit: 686895fcf156fb2dc753ce7c4758313bc5070416
Parents: bd7b9cf
Author: Adam Fuchs <afuchs@apache.org>
Authored: Tue Feb 7 17:50:10 2012 +0000
Committer: Adam Fuchs <afuchs@apache.org>
Committed: Tue Feb 7 17:50:10 2012 +0000

----------------------------------------------------------------------
 .../wikisearch/ingest/WikipediaInputFormat.java |  2 +-
 .../ingest/WikipediaInputSplitTest.java         | 56 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/blob/686895fc/ingest/src/main/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputFormat.java
----------------------------------------------------------------------
diff --git a/ingest/src/main/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputFormat.java
b/ingest/src/main/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputFormat.java
index 7c7cf4e..dd2eeb9 100644
--- a/ingest/src/main/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputFormat.java
+++ b/ingest/src/main/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputFormat.java
@@ -75,10 +75,10 @@ public class WikipediaInputFormat extends TextInputFormat {
       Path file = new Path(in.readUTF());
       long start = in.readLong();
       long length = in.readLong();
-      int numHosts = in.readInt();
       String [] hosts = null;
       if(in.readBoolean())
       {
+        int numHosts = in.readInt();
         hosts = new String[numHosts];
         for(int i = 0; i < numHosts; i++)
           hosts[i] = in.readUTF();

http://git-wip-us.apache.org/repos/asf/accumulo-wikisearch/blob/686895fc/ingest/src/test/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputSplitTest.java
----------------------------------------------------------------------
diff --git a/ingest/src/test/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputSplitTest.java
b/ingest/src/test/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputSplitTest.java
new file mode 100644
index 0000000..3da5a62
--- /dev/null
+++ b/ingest/src/test/java/org/apache/accumulo/examples/wikisearch/ingest/WikipediaInputSplitTest.java
@@ -0,0 +1,56 @@
+package org.apache.accumulo.examples.wikisearch.ingest;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import junit.framework.Assert;
+
+import org.apache.accumulo.examples.wikisearch.ingest.WikipediaInputFormat.WikipediaInputSplit;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapreduce.lib.input.FileSplit;
+import org.junit.Test;
+
+public class WikipediaInputSplitTest {
+  @Test
+  public void testSerialization() throws IOException
+  {
+    Path testPath = new Path("/foo/bar");
+    String [] hosts = new String [2];
+    hosts[0] = "abcd";
+    hosts[1] = "efgh";
+    FileSplit fSplit = new FileSplit(testPath,1,2,hosts);
+    WikipediaInputSplit split = new WikipediaInputSplit(fSplit,7);
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    ObjectOutputStream out = new ObjectOutputStream(baos);
+    split.write(out);
+    out.close();    
+    baos.close();
+
+    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+    DataInput in = new ObjectInputStream(bais);
+    
+    WikipediaInputSplit split2 = new WikipediaInputSplit();
+    split2.readFields(in);
+    Assert.assertTrue(bais.available() == 0);
+    bais.close();
+    
+    Assert.assertTrue(split.getPartition() == split2.getPartition());
+    
+    FileSplit fSplit2 = split2.getFileSplit();
+    Assert.assertTrue(fSplit.getPath().equals(fSplit2.getPath()));
+    Assert.assertTrue(fSplit.getStart() == fSplit2.getStart());
+    Assert.assertTrue(fSplit.getLength() == fSplit2.getLength());
+
+    String [] hosts2 = fSplit2.getLocations();
+    Assert.assertEquals(hosts.length, hosts2.length);
+    for(int i = 0; i < hosts.length; i++)
+    {
+      Assert.assertEquals(hosts[i],hosts2[i]);
+    }
+  }
+}


Mime
View raw message