Author: edwardyoon
Date: Fri Jan  3 08:44:36 2014
New Revision: 1555030

URL: http://svn.apache.org/r1555030
Log:
Fix SpMVTest fails

Modified:
    hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java

Modified: 
hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java
URL: 
http://svn.apache.org/viewvc/hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java?rev=1555030&r1=1555029&r2=1555030&view=diff
==============================================================================
--- hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java 
(original)
+++ hama/trunk/examples/src/test/java/org/apache/hama/examples/SpMVTest.java 
Fri Jan  3 08:44:36 2014
@@ -49,7 +49,7 @@ public class SpMVTest {
   private static HamaConfiguration conf;
   private static String baseDir;
   private static FileSystem fs;
-  
+
   @Before
   public void prepare() throws IOException {
     conf = new HamaConfiguration();
@@ -85,10 +85,17 @@ public class SpMVTest {
    */
   @Test
   public void simpleSpMVTest() {
+    HamaConfiguration conf = new HamaConfiguration();
+    String testDir = "/simple/";
+    int size = 4;
+    String matrixPath = baseDir + testDir + "inputMatrix";
+    String vectorPath = baseDir + testDir + "inputVector";
+    String outputPath = baseDir + testDir;
+
     try {
-      HamaConfiguration conf = new HamaConfiguration();
-      String testDir = "/simple/";
-      int size = 4;
+      if (fs.exists(new Path(baseDir))) {
+        fs.delete(new Path(baseDir), true);
+      }
 
       // creating test matrix
       HashMap<Integer, Writable> inputMatrix = new HashMap<Integer, 
Writable>();
@@ -111,7 +118,6 @@ public class SpMVTest {
       inputMatrix.put(1, vector1);
       inputMatrix.put(2, vector2);
       inputMatrix.put(3, vector3);
-      String matrixPath = baseDir + testDir + "inputMatrix";
       writeMatrix(matrixPath, conf, inputMatrix);
 
       HashMap<Integer, Writable> inputVector = new HashMap<Integer, 
Writable>();
@@ -122,20 +128,15 @@ public class SpMVTest {
       vector.addCell(2, 6);
       vector.addCell(3, 1);
       inputVector.put(0, vector);
-      String vectorPath = baseDir + testDir + "inputVector";
       writeMatrix(vectorPath, conf, inputVector);
 
-      String outputPath = baseDir + testDir;
       SpMV.main(new String[] { matrixPath, vectorPath, outputPath, "4" });
 
       String resultPath = SpMV.getResultPath();
       DenseVectorWritable result = new DenseVectorWritable();
       SpMV.readFromFile(resultPath, result, conf);
+      LOG.info("result is a file: " + fs.isFile(new Path(resultPath)));
 
-      LOG.info(resultPath +": " + fs.exists(new Path(resultPath)));
-      LOG.info(fs.getLength(new Path(resultPath)));
-      LOG.info(">>>>>>>>>>> " + result);
-      
       double expected[] = { 38, 12, 24, 11 };
       if (result.getSize() != size)
         throw new Exception("Incorrect size of output vector");
@@ -147,9 +148,11 @@ public class SpMVTest {
         if (expected[i] != 0)
           throw new Exception("Result doesn't meets expectations");
 
+      fs.delete(new Path(baseDir), true);
     } catch (Exception e) {
       e.printStackTrace();
       fail(e.getLocalizedMessage());
+    } finally {
     }
   }
 


Reply via email to