You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2010/07/08 11:42:56 UTC

svn commit: r961683 - in /incubator/lcf/trunk/modules: testdata/ tests/org/apache/lcf/tests/Sanity.java tests/org/apache/lcf/tests/TestBase.java

Author: kwright
Date: Thu Jul  8 09:42:56 2010
New Revision: 961683

URL: http://svn.apache.org/viewvc?rev=961683&view=rev
Log:
Revise test to create its own data, and add incremental crawls to it.

Removed:
    incubator/lcf/trunk/modules/testdata/
Modified:
    incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java
    incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/TestBase.java

Modified: incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java?rev=961683&r1=961682&r2=961683&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java (original)
+++ incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java Thu Jul  8 09:42:56 2010
@@ -31,6 +31,38 @@ import org.junit.*;
 public class Sanity extends TestBase
 {
   
+  @Before
+  public void createTestArea()
+    throws Exception
+  {
+    try
+    {
+      File f = new File("testdata");
+      removeDirectory(f);
+      createDirectory(f);
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  @After
+  public void removeTestArea()
+    throws Exception
+  {
+    try
+    {
+      File f = new File("testdata");
+      removeDirectory(f);
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
   
   @Test
   public void sanityCheck()
@@ -75,7 +107,7 @@ public class Sanity extends TestBase
       // Now, set up the document specification.
       DocumentSpecification ds = job.getSpecification();
       // Crawl everything underneath the 'testdata' area
-      File testDataFile = new File("../testdata").getCanonicalFile();
+      File testDataFile = new File("testdata").getCanonicalFile();
       if (!testDataFile.exists())
         throw new LCFException("Test data area not found!  Looking in "+testDataFile.toString());
       if (!testDataFile.isDirectory())
@@ -86,10 +118,6 @@ public class Sanity extends TestBase
       n.setAttribute("type","file");
       n.setAttribute("match","*");
       sn.addChild(sn.getChildCount(),n);
-      n = new SpecificationNode("exclude");
-      n.setAttribute("type","directory");
-      n.setAttribute("match","*.svn");
-      sn.addChild(sn.getChildCount(),n);
       n = new SpecificationNode("include");
       n.setAttribute("type","directory");
       n.setAttribute("match","*");
@@ -102,6 +130,12 @@ public class Sanity extends TestBase
       
       // Save the job.
       jobManager.save(job);
+
+      // Create the test data files.
+      createFile(new File("testdata/test1.txt"),"This is a test file");
+      createFile(new File("testdata/test2.txt"),"This is another test file");
+      createDirectory(new File("testdata/testdir"));
+      createFile(new File("testdata/testdir/test3.txt"),"This is yet another test file");
       
       // Now, start the job, and wait until it completes.
       jobManager.manualStart(job.getID());
@@ -113,8 +147,44 @@ public class Sanity extends TestBase
       if (status.getDocumentsProcessed() != 5)
         throw new LCFException("Wrong number of documents processed - expected 5, saw "+new Long(status.getDocumentsProcessed()).toString());
       
-      // May want to do an incremental crawl or two also.
+      // Add a file and recrawl
+      createFile(new File("testdata/testdir/test4.txt"),"Added file");
+
+      // Now, start the job, and wait until it completes.
+      jobManager.manualStart(job.getID());
+      waitJobInactive(jobManager,job.getID());
+
+      status = jobManager.getStatus(job.getID());
+      // The test data area has 4 documents and one directory, and we have to count the root directory too.
+      if (status.getDocumentsProcessed() != 6)
+        throw new LCFException("Wrong number of documents processed after add - expected 6, saw "+new Long(status.getDocumentsProcessed()).toString());
+
+      // Change a file, and recrawl
+      changeFile(new File("testdata/test1.txt"),"Modified contents");
+      
+      // Now, start the job, and wait until it completes.
+      jobManager.manualStart(job.getID());
+      waitJobInactive(jobManager,job.getID());
+
+      status = jobManager.getStatus(job.getID());
+      // The test data area has 4 documents and one directory, and we have to count the root directory too.
+      if (status.getDocumentsProcessed() != 6)
+        throw new LCFException("Wrong number of documents processed after change - expected 6, saw "+new Long(status.getDocumentsProcessed()).toString());
+      // We also need to make sure the new document was indexed.  Have to think about how to do this though.
       // MHL
+      
+      // Delete a file, and recrawl
+      removeFile(new File("testdata/test2.txt"));
+      
+      // Now, start the job, and wait until it completes.
+      jobManager.manualStart(job.getID());
+      waitJobInactive(jobManager,job.getID());
+
+      // Check to be sure we actually processed the right number of documents.
+      status = jobManager.getStatus(job.getID());
+      // The test data area has 3 documents and one directory, and we have to count the root directory too.
+      if (status.getDocumentsProcessed() != 5)
+        throw new LCFException("Wrong number of documents processed after delete - expected 5, saw "+new Long(status.getDocumentsProcessed()).toString());
 
       // Now, delete the job.
       jobManager.deleteJob(job.getID());

Modified: incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/TestBase.java?rev=961683&r1=961682&r2=961683&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/TestBase.java (original)
+++ incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/TestBase.java Thu Jul  8 09:42:56 2010
@@ -54,6 +54,68 @@ public class TestBase extends org.apache
     return new String[]{"org.apache.lcf.agents.output.nullconnector.NullConnector"};
   }
   
+  protected void createDirectory(File f)
+    throws Exception
+  {
+    if (f.mkdirs() == false)
+      throw new Exception("Failed to create directory "+f.toString());
+  }
+  
+  protected void removeDirectory(File f)
+    throws Exception
+  {
+    File[] files = f.listFiles();
+    if (files != null)
+    {
+      int i = 0;
+      while (i < files.length)
+      {
+        File subfile = files[i++];
+        if (subfile.isDirectory())
+          removeDirectory(subfile);
+        else
+          subfile.delete();
+      }
+    }
+    f.delete();
+  }
+  
+  protected void createFile(File f, String contents)
+    throws Exception
+  {
+    OutputStream os = new FileOutputStream(f);
+    try
+    {
+      Writer w = new OutputStreamWriter(os,"utf-8");
+      try
+      {
+        w.write(contents);
+      }
+      finally
+      {
+        w.flush();
+      }
+    }
+    finally
+    {
+      os.close();
+    }
+  }
+  
+  protected void removeFile(File f)
+    throws Exception
+  {
+    if (f.delete() == false)
+      throw new Exception("Failed to delete file "+f.toString());
+  }
+  
+  protected void changeFile(File f, String newContents)
+    throws Exception
+  {
+    removeFile(f);
+    createFile(f,newContents);
+  }
+  
   @Before
   public void setUp()
     throws Exception