Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add integration testing across index updates.

  • Loading branch information...
commit 7c8ce485e1c6c7407055abdfb28831400b64473e 1 parent 0cb9bb7
Robert Newson authored
2  src/main/java/com/github/rnewson/couchdb/lucene/Database.java
View
@@ -169,7 +169,7 @@ private String execute(final HttpMethodBase method) throws IOException {
try {
final int sc = CLIENT.executeMethod(method);
if (sc < 200 || sc > 299) {
- throw new HttpException("Unexpected status code: " + sc);
+ throw new HttpException("Unexpected status code: " + sc + ": " + method.getStatusText());
}
final InputStream in = method.getResponseBodyAsStream();
try {
1  src/main/java/com/github/rnewson/couchdb/lucene/Main.java
View
@@ -28,6 +28,7 @@ public static void main(final String[] args) throws Exception {
if (System.getProperty("couchdb.log.dir") == null) {
System.setProperty("couchdb.log.dir", System.getProperty("java.io.tmpdir"));
}
+
if (args.length >= 1 && args[0].equals("-index")) {
Index.main(args);
return;
24 src/test/java/com/github/rnewson/couchdb/lucene/IntegrationTest.java
View
@@ -1,5 +1,6 @@
package com.github.rnewson.couchdb.lucene;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -31,10 +32,15 @@ public void setup() throws IOException, InterruptedException {
db = new Database(base);
try {
db.deleteDatabase(dbname);
+ SECONDS.sleep(6);
db.createDatabase(dbname);
} catch (final IOException e) {
+ // Bail here if couch isn't running.
assumeTrue(false);
}
+
+ final String ddoc = "{\"fulltext\": {\"idx\": {\"index\":\"function(doc) {var ret=new Document(); ret.add(doc.content); return ret;}\"}}}";
+ assertThat(db.saveDocument(dbname, "_design/lucene", ddoc), is(true));
}
@After
@@ -44,8 +50,6 @@ public void teardown() throws IOException {
@Test
public void index() throws IOException, InterruptedException {
- final String ddoc = "{\"fulltext\": {\"idx\": {\"index\":\"function(doc) {var ret=new Document(); ret.add(doc.content); return ret;}\"}}}";
- assertThat(db.saveDocument(dbname, "_design/lucene", ddoc), is(true));
for (int i = 0; i < 50; i++) {
assertThat(db.saveDocument(dbname, "doc-" + i, "{\"content\":\"hello\"}"), is(true));
}
@@ -59,4 +63,20 @@ public void index() throws IOException, InterruptedException {
assertThat(queryResult.getInt("total_rows"), is(50));
}
+ @Test
+ public void longIndex() throws IOException, InterruptedException {
+ for (int i = 0; i < 20; i++) {
+ assertThat(db.saveDocument(dbname, "doc-" + i, "{\"content\":\"hello\"}"), is(true));
+ MILLISECONDS.sleep(500);
+ }
+
+ SECONDS.sleep(6);
+
+ final JSONObject indexState = db.getDoc(dbname, "_fti");
+ assertThat(indexState.getInt("doc_count"), is(21));
+
+ final JSONObject queryResult = db.getDoc(dbname, "/_fti/lucene/idx?q=hello");
+ assertThat(queryResult.getInt("total_rows"), is(20));
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.