You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by pr...@apache.org on 2012/02/27 18:48:23 UTC
svn commit: r1294245 - in /oodt/trunk/workflow/src:
main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java
test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
Author: pramirez
Date: Mon Feb 27 17:48:22 2012
New Revision: 1294245
URL: http://svn.apache.org/viewvc?rev=1294245&view=rev
Log:
OODT-389 Lucene Instance Repository now has an index that is initialized in the factory.
Modified:
oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java
oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
Modified: oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java?rev=1294245&r1=1294244&r2=1294245&view=diff
==============================================================================
--- oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java (original)
+++ oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/instrepo/LuceneWorkflowInstanceRepositoryFactory.java Mon Feb 27 17:48:22 2012
@@ -18,9 +18,17 @@
package org.apache.oodt.cas.workflow.instrepo;
+//JDK imports
+import java.io.File;
+import java.util.logging.Logger;
+
//OODT imports
import org.apache.oodt.cas.metadata.util.PathUtils;
+//Lucene imports
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.index.IndexWriter;
+
/**
* @author mattmann
* @version $Revision$
@@ -36,6 +44,9 @@ public class LuceneWorkflowInstanceRepos
private String indexFilePath = null;
private int pageSize = -1;
+
+ /* our log stream */
+ private static final Logger LOG = Logger.getLogger(LuceneWorkflowInstanceRepositoryFactory.class.getName());
public LuceneWorkflowInstanceRepositoryFactory()
throws InstantiationException {
@@ -61,6 +72,24 @@ public class LuceneWorkflowInstanceRepos
* @see org.apache.oodt.cas.workflow.instrepo.WorkflowInstanceRepositoryFactory#createInstanceRepository()
*/
public WorkflowInstanceRepository createInstanceRepository() {
+ File indexDir = new File(indexFilePath);
+ // Create the index if it does not already exist
+ IndexWriter writer = null;
+ if (!indexDir.exists()) {
+ try {
+ writer = new IndexWriter(indexDir, new StandardAnalyzer(), true);
+ } catch (Exception e) {
+ LOG.severe("Unable to create index: " + e.getMessage());
+ } finally {
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (Exception e) {
+ LOG.severe("Unable to close index: " + e.getMessage());
+ }
+ }
+ }
+ }
return new LuceneWorkflowInstanceRepository(indexFilePath, pageSize);
}
Modified: oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java?rev=1294245&r1=1294244&r2=1294245&view=diff
==============================================================================
--- oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java (original)
+++ oodt/trunk/workflow/src/test/org/apache/oodt/cas/workflow/instrepo/TestLuceneWorkflowInstanceRepository.java Mon Feb 27 17:48:22 2012
@@ -30,11 +30,13 @@ import org.apache.oodt.cas.workflow.stru
//JDK imports
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
+//Apache Imports
import org.apache.commons.io.FileUtils;
//Junit imports
@@ -52,9 +54,6 @@ import junit.framework.TestCase;
public class TestLuceneWorkflowInstanceRepository extends TestCase implements
WorkflowStatus {
- private static final String catalogPath = new File(
- "./target/instRepoTestCat").getAbsolutePath();
-
private LuceneWorkflowInstanceRepository repo = null;
private WorkflowInstance testInst = null;
@@ -65,25 +64,13 @@ public class TestLuceneWorkflowInstanceR
private WorkflowCondition testCond;
- private static final int defaultPgSz = 20;
+ private String tmpDirPath = null;
public TestLuceneWorkflowInstanceRepository() {
testInst = new WorkflowInstance();
testWkflw = new Workflow();
testTask = new WorkflowTask();
testCond = new WorkflowCondition();
-
- // check to see if catalog path exists: (it may b/c
- // the user may run many unit tests)
- // if it exists, blow it away
- if (new File(catalogPath).exists()) {
- try {
- FileUtils.deleteDirectory(new File(catalogPath));
- } catch (IOException e) {
- fail(e.getMessage());
- }
- }
- repo = new LuceneWorkflowInstanceRepository(catalogPath, defaultPgSz);
testWkflw.setName("test.workflow");
testWkflw.setId("test.id");
List tasks = new Vector();
@@ -114,6 +101,82 @@ public class TestLuceneWorkflowInstanceR
sharedContext.addMetadata("TestKey1", "TestVal2");
sharedContext.addMetadata("TestKey2", "TestVal3");
testInst.setSharedContext(sharedContext);
+
+ // first load the example configuration
+ try {
+ System.getProperties().load(
+ new FileInputStream("./src/main/resources/workflow.properties"));
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ // get a temp directory
+
+ File tempDir = null;
+ File tempFile = null;
+
+ try {
+ tempFile = File.createTempFile("foo", "bar");
+ tempFile.deleteOnExit();
+ tempDir = tempFile.getParentFile();
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
+
+ tmpDirPath = tempDir.getAbsolutePath();
+ if (!tmpDirPath.endsWith("/")) {
+ tmpDirPath += "/";
+ }
+
+ tmpDirPath += "testInstRepo/";
+
+ // now override the catalog ones
+ System.setProperty(
+ "org.apache.oodt.cas.workflow.instanceRep.lucene.idxPath",
+ tmpDirPath);
+
+ System.setProperty(
+ "org.apache.oodt.cas.workflow.instanceRep.pageSize", "20");
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ repo = (LuceneWorkflowInstanceRepository) new LuceneWorkflowInstanceRepositoryFactory().createInstanceRepository();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ // now remove the temporary directory used
+ if (tmpDirPath != null) {
+ FileUtils.forceDelete(new File(tmpDirPath));
+ }
+ if (repo != null) {
+ repo = null;
+ }
+
+ }
+
+ /**
+ * @since OODT-389
+ **/
+ public void testInstanceRepoInitialization() {
+ // Getting the number of workflow instances should not fail even on an empty index
+ try {
+ int count = repo.getNumWorkflowInstances();
+ // There should be no instances in the index at this point
+ assertEquals(0, count);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ }
}
public void testUpdateDocumentAndPreserveId() {
@@ -122,7 +185,6 @@ public class TestLuceneWorkflowInstanceR
} catch (InstanceRepositoryException e) {
fail(e.getMessage());
}
-
// preserve its id
String wInstId = testInst.getId();