lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r634355 - /lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java
Date Thu, 06 Mar 2008 17:20:58 GMT
Author: mikemccand
Date: Thu Mar  6 09:20:56 2008
New Revision: 634355

URL: http://svn.apache.org/viewvc?rev=634355&view=rev
Log:
LUCENE-1204: improve TestStressIndexing2 test by interleaving deletes by term & query

Modified:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java

Modified: lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java?rev=634355&r1=634354&r2=634355&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/index/TestStressIndexing2.java Thu Mar  6
09:20:56 2008
@@ -19,6 +19,7 @@
 import org.apache.lucene.analysis.*;
 
 import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.search.TermQuery;
 
 import java.util.*;
 import java.io.ByteArrayOutputStream;
@@ -89,7 +90,6 @@
       int nThreads=r.nextInt(5)+1;
       int iter=r.nextInt(10)+1;
       int range=r.nextInt(20)+1;
-
       Directory dir1 = new MockRAMDirectory();
       Directory dir2 = new MockRAMDirectory();
       Map docs = indexRandom(nThreads, iter, range, dir1);
@@ -210,7 +210,13 @@
       if (term==null || term.field() != idField) break;
 
       termDocs1.seek (termEnum);
-      assertTrue(termDocs1.next());
+      if (!termDocs1.next()) {
+        // This doc is deleted and wasn't replaced
+        termDocs2.seek(termEnum);
+        assertFalse(termDocs2.next());
+        continue;
+      }
+
       int id1 = termDocs1.doc();
       assertFalse(termDocs1.next());
 
@@ -420,14 +426,16 @@
       return new String(arr);
     }
 
+    public String getIdString() {
+      return Integer.toString(base + nextInt(range));
+    }
 
     public void indexDoc() throws IOException {
       Document d = new Document();
 
       ArrayList fields = new ArrayList();      
-      int id = base + nextInt(range);
-      String idString = ""+id;
-      Field idField =  new Field("id", idString, Field.Store.YES, Field.Index.NO_NORMS);
+      String idString = getIdString();
+      Field idField =  new Field(idTerm.field(), idString, Field.Store.YES, Field.Index.NO_NORMS);
       fields.add(idField);
 
       int nFields = nextInt(maxFields);
@@ -480,11 +488,30 @@
       docs.put(idString, d);
     }
 
+    public void deleteDoc() throws IOException {
+      String idString = getIdString();
+      w.deleteDocuments(idTerm.createTerm(idString));
+      docs.remove(idString);
+    }
+
+    public void deleteByQuery() throws IOException {
+      String idString = getIdString();
+      w.deleteDocuments(new TermQuery(idTerm.createTerm(idString)));
+      docs.remove(idString);
+    }
+
     public void run() {
       try {
         r = new Random(base+range+seed);
         for (int i=0; i<iterations; i++) {
-          indexDoc();
+          int what = nextInt(100);
+          if (what < 5) {
+            deleteDoc();
+          } else if (what < 10) {
+            deleteByQuery();
+          } else {
+            indexDoc();
+          }
         }
       } catch (Exception e) {
         e.printStackTrace();



Mime
View raw message