Permalink
Browse files

added feature to setup searchd and indexer for tests

  • Loading branch information...
1 parent a21f162 commit 2a9d0d76646a99477fd493f17bf7d6a7324106db @erka committed Oct 15, 2009
View
@@ -4,3 +4,4 @@ target
.classpath
.settings
doc
+src/test/resources/junit.properties
View
@@ -20,7 +20,12 @@ This version has full compatibility with jdk 1.4.
== Requirements
Tests need searchd service with "test1" index. Checkout <tt>src/test/resources/sphinx_test.sql</tt> for the database setup.
-The indexer and searchd daemon are automatically started for the tests, but indexer and searchd must be in your path. *Does not work for windows at this moment*
+The indexer and searchd daemon are automatically started for the tests, but indexer and searchd must be in your path.
+If you don't have indexer or searchd daemons into your path, you should copy
+<tt>src/test/resources/junit-default.properties</tt> to <tt>src/test/resources/junit.properties</tt> and modify
+<tt>sphinx.searchd</tt> and <tt>sphinx.indexer</tt> values depends on your environment.
+
+*Does not work for windows at this moment*
== Building
@@ -7,6 +7,7 @@
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.sphx.util.JUnitProperties;
/**
*
@@ -15,6 +16,7 @@
public class SphinxRunner {
private static Logger logger = LoggerFactory.getLogger(SphinxRunner.class);
+ private static JUnitProperties junitProperties = new JUnitProperties();
static {
try {
start();
@@ -41,19 +43,19 @@ private static void start() throws IOException {
shutdown();
// indexer -c src/test/resources/sphinx.conf test1
- String[] command = new String[]{"indexer", "-c", "src/test/resources/sphinx.conf", "test1", "test2"};
+ String[] command = new String[]{ junitProperties.getSphinxIndexer(), "-c", "src/test/resources/sphinx.conf", "test1", "test2"};
logger.debug("Running indexer: {}", StringUtils.join( command, " " ) );
execute( command );
// searchd -c src/test/resources/sphinx.conf -p 4347
- command = new String[]{"searchd", "-c", "src/test/resources/sphinx.conf" };
+ command = new String[]{ junitProperties.getSphinxSearcherd(), "-c", "src/test/resources/sphinx.conf" };
logger.debug("Running searchd: {}", StringUtils.join( command, " " ) );
execute( command );
}
private static void shutdown() {
- String[] command = new String[]{"searchd", "-c", "src/test/resources/sphinx.conf", "--stop"};
+ String[] command = new String[]{ junitProperties.getSphinxSearcherd(), "-c", "src/test/resources/sphinx.conf", "--stop"};
logger.debug("Stopping searchd: {}", StringUtils.join( command, " " ) );
try {
// searchd -c src/test/resources/sphinx.conf -p 4347 --stop
@@ -0,0 +1,49 @@
+package org.sphx.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class JUnitProperties {
+ private static final String SPHINX_SEARCHERD_KEY = "sphinx.searchd";
+ private static final String SPHINX_INDEXER_KEY = "sphinx.indexer";
+
+ private static final String SPHINX_SEARCHERD_DEFAULT_CMD = "searchd";
+ private static final String SPHINX_INDEXER_DEFAULT_CMD = "indexer";
+
+ private static Logger logger = LoggerFactory.getLogger(JUnitProperties.class);
+ Properties properties = new Properties();
+
+ public JUnitProperties() {
+
+ InputStream propertiesInputStream = getClass().getResourceAsStream("/junit.properties");
+ if (propertiesInputStream != null) {
+ try {
+ properties.load(propertiesInputStream);
+ } catch (IOException ex) {
+ logger.warn("Located junit.properties but could not load from it", ex);
+ }
+ } else {
+ logger.info("junit.properties was not found. Use default configuration");
+ }
+ }
+
+ public String getSphinxSearcherd() {
+ String searcherd = properties.getProperty(SPHINX_SEARCHERD_KEY);
+ if (searcherd == null) {
+ searcherd = SPHINX_SEARCHERD_DEFAULT_CMD;
+ }
+ return searcherd;
+ }
+
+ public String getSphinxIndexer() {
+ String indexer = properties.getProperty(SPHINX_INDEXER_KEY);
+ if (indexer == null) {
+ indexer = SPHINX_INDEXER_DEFAULT_CMD;
+ }
+ return indexer;
+ }
+}
@@ -0,0 +1,2 @@
+sphinx.searchd=/path/to/sphinx/bin/searchd
+sphinx.indexer=/path/to/sphinx/bin/indexer

0 comments on commit 2a9d0d7

Please sign in to comment.