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/06/08 22:27:54 UTC
svn commit: r952805 - in /incubator/lcf/trunk/modules: ./
connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/
framework/tests/org/apache/lcf/crawler/tests/ tests/ tests/lib/
tests/org/apache/lcf/tests/ tests/war/
Author: kwright
Date: Tue Jun 8 20:27:54 2010
New Revision: 952805
URL: http://svn.apache.org/viewvc?rev=952805&view=rev
Log:
Hook up module-level tests, including a runt sanity test (to be fleshed out more completely over time).
Added:
incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java (with props)
Removed:
incubator/lcf/trunk/modules/tests/build.xml
incubator/lcf/trunk/modules/tests/lib/
incubator/lcf/trunk/modules/tests/war/
Modified:
incubator/lcf/trunk/modules/build.xml
incubator/lcf/trunk/modules/connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/TestBase.java
incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java
Modified: incubator/lcf/trunk/modules/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/build.xml?rev=952805&r1=952804&r2=952805&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/build.xml (original)
+++ incubator/lcf/trunk/modules/build.xml Tue Jun 8 20:27:54 2010
@@ -3,6 +3,7 @@
<target name="clean">
<delete dir="build"/>
<delete dir="dist"/>
+ <delete dir="test-output"/>
<ant dir="framework" target="clean"/>
<delete dir="framework/lib"/>
<ant dir="connectors/activedirectory" target="clean"/>
@@ -706,6 +707,54 @@
<jar destfile="dist/web/war/lcf-authority-service.war" basedir="build/authority-service"/>
</target>
+ <target name="calculate-tests-condition" depends="calculate-filesystem-condition,calculate-nulloutput-condition">
+ <condition property="tests.include">
+ <and>
+ <isset property="filesystem.include"/>
+ <isset property="nulloutput.include"/>
+ </and>
+ </condition>
+ </target>
+
+ <target name="compile-tests" depends="build-framework,calculate-tests-condition,build-filesystem-connector,build-nulloutput-connector" if="tests.include">
+ <mkdir dir="build/tests/classes"/>
+ <javac srcdir="tests" destdir="build/tests/classes" target="1.5" source="1.5" debug="true" debuglevel="lines,vars,source">
+ <classpath>
+ <fileset dir="framework/lib">
+ <include name="*.jar"/>
+ </fileset>
+ <pathelement location="framework/build/core/classes"/>
+ <pathelement location="framework/build/ui-core/classes"/>
+ <pathelement location="framework/build/agents/classes"/>
+ <pathelement location="framework/build/pull-agent/classes"/>
+ <pathelement location="framework/build/tests/classes"/>
+ <pathelement location="connectors/filesystem/build/connector/classes"/>
+ <pathelement location="connectors/nulloutput/build/connector/classes"/>
+ </classpath>
+ </javac>
+ </target>
+
+ <target name="run-tests" depends="compile-tests,calculate-tests-condition" if="tests.include">
+ <mkdir dir="test-output"/>
+ <junit fork="true" maxmemory="128m" dir="test-output" showoutput="true">
+ <classpath>
+ <fileset dir="framework/lib">
+ <include name="*.jar"/>
+ </fileset>
+ <pathelement location="framework/build/core/classes"/>
+ <pathelement location="framework/build/ui-core/classes"/>
+ <pathelement location="framework/build/agents/classes"/>
+ <pathelement location="framework/build/pull-agent/classes"/>
+ <pathelement location="framework/build/tests/classes"/>
+ <pathelement location="connectors/filesystem/build/connector/classes"/>
+ <pathelement location="connectors/nulloutput/build/connector/classes"/>
+ <pathelement location="build/tests/classes"/>
+ </classpath>
+ <test name="org.apache.lcf.tests.Sanity" todir="test-output"/>
+ <!-- MHL -->
+ </junit>
+ </target>
+
<target name="deliver-open-connectors" depends="deliver-activedirectory-connector,deliver-filesystem-connector,deliver-rss-connector,deliver-webcrawler-connector,deliver-jdbc-connector"/>
<target name="deliver-output-connectors" depends="deliver-gts-connector,deliver-solr-connector,deliver-nulloutput-connector"/>
@@ -714,7 +763,7 @@
<target name="deliver-proprietary-connectors" depends="deliver-documentum-connector,deliver-filenet-connector,deliver-livelink-connector,deliver-memex-connector,deliver-meridio-connector,deliver-sharepoint-connector"/>
- <target name="all" depends="deliver-database-support,deliver-framework,deliver-open-connectors,deliver-output-connectors,deliver-lgpl-connectors,deliver-proprietary-connectors,deliver-wars"/>
+ <target name="all" depends="deliver-database-support,deliver-framework,deliver-open-connectors,deliver-output-connectors,deliver-lgpl-connectors,deliver-proprietary-connectors,deliver-wars,run-tests"/>
</project>
Modified: incubator/lcf/trunk/modules/connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/TestBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/TestBase.java?rev=952805&r1=952804&r2=952805&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/TestBase.java (original)
+++ incubator/lcf/trunk/modules/connectors/filesystem/tests/org/apache/lcf/crawler/connectors/filesystem/tests/TestBase.java Tue Jun 8 20:27:54 2010
@@ -31,14 +31,14 @@ import org.junit.*;
public class TestBase extends org.apache.lcf.crawler.tests.TestConnectorBase
{
- protected String getConnectorName()
+ protected String[] getConnectorNames()
{
- return "File Connector";
+ return new String[]{"File Connector"};
}
- protected String getConnectorClass()
+ protected String[] getConnectorClasses()
{
- return "org.apache.lcf.crawler.connectors.filesystem.FileConnector";
+ return new String[]{"org.apache.lcf.crawler.connectors.filesystem.FileConnector"};
}
}
Modified: incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java?rev=952805&r1=952804&r2=952805&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java (original)
+++ incubator/lcf/trunk/modules/framework/tests/org/apache/lcf/crawler/tests/TestConnectorBase.java Tue Jun 8 20:27:54 2010
@@ -21,18 +21,46 @@ package org.apache.lcf.crawler.tests;
import org.apache.lcf.core.interfaces.*;
import org.apache.lcf.agents.interfaces.*;
import org.apache.lcf.crawler.interfaces.*;
-import org.apache.lcf.crawler.system.LCF;
+import org.apache.lcf.authorities.interfaces.*;
+import org.apache.lcf.core.system.LCF;
import java.io.*;
import java.util.*;
import org.junit.*;
/** This is a testing base class that is responsible for setting up/tearing down the agents framework. */
-public abstract class TestConnectorBase extends org.apache.lcf.crawler.tests.TestBase
+public class TestConnectorBase extends org.apache.lcf.crawler.tests.TestBase
{
- protected abstract String getConnectorClass();
- protected abstract String getConnectorName();
+ protected String[] getConnectorClasses()
+ {
+ return new String[0];
+ }
+
+ protected String[] getConnectorNames()
+ {
+ return new String[0];
+ }
+
+ protected String[] getAuthorityClasses()
+ {
+ return new String[0];
+ }
+
+ protected String[] getAuthorityNames()
+ {
+ return new String[0];
+ }
+
+ protected String[] getOutputClasses()
+ {
+ return new String[0];
+ }
+
+ protected String[] getOutputNames()
+ {
+ return new String[0];
+ }
@Before
public void setUp()
@@ -52,8 +80,6 @@ public abstract class TestConnectorBase
protected void localSetUp()
throws Exception
{
- String connectorClass = getConnectorClass();
- String connectorName = getConnectorName();
super.localSetUp();
@@ -66,20 +92,62 @@ public abstract class TestConnectorBase
LCF.getMasterDatabaseName(),
LCF.getMasterDatabaseUsername(),
LCF.getMasterDatabasePassword());
+
IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+ IAuthorityConnectorManager authMgr = AuthorityConnectorManagerFactory.make(tc);
IJobManager jobManager = JobManagerFactory.make(tc);
IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+ IOutputConnectorManager outputMgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager outputConnManager = OutputConnectionManagerFactory.make(tc);
+
// Deregistration should be done in a transaction
database.beginTransaction();
try
{
- // First, register connector
- mgr.registerConnector(connectorName,connectorClass);
- // Then, signal to all jobs that might depend on this connector that they can switch state
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(connectorClass);
- // For each connection name, modify the jobs to note that the connector is now installed
- jobManager.noteConnectorRegistration(connectionNames);
+ int i;
+
+ String[] connectorClasses = getConnectorClasses();
+ String[] connectorNames = getConnectorNames();
+
+ i = 0;
+ while (i < connectorClasses.length)
+ {
+ // First, register connector
+ mgr.registerConnector(connectorNames[i],connectorClasses[i]);
+ // Then, signal to all jobs that might depend on this connector that they can switch state
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(connectorClasses[i]);
+ // For each connection name, modify the jobs to note that the connector is now installed
+ jobManager.noteConnectorRegistration(connectionNames);
+ i++;
+ }
+
+ String[] authorityClasses = getAuthorityClasses();
+ String[] authorityNames = getAuthorityNames();
+
+ i = 0;
+ while (i < authorityClasses.length)
+ {
+ authMgr.registerConnector(authorityNames[i],authorityClasses[i]);
+ i++;
+ }
+
+ String[] outputClasses = getOutputClasses();
+ String[] outputNames = getOutputNames();
+
+ i = 0;
+ while (i < outputClasses.length)
+ {
+ // First, register connector
+ outputMgr.registerConnector(outputNames[i],outputClasses[i]);
+ // Then, signal to all jobs that might depend on this connector that they can switch state
+ // Find the connection names that come with this class
+ String[] connectionNames = outputConnManager.findConnectionsForConnector(outputClasses[i]);
+ // For all connection names, notify all agents of the registration
+ AgentManagerFactory.noteOutputConnectorRegistration(tc,connectionNames);
+ i++;
+ }
+
}
catch (LCFException e)
{
@@ -107,7 +175,6 @@ public abstract class TestConnectorBase
protected void localCleanUp()
throws Exception
{
- String connectorClass = getConnectorClass();
initialize();
if (propertiesFile.exists())
{
@@ -116,25 +183,174 @@ public abstract class TestConnectorBase
IThreadContext tc = ThreadContextFactory.make();
Exception currentException = null;
+ // First, tear down all jobs, connections, authority connections, and output connections.
+ try
+ {
+ IJobManager jobManager = JobManagerFactory.make(tc);
+ IRepositoryConnectionManager connMgr = RepositoryConnectionManagerFactory.make(tc);
+ IAuthorityConnectionManager authConnMgr = AuthorityConnectionManagerFactory.make(tc);
+ IOutputConnectionManager outputMgr = OutputConnectionManagerFactory.make(tc);
+
+ // Get a list of the current active jobs
+ IJobDescription[] jobs = jobManager.getAllJobs();
+ int i = 0;
+ while (i < jobs.length)
+ {
+ IJobDescription desc = jobs[i++];
+ // Abort this job, if it is running
+ try
+ {
+ jobManager.manualAbort(desc.getID());
+ }
+ catch (LCFException e)
+ {
+ // This generally means that the job was not running
+ }
+ }
+ i = 0;
+ while (i < jobs.length)
+ {
+ IJobDescription desc = jobs[i++];
+ // Wait for this job to stop
+ while (true)
+ {
+ JobStatus status = jobManager.getStatus(desc.getID());
+ if (status != null)
+ {
+ int statusValue = status.getStatus();
+ switch (statusValue)
+ {
+ case JobStatus.JOBSTATUS_NOTYETRUN:
+ case JobStatus.JOBSTATUS_COMPLETED:
+ case JobStatus.JOBSTATUS_ERROR:
+ break;
+ default:
+ LCF.sleep(10000);
+ continue;
+ }
+ }
+ break;
+ }
+ }
+
+ // Now, delete them all
+ i = 0;
+ while (i < jobs.length)
+ {
+ IJobDescription desc = jobs[i++];
+ try
+ {
+ jobManager.deleteJob(desc.getID());
+ }
+ catch (LCFException e)
+ {
+ // This usually means that the job is already being deleted
+ }
+ }
+
+ i = 0;
+ while (i < jobs.length)
+ {
+ IJobDescription desc = jobs[i++];
+ // Wait for this job to disappear
+ while (true)
+ {
+ JobStatus status = jobManager.getStatus(desc.getID());
+ if (status != null)
+ {
+ LCF.sleep(10000);
+ continue;
+ }
+ break;
+ }
+ }
+
+ // Now, get a list of the repository connections
+ IRepositoryConnection[] connections = connMgr.getAllConnections();
+ i = 0;
+ while (i < connections.length)
+ {
+ connMgr.delete(connections[i++].getName());
+ }
+
+ // Get a list of authority connections
+ IAuthorityConnection[] authorities = authConnMgr.getAllConnections();
+ i = 0;
+ while (i < authorities.length)
+ {
+ authConnMgr.delete(authorities[i++].getName());
+ }
+
+ // Finally, get rid of output connections
+ IOutputConnection[] outputs = outputMgr.getAllConnections();
+ i = 0;
+ while (i < outputs.length)
+ {
+ outputMgr.delete(outputs[i++].getName());
+ }
+
+ }
+ catch (Exception e)
+ {
+ currentException = e;
+ }
try
{
IDBInterface database = DBInterfaceFactory.make(tc,
LCF.getMasterDatabaseName(),
LCF.getMasterDatabaseUsername(),
LCF.getMasterDatabasePassword());
+
IConnectorManager mgr = ConnectorManagerFactory.make(tc);
+ IAuthorityConnectorManager authMgr = AuthorityConnectorManagerFactory.make(tc);
+ IOutputConnectorManager outputMgr = OutputConnectorManagerFactory.make(tc);
+ IOutputConnectionManager outputConnManager = OutputConnectionManagerFactory.make(tc);
IJobManager jobManager = JobManagerFactory.make(tc);
IRepositoryConnectionManager connManager = RepositoryConnectionManagerFactory.make(tc);
+
// Deregistration should be done in a transaction
database.beginTransaction();
try
{
- // Find the connection names that come with this class
- String[] connectionNames = connManager.findConnectionsForConnector(connectorClass);
- // For each connection name, modify the jobs to note that the connector is no longer installed
- jobManager.noteConnectorDeregistration(connectionNames);
- // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
- mgr.unregisterConnector(connectorClass);
+ int i;
+
+ String[] connectorClasses = getConnectorClasses();
+
+ i = 0;
+ while (i < connectorClasses.length)
+ {
+ // Find the connection names that come with this class
+ String[] connectionNames = connManager.findConnectionsForConnector(connectorClasses[i]);
+ // For each connection name, modify the jobs to note that the connector is no longer installed
+ jobManager.noteConnectorDeregistration(connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ mgr.unregisterConnector(connectorClasses[i]);
+ i++;
+ }
+
+ String[] authorityClasses = getAuthorityClasses();
+
+ i = 0;
+ while (i < authorityClasses.length)
+ {
+ authMgr.unregisterConnector(authorityClasses[i]);
+ i++;
+ }
+
+ String[] outputClasses = getOutputClasses();
+
+ i = 0;
+ while (i < outputClasses.length)
+ {
+ // Find the connection names that come with this class
+ String[] connectionNames = outputConnManager.findConnectionsForConnector(outputClasses[i]);
+ // For all connection names, notify all agents of the deregistration
+ AgentManagerFactory.noteOutputConnectorDeregistration(tc,connectionNames);
+ // Now that all jobs have been placed into an appropriate state, actually do the deregistration itself.
+ outputMgr.unregisterConnector(outputClasses[i]);
+ i++;
+ }
+
}
catch (LCFException e)
{
Added: 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=952805&view=auto
==============================================================================
--- incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java (added)
+++ incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java Tue Jun 8 20:27:54 2010
@@ -0,0 +1,88 @@
+/* $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.lcf.tests;
+
+import org.apache.lcf.core.interfaces.*;
+import org.apache.lcf.agents.interfaces.*;
+import org.apache.lcf.crawler.interfaces.*;
+import org.apache.lcf.crawler.system.LCF;
+
+import java.io.*;
+import java.util.*;
+import org.junit.*;
+
+/** This is a very basic sanity check */
+public class Sanity extends org.apache.lcf.crawler.tests.TestConnectorBase
+{
+
+ protected String[] getConnectorNames()
+ {
+ return new String[]{"File Connector"};
+ }
+
+ protected String[] getConnectorClasses()
+ {
+ return new String[]{"org.apache.lcf.crawler.connectors.filesystem.FileConnector"};
+ }
+
+ protected String[] getOutputNames()
+ {
+ return new String[]{"Null Output"};
+ }
+
+ protected String[] getOutputClasses()
+ {
+ return new String[]{"org.apache.lcf.agents.output.nullconnector.NullConnector"};
+ }
+
+ @Test
+ public void sanityCheck()
+ throws Exception
+ {
+ // 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.lcf.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.lcf.agents.output.nullconnector.NullConnector");
+ outputConn.setMaxConnections(100);
+ // Now, save
+ outputMgr.save(outputConn);
+
+ // MHL
+
+ // Cleanup is automatic by the base class, so we can feel free to leave jobs and connections lying around.
+ }
+
+
+}
Propchange: incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/trunk/modules/tests/org/apache/lcf/tests/Sanity.java
------------------------------------------------------------------------------
svn:keywords = Id