lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1066850 - in /lucene/dev/trunk/solr/src/test/org/apache/solr: JSONTestUtil.java SolrTestCaseJ4.java
Date Thu, 03 Feb 2011 16:14:07 GMT
Author: yonik
Date: Thu Feb  3 16:14:07 2011
New Revision: 1066850

URL: http://svn.apache.org/viewvc?rev=1066850&view=rev
Log:
tests: get model order from index, fix some json numeric comparisons

Modified:
    lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java
    lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java?rev=1066850&r1=1066849&r2=1066850&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/JSONTestUtil.java Thu Feb  3 16:14:07 2011
@@ -135,14 +135,16 @@ class CollectionTester {
     if (!expected.equals(val)) {
 
       // make an exception for some numerics
-      if (expected instanceof Integer && val instanceof Long || expected instanceof
Long && val instanceof Integer
+      if ((expected instanceof Integer && val instanceof Long || expected instanceof
Long && val instanceof Integer)
           && ((Number)expected).longValue() == ((Number)val).longValue())
       {
-        // OK
-      } else if (expected instanceof Float && val instanceof Double || expected instanceof
Double && val instanceof Float
-          && ((Number)expected).doubleValue() == ((Number)val).doubleValue())
-      {
-        // OK
+        return true;
+      } else if ((expected instanceof Float && val instanceof Double || expected
instanceof Double && val instanceof Float)) {
+        double a = ((Number)expected).doubleValue();
+        double b = ((Number)val).doubleValue();
+        if (Double.compare(a,b) == 0) return true;
+        if (Math.abs(a-b) < 1e-5) return true;
+        return false;
       } else {
         setErr("mismatch: '" + expected + "'!='" + val + "'");
         return false;

Modified: lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java?rev=1066850&r1=1066849&r2=1066850&view=diff
==============================================================================
--- lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/src/test/org/apache/solr/SolrTestCaseJ4.java Thu Feb  3 16:14:07
2011
@@ -22,6 +22,7 @@ package org.apache.solr;
 import org.apache.lucene.util.LuceneTestCase;
 import org.apache.noggit.CharArr;
 import org.apache.noggit.JSONUtil;
+import org.apache.noggit.ObjectBuilder;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
 import org.apache.solr.common.SolrInputField;
@@ -837,17 +838,9 @@ public abstract class SolrTestCaseJ4 ext
     // commit an average of 10 times for large sets, or 10% of the time for small sets
     int commitOneOutOf = Math.max(nDocs/10, 10);
 
-
-    // find the max order (docid) and start from there
-    int order = -1;
-    for (Doc doc : model.values()) {
-      order = Math.max(order, doc.order);
-    }
-    order++;
-
     for (int i=0; i<nDocs; i++) {
       Doc doc = createDoc(descriptor);
-      doc.order = order++;
+      // doc.order = order++;
       updateJ(toJSON(doc), null);
       model.put(doc.id, doc);
 
@@ -870,6 +863,25 @@ public abstract class SolrTestCaseJ4 ext
       assertU(commit());
     }
 
+    // merging segments no longer selects just adjacent segments hence ids (doc.order) can
be shuffled.
+    // we need to look at the index to determine the order.
+    String responseStr = h.query(req("q","*:*", "fl","id", "sort","_docid_ asc", "rows",Integer.toString(model.size()*2),
"wt","json", "indent","true"));
+    Object response = ObjectBuilder.fromJSON(responseStr);
+
+    response = ((Map)response).get("response");
+    response = ((Map)response).get("docs");
+    List<Map> docList = (List<Map>)response;
+    int order = 0;
+    for (Map doc : docList) {
+      Object id = doc.get("id");
+      Doc modelDoc = model.get(id);
+      if (modelDoc == null) continue;  // may be some docs in the index that aren't modeled
+      modelDoc.order = order++;
+    }
+
+    // make sure we updated the order of all docs in the model
+    assertEquals(order, model.size());
+
     return model;
   }
 



Mime
View raw message