incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1049834 - in /incubator/lcf/trunk: ./ connectors/filesystem/ framework/ tests/filesystem/org/apache/manifoldcf/filesystem_tests/
Date Thu, 16 Dec 2010 09:16:25 GMT
Author: kwright
Date: Thu Dec 16 09:16:25 2010
New Revision: 1049834

URL: http://svn.apache.org/viewvc?rev=1049834&view=rev
Log:
Tests to support valid completion of CONNECTORS-128.

Added:
    incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
  (with props)
    incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
  (with props)
Modified:
    incubator/lcf/trunk/build.xml
    incubator/lcf/trunk/connectors/filesystem/build.xml
    incubator/lcf/trunk/framework/build.xml
    incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/APISanity.java
    incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Sanity.java

Modified: incubator/lcf/trunk/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/build.xml?rev=1049834&r1=1049833&r2=1049834&view=diff
==============================================================================
--- incubator/lcf/trunk/build.xml (original)
+++ incubator/lcf/trunk/build.xml Thu Dec 16 09:16:25 2010
@@ -1424,7 +1424,7 @@
 
     <target name="run-filesystem-tests" depends="compile-filesystem-tests,calculate-filesystem-tests-condition"
if="filesystem-tests.include">
         <mkdir dir="test-output/filesystem"/>
-        <junit fork="true" maxmemory="128m" dir="test-output/filesystem" showoutput="true">
+        <junit fork="true" maxmemory="128m" dir="test-output/filesystem" showoutput="true"
haltonfailure="true">
             <classpath>
                 <fileset dir="framework/lib">
                     <include name="*.jar"/>
@@ -1451,13 +1451,15 @@
             </classpath>
             <test name="org.apache.manifoldcf.filesystem_tests.Sanity" todir="test-output/filesystem"/>
             <test name="org.apache.manifoldcf.filesystem_tests.APISanity" todir="test-output/filesystem"/>
+            <test name="org.apache.manifoldcf.filesystem_tests.Hopcount" todir="test-output/filesystem"/>
+            <test name="org.apache.manifoldcf.filesystem_tests.Expiration" todir="test-output/filesystem"/>
             <!-- MHL -->
         </junit>
     </target>
 
     <target name="run-sharepoint-tests" depends="compile-sharepoint-tests,calculate-sharepoint-tests-condition"
if="sharepoint-tests.include">
         <mkdir dir="test-output/sharepoint"/>
-        <junit fork="true" maxmemory="128m" dir="test-output/sharepoint" showoutput="true">
+        <junit fork="true" maxmemory="128m" dir="test-output/sharepoint" showoutput="true"
haltonfailure="true">
             <classpath>
                 <fileset dir="framework/lib">
                     <include name="*.jar"/>
@@ -1574,21 +1576,21 @@ All targets requiring Apache Forrest als
       </echo>
     </target>
 
-<target name="-taskdef">
-    <typedef resource="org/apache/rat/anttasks/antlib.xml" uri="antlib:rat.anttasks">
-      <classpath>
-        <fileset dir="." includes="rat*.jar"/>
-      </classpath>
-    </typedef>
-  </target>
-  <target name="rat-sources" depends="-taskdef"
-    description="runs the tasks over src/java excluding the license directory">
-    <rat:report xmlns:rat="antlib:org.apache.rat.anttasks">
-      <fileset dir="connectors/"/>
-      <fileset dir="framework/"/>
-      <fileset dir="site/src/"/>
-    </rat:report>
-  </target>
+    <target name="-taskdef">
+      <typedef resource="org/apache/rat/anttasks/antlib.xml" uri="antlib:rat.anttasks">
+        <classpath>
+          <fileset dir="." includes="rat*.jar"/>
+        </classpath>
+      </typedef>
+    </target>
+    <target name="rat-sources" depends="-taskdef"
+      description="runs the tasks over src/java excluding the license directory">
+      <rat:report xmlns:rat="antlib:org.apache.rat.anttasks">
+        <fileset dir="connectors/"/>
+        <fileset dir="framework/"/>
+        <fileset dir="site/src/"/>
+      </rat:report>
+    </target>
 
     
 </project>

Modified: incubator/lcf/trunk/connectors/filesystem/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/connectors/filesystem/build.xml?rev=1049834&r1=1049833&r2=1049834&view=diff
==============================================================================
--- incubator/lcf/trunk/connectors/filesystem/build.xml (original)
+++ incubator/lcf/trunk/connectors/filesystem/build.xml Thu Dec 16 09:16:25 2010
@@ -71,7 +71,7 @@
 
     <target name="run-tests" depends="compile-tests">
         <mkdir dir="test-output"/>
-        <junit fork="true" maxmemory="128m" dir="test-output" showoutput="true">
+        <junit fork="true" maxmemory="128m" dir="test-output" showoutput="true" haltonfailure="true">
             <classpath>
                 <fileset dir="lib">
                     <include name="*.jar"/>

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1049834&r1=1049833&r2=1049834&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Thu Dec 16 09:16:25 2010
@@ -447,7 +447,7 @@
 
     <target name="run-tests" depends="compile-tests">
         <mkdir dir="test-output"/>
-        <junit fork="true" maxmemory="128m" dir="test-output" showoutput="true">
+        <junit fork="true" maxmemory="128m" dir="test-output" showoutput="true" haltonfailure="true">
             <classpath>
                 <fileset dir="lib">
                     <include name="*.jar"/>

Modified: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/APISanity.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/APISanity.java?rev=1049834&r1=1049833&r2=1049834&view=diff
==============================================================================
--- incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/APISanity.java
(original)
+++ incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/APISanity.java
Thu Dec 16 09:16:25 2010
@@ -222,7 +222,7 @@ public class APISanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       startJob(jobIDString);
-      waitJobInactive(jobIDString);
+      waitJobInactive(jobIDString, 120000L);
 
       // Check to be sure we actually processed the right number of documents.
       // The test data area has 3 documents and one directory, and we have to count the root
directory too.
@@ -236,7 +236,7 @@ public class APISanity extends TestBase
 
       // Now, start the job, and wait until it completes.
       startJob(jobIDString);
-      waitJobInactive(jobIDString);
+      waitJobInactive(jobIDString, 120000L);
 
       // The test data area has 4 documents and one directory, and we have to count the root
directory too.
       count = getJobDocumentsProcessed(jobIDString);
@@ -248,7 +248,7 @@ public class APISanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       startJob(jobIDString);
-      waitJobInactive(jobIDString);
+      waitJobInactive(jobIDString, 120000L);
 
       // The test data area has 4 documents and one directory, and we have to count the root
directory too.
       count = getJobDocumentsProcessed(jobIDString);
@@ -262,7 +262,7 @@ public class APISanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       startJob(jobIDString);
-      waitJobInactive(jobIDString);
+      waitJobInactive(jobIDString, 120000L);
 
       // Check to be sure we actually processed the right number of documents.
       // The test data area has 3 documents and one directory, and we have to count the root
directory too.
@@ -273,7 +273,7 @@ public class APISanity extends TestBase
       // Now, delete the job.
       deleteJob(jobIDString);
 
-      waitJobDeleted(jobIDString);
+      waitJobDeleted(jobIDString, 120000L);
       
       // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections
lying around.
     }
@@ -365,10 +365,11 @@ public class APISanity extends TestBase
     return new Long(documentsProcessed).longValue();
   }
 
-  protected void waitJobInactive(String jobIDString)
+  protected void waitJobInactive(String jobIDString, long maxTime)
     throws Exception
   {
-    while (true)
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
     {
       String status = getJobStatus(jobIDString);
       if (status == null)
@@ -376,24 +377,27 @@ public class APISanity extends TestBase
       if (status.equals("not yet run"))
         throw new Exception("Job was never started.");
       if (status.equals("done"))
-        break;
+        return;
       if (status.equals("error"))
         throw new Exception("Job reports error.");
-      ManifoldCF.sleep(10000L);
+      ManifoldCF.sleep(1000L);
       continue;
     }
+    throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
   }
   
-  protected void waitJobDeleted(String jobIDString)
+  protected void waitJobDeleted(String jobIDString, long maxTime)
     throws Exception
   {
-    while (true)
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
     {
       String status = getJobStatus(jobIDString);
       if (status == null)
-        break;
-      ManifoldCF.sleep(10000L);
+        return;
+      ManifoldCF.sleep(1000L);
     }
+    throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
   }
     
 

Added: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java?rev=1049834&view=auto
==============================================================================
--- incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
(added)
+++ incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
Thu Dec 16 09:16:25 2010
@@ -0,0 +1,259 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.filesystem_tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.crawler.interfaces.*;
+import org.apache.manifoldcf.crawler.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a test which checks to see if document expiration works properly. */
+public class Expiration 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 expirationCheck()
+    throws Exception
+  {
+    try
+    {
+      // Hey, we were able to install the file system connector etc.
+      // Now, create a local test job and run it.
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      // Create a basic file system connection, and save it.
+      IRepositoryConnectionManager mgr = RepositoryConnectionManagerFactory.make(tc);
+      IRepositoryConnection conn = mgr.create();
+      conn.setName("File Connection");
+      conn.setDescription("File Connection");
+      conn.setClassName("org.apache.manifoldcf.crawler.connectors.filesystem.FileConnector");
+      conn.setMaxConnections(100);
+      // Now, save
+      mgr.save(conn);
+      
+      // Create a basic null output connection, and save it.
+      IOutputConnectionManager outputMgr = OutputConnectionManagerFactory.make(tc);
+      IOutputConnection outputConn = outputMgr.create();
+      outputConn.setName("Null Connection");
+      outputConn.setDescription("Null Connection");
+      outputConn.setClassName("org.apache.manifoldcf.agents.output.nullconnector.NullConnector");
+      outputConn.setMaxConnections(100);
+      // Now, save
+      outputMgr.save(outputConn);
+
+      // Create a job.
+      IJobManager jobManager = JobManagerFactory.make(tc);
+      IJobDescription job = jobManager.createJob();
+      job.setDescription("Test Job");
+      job.setConnectionName("File Connection");
+      job.setOutputConnectionName("Null Connection");
+      job.setType(job.TYPE_SPECIFIED);
+      job.setStartMethod(job.START_DISABLE);
+      job.setHopcountMode(job.HOPCOUNT_ACCURATE);
+      // 60-second expiration for all documents..
+      job.setExpiration(new Long(60000L));
+      // Infinite rescan interval.
+      job.setInterval(null);
+      // Continuous job.
+      job.setType(IJobDescription.TYPE_CONTINUOUS);
+      
+      // Now, set up the document specification.
+      DocumentSpecification ds = job.getSpecification();
+      // Crawl everything underneath the 'testdata' area
+      File testDataFile = new File("testdata").getCanonicalFile();
+      if (!testDataFile.exists())
+        throw new ManifoldCFException("Test data area not found!  Looking in "+testDataFile.toString());
+      if (!testDataFile.isDirectory())
+        throw new ManifoldCFException("Test data area not a directory!  Looking in "+testDataFile.toString());
+      SpecificationNode sn = new SpecificationNode("startpoint");
+      sn.setAttribute("path",testDataFile.toString());
+      SpecificationNode n = new SpecificationNode("include");
+      n.setAttribute("type","file");
+      n.setAttribute("match","*");
+      sn.addChild(sn.getChildCount(),n);
+      n = new SpecificationNode("include");
+      n.setAttribute("type","directory");
+      n.setAttribute("match","*");
+      sn.addChild(sn.getChildCount(),n);
+      ds.addChild(ds.getChildCount(),sn);
+      
+      // Set up the output specification.
+      OutputSpecification os = job.getOutputSpecification();
+      // Null output connections have no output specification, so this is a no-op.
+      
+      // 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");
+      createDirectory(new File("testdata/testdir/seconddir"));
+      createFile(new File("testdata/testdir/seconddir/test4.txt"),"Lowest test file");
+      
+      // Now, start the job, and wait until it is running.
+      jobManager.manualStart(job.getID());
+      waitJobRunning(jobManager,job.getID(),30000L);
+      
+      JobStatus status;
+      
+      // Now we wait, and we should see 7 documents eventually.
+      long startTime = System.currentTimeMillis();
+      while (System.currentTimeMillis() < startTime + 120000L)
+      {
+        status = jobManager.getStatus(job.getID());
+        if (status.getDocumentsProcessed() == 7)
+          break;
+
+        ManifoldCF.sleep(1000L);
+      }
+      
+      // At this point there should be 7 documents.
+      // OK, documents should expire starting a minute later.  The number of documents will
go quickly to zero after this time. 
+      // So all we need to do is confirm that the job stops within 2 minutes.
+      waitJobInactive(jobManager,job.getID(),180000L);
+
+      status = jobManager.getStatus(job.getID());
+      if (status.getDocumentsProcessed() != 0)
+        throw new ManifoldCFException("Wrong number of documents processed - expected 0,
saw "+new Long(status.getDocumentsProcessed()).toString());
+      
+
+      // Now, delete the job.
+      jobManager.deleteJob(job.getID());
+      waitJobDeleted(jobManager,job.getID(),120000L);
+      
+      // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections
lying around.
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  protected void waitJobInactive(IJobManager jobManager, Long jobID, long maxTime)
+    throws ManifoldCFException, InterruptedException
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      JobStatus status = jobManager.getStatus(jobID);
+      if (status == null)
+        throw new ManifoldCFException("No such job: '"+jobID+"'");
+      int statusValue = status.getStatus();
+      switch (statusValue)
+      {
+        case JobStatus.JOBSTATUS_NOTYETRUN:
+          throw new ManifoldCFException("Job was never started.");
+        case JobStatus.JOBSTATUS_COMPLETED:
+          break;
+        case JobStatus.JOBSTATUS_ERROR:
+          throw new ManifoldCFException("Job reports error status: "+status.getErrorText());
+        default:
+          ManifoldCF.sleep(1000L);
+          continue;
+      }
+      return;
+    }
+    throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+  
+  protected void waitJobRunning(IJobManager jobManager, Long jobID, long maxTime)
+    throws ManifoldCFException, InterruptedException
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      JobStatus status = jobManager.getStatus(jobID);
+      if (status == null)
+        throw new ManifoldCFException("No such job: '"+jobID+"'");
+      int statusValue = status.getStatus();
+      switch (statusValue)
+      {
+        case JobStatus.JOBSTATUS_NOTYETRUN:
+          throw new ManifoldCFException("Job was never started.");
+        case JobStatus.JOBSTATUS_COMPLETED:
+          throw new ManifoldCFException("Job ended on its own!");
+        case JobStatus.JOBSTATUS_ERROR:
+          throw new ManifoldCFException("Job reports error status: "+status.getErrorText());
+        case JobStatus.JOBSTATUS_RUNNING:
+          break;
+        default:
+          ManifoldCF.sleep(1000L);
+          continue;
+      }
+      return;
+    }
+    throw new ManifoldCFException("ManifoldCF did not start in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+
+  protected void waitJobDeleted(IJobManager jobManager, Long jobID, long maxTime)
+    throws ManifoldCFException, InterruptedException
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      JobStatus status = jobManager.getStatus(jobID);
+      if (status == null)
+        return;
+      ManifoldCF.sleep(1000L);
+    }
+    throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+    
+
+}

Propchange: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Expiration.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java?rev=1049834&view=auto
==============================================================================
--- incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
(added)
+++ incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
Thu Dec 16 09:16:25 2010
@@ -0,0 +1,209 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.manifoldcf.filesystem_tests;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import org.apache.manifoldcf.agents.interfaces.*;
+import org.apache.manifoldcf.crawler.interfaces.*;
+import org.apache.manifoldcf.crawler.system.ManifoldCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a test which checks to be sure hopcount functionality is working properly. */
+public class Hopcount 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 hopcountCheck()
+    throws Exception
+  {
+    try
+    {
+      // Hey, we were able to install the file system connector etc.
+      // Now, create a local test job and run it.
+      IThreadContext tc = ThreadContextFactory.make();
+      
+      // Create a basic file system connection, and save it.
+      IRepositoryConnectionManager mgr = RepositoryConnectionManagerFactory.make(tc);
+      IRepositoryConnection conn = mgr.create();
+      conn.setName("File Connection");
+      conn.setDescription("File Connection");
+      conn.setClassName("org.apache.manifoldcf.crawler.connectors.filesystem.FileConnector");
+      conn.setMaxConnections(100);
+      // Now, save
+      mgr.save(conn);
+      
+      // Create a basic null output connection, and save it.
+      IOutputConnectionManager outputMgr = OutputConnectionManagerFactory.make(tc);
+      IOutputConnection outputConn = outputMgr.create();
+      outputConn.setName("Null Connection");
+      outputConn.setDescription("Null Connection");
+      outputConn.setClassName("org.apache.manifoldcf.agents.output.nullconnector.NullConnector");
+      outputConn.setMaxConnections(100);
+      // Now, save
+      outputMgr.save(outputConn);
+
+      // Create a job.
+      IJobManager jobManager = JobManagerFactory.make(tc);
+      IJobDescription job = jobManager.createJob();
+      job.setDescription("Test Job");
+      job.setConnectionName("File Connection");
+      job.setOutputConnectionName("Null Connection");
+      job.setType(job.TYPE_SPECIFIED);
+      job.setStartMethod(job.START_DISABLE);
+      job.setHopcountMode(job.HOPCOUNT_ACCURATE);
+      job.addHopCountFilter("child",new Long(2));
+      
+      // Now, set up the document specification.
+      DocumentSpecification ds = job.getSpecification();
+      // Crawl everything underneath the 'testdata' area
+      File testDataFile = new File("testdata").getCanonicalFile();
+      if (!testDataFile.exists())
+        throw new ManifoldCFException("Test data area not found!  Looking in "+testDataFile.toString());
+      if (!testDataFile.isDirectory())
+        throw new ManifoldCFException("Test data area not a directory!  Looking in "+testDataFile.toString());
+      SpecificationNode sn = new SpecificationNode("startpoint");
+      sn.setAttribute("path",testDataFile.toString());
+      SpecificationNode n = new SpecificationNode("include");
+      n.setAttribute("type","file");
+      n.setAttribute("match","*");
+      sn.addChild(sn.getChildCount(),n);
+      n = new SpecificationNode("include");
+      n.setAttribute("type","directory");
+      n.setAttribute("match","*");
+      sn.addChild(sn.getChildCount(),n);
+      ds.addChild(ds.getChildCount(),sn);
+      
+      // Set up the output specification.
+      OutputSpecification os = job.getOutputSpecification();
+      // Null output connections have no output specification, so this is a no-op.
+      
+      // 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");
+      createDirectory(new File("testdata/testdir/seconddir"));
+      createFile(new File("testdata/testdir/seconddir/test4.txt"),"Lowest test file");
+      
+      // Now, start the job, and wait until it completes.
+      jobManager.manualStart(job.getID());
+      waitJobInactive(jobManager,job.getID(),120000L);
+
+      // Check to be sure we actually processed the right number of documents.
+      JobStatus status = jobManager.getStatus(job.getID());
+      // The test data area has 4 documents and 2 directories and we have to count the root
directory too.
+      // But the max hopcount is 2, so one file will be left behind, so the count should
be 6, not 7.
+      if (status.getDocumentsProcessed() != 6)
+        throw new ManifoldCFException("Wrong number of documents processed - expected 6,
saw "+new Long(status.getDocumentsProcessed()).toString());
+      
+      // Now, delete the job.
+      jobManager.deleteJob(job.getID());
+      waitJobDeleted(jobManager,job.getID(), 120000L);
+      
+      // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections
lying around.
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+      throw e;
+    }
+  }
+  
+  protected void waitJobInactive(IJobManager jobManager, Long jobID, long maxTime)
+    throws ManifoldCFException, InterruptedException
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      JobStatus status = jobManager.getStatus(jobID);
+      if (status == null)
+        throw new ManifoldCFException("No such job: '"+jobID+"'");
+      int statusValue = status.getStatus();
+      switch (statusValue)
+      {
+        case JobStatus.JOBSTATUS_NOTYETRUN:
+          throw new ManifoldCFException("Job was never started.");
+        case JobStatus.JOBSTATUS_COMPLETED:
+          break;
+        case JobStatus.JOBSTATUS_ERROR:
+          throw new ManifoldCFException("Job reports error status: "+status.getErrorText());
+        default:
+          ManifoldCF.sleep(1000L);
+          continue;
+      }
+      return;
+    }
+    throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+  
+  protected void waitJobDeleted(IJobManager jobManager, Long jobID, long maxTime)
+    throws ManifoldCFException, InterruptedException
+  {
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
+    {
+      JobStatus status = jobManager.getStatus(jobID);
+      if (status == null)
+        return;
+      ManifoldCF.sleep(1000L);
+    }
+    throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
+  }
+    
+
+}

Propchange: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Hopcount.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Sanity.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Sanity.java?rev=1049834&r1=1049833&r2=1049834&view=diff
==============================================================================
--- incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Sanity.java
(original)
+++ incubator/lcf/trunk/tests/filesystem/org/apache/manifoldcf/filesystem_tests/Sanity.java
Thu Dec 16 09:16:25 2010
@@ -139,7 +139,7 @@ public class Sanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       jobManager.manualStart(job.getID());
-      waitJobInactive(jobManager,job.getID());
+      waitJobInactive(jobManager,job.getID(),120000L);
 
       // Check to be sure we actually processed the right number of documents.
       JobStatus status = jobManager.getStatus(job.getID());
@@ -152,7 +152,7 @@ public class Sanity extends TestBase
 
       // Now, start the job, and wait until it completes.
       jobManager.manualStart(job.getID());
-      waitJobInactive(jobManager,job.getID());
+      waitJobInactive(jobManager,job.getID(),120000L);
 
       status = jobManager.getStatus(job.getID());
       // The test data area has 4 documents and one directory, and we have to count the root
directory too.
@@ -164,7 +164,7 @@ public class Sanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       jobManager.manualStart(job.getID());
-      waitJobInactive(jobManager,job.getID());
+      waitJobInactive(jobManager,job.getID(),120000L);
 
       status = jobManager.getStatus(job.getID());
       // The test data area has 4 documents and one directory, and we have to count the root
directory too.
@@ -178,7 +178,7 @@ public class Sanity extends TestBase
       
       // Now, start the job, and wait until it completes.
       jobManager.manualStart(job.getID());
-      waitJobInactive(jobManager,job.getID());
+      waitJobInactive(jobManager,job.getID(),120000L);
 
       // Check to be sure we actually processed the right number of documents.
       status = jobManager.getStatus(job.getID());
@@ -188,7 +188,7 @@ public class Sanity extends TestBase
 
       // Now, delete the job.
       jobManager.deleteJob(job.getID());
-      waitJobDeleted(jobManager,job.getID());
+      waitJobDeleted(jobManager,job.getID(),120000L);
       
       // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections
lying around.
     }
@@ -199,10 +199,11 @@ public class Sanity extends TestBase
     }
   }
   
-  protected void waitJobInactive(IJobManager jobManager, Long jobID)
+  protected void waitJobInactive(IJobManager jobManager, Long jobID, long maxTime)
     throws ManifoldCFException, InterruptedException
   {
-    while (true)
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
     {
       JobStatus status = jobManager.getStatus(jobID);
       if (status == null)
@@ -217,23 +218,26 @@ public class Sanity extends TestBase
         case JobStatus.JOBSTATUS_ERROR:
           throw new ManifoldCFException("Job reports error status: "+status.getErrorText());
         default:
-          ManifoldCF.sleep(10000L);
+          ManifoldCF.sleep(1000L);
           continue;
       }
-      break;
+      return;
     }
+    throw new ManifoldCFException("ManifoldCF did not terminate in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
   }
   
-  protected void waitJobDeleted(IJobManager jobManager, Long jobID)
+  protected void waitJobDeleted(IJobManager jobManager, Long jobID, long maxTime)
     throws ManifoldCFException, InterruptedException
   {
-    while (true)
+    long startTime = System.currentTimeMillis();
+    while (System.currentTimeMillis() < startTime + maxTime)
     {
       JobStatus status = jobManager.getStatus(jobID);
       if (status == null)
-        break;
-      ManifoldCF.sleep(10000L);
+        return;
+      ManifoldCF.sleep(1000L);
     }
+    throw new ManifoldCFException("ManifoldCF did not delete in the allotted time of "+new
Long(maxTime).toString()+" milliseconds");
   }
     
 



Mime
View raw message