lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sha...@apache.org
Subject [20/50] [abbrv] lucene-solr:jira/solr-11990: SOLR-11598: Fix test case + class name typo
Date Sat, 28 Jul 2018 04:49:43 GMT
SOLR-11598: Fix test case + class name typo


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/877bde73
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/877bde73
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/877bde73

Branch: refs/heads/jira/solr-11990
Commit: 877bde7347794c93569201040538edfdae057709
Parents: 028c86b
Author: Varun Thacker <varun@apache.org>
Authored: Mon Jul 23 12:21:59 2018 -0700
Committer: Varun Thacker <varun@apache.org>
Committed: Mon Jul 23 12:21:59 2018 -0700

----------------------------------------------------------------------
 .../apache/solr/handler/export/DoubeValue.java  |  81 --------------
 .../apache/solr/handler/export/DoubleValue.java |  81 ++++++++++++++
 .../solr/handler/export/TestExportWriter.java   | 106 +++++++++----------
 3 files changed, 131 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/877bde73/solr/core/src/java/org/apache/solr/handler/export/DoubeValue.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/export/DoubeValue.java b/solr/core/src/java/org/apache/solr/handler/export/DoubeValue.java
deleted file mode 100644
index a37e13d..0000000
--- a/solr/core/src/java/org/apache/solr/handler/export/DoubeValue.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.solr.handler.export;
-
-import java.io.IOException;
-
-import org.apache.lucene.index.DocValues;
-import org.apache.lucene.index.LeafReader;
-import org.apache.lucene.index.LeafReaderContext;
-import org.apache.lucene.index.NumericDocValues;
-
-class DoubleValue implements SortValue {
-
-  protected NumericDocValues vals;
-  protected String field;
-  protected double currentValue;
-  protected DoubleComp comp;
-  private int lastDocID;
-  private LeafReader reader;
-
-  public DoubleValue(String field, DoubleComp comp) {
-    this.field = field;
-    this.comp = comp;
-    this.currentValue = comp.resetValue();
-  }
-
-  public DoubleValue copy() {
-    return new DoubleValue(field, comp);
-  }
-
-  public void setNextReader(LeafReaderContext context) throws IOException {
-    this.reader = context.reader();
-    this.vals = DocValues.getNumeric(this.reader, this.field);
-    lastDocID = 0;
-  }
-
-  public void setCurrentValue(int docId) throws IOException {
-    if (docId < lastDocID) {
-      throw new AssertionError("docs were sent out-of-order: lastDocID=" + lastDocID + "
vs doc=" + docId);
-    }
-    lastDocID = docId;
-    int curDocID = vals.docID();
-    if (docId > curDocID) {
-      curDocID = vals.advance(docId);
-    }
-    if (docId == curDocID) {
-      currentValue = Double.longBitsToDouble(vals.longValue());
-    } else {
-      currentValue = 0f;
-    }
-  }
-
-  public void setCurrentValue(SortValue sv) {
-    DoubleValue dv = (DoubleValue)sv;
-    this.currentValue = dv.currentValue;
-  }
-
-  public void reset() {
-    this.currentValue = comp.resetValue();
-  }
-
-  public int compareTo(SortValue o) {
-    DoubleValue dv = (DoubleValue)o;
-    return comp.compare(currentValue, dv.currentValue);
-  }
-}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/877bde73/solr/core/src/java/org/apache/solr/handler/export/DoubleValue.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/export/DoubleValue.java b/solr/core/src/java/org/apache/solr/handler/export/DoubleValue.java
new file mode 100644
index 0000000..a37e13d
--- /dev/null
+++ b/solr/core/src/java/org/apache/solr/handler/export/DoubleValue.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.solr.handler.export;
+
+import java.io.IOException;
+
+import org.apache.lucene.index.DocValues;
+import org.apache.lucene.index.LeafReader;
+import org.apache.lucene.index.LeafReaderContext;
+import org.apache.lucene.index.NumericDocValues;
+
+class DoubleValue implements SortValue {
+
+  protected NumericDocValues vals;
+  protected String field;
+  protected double currentValue;
+  protected DoubleComp comp;
+  private int lastDocID;
+  private LeafReader reader;
+
+  public DoubleValue(String field, DoubleComp comp) {
+    this.field = field;
+    this.comp = comp;
+    this.currentValue = comp.resetValue();
+  }
+
+  public DoubleValue copy() {
+    return new DoubleValue(field, comp);
+  }
+
+  public void setNextReader(LeafReaderContext context) throws IOException {
+    this.reader = context.reader();
+    this.vals = DocValues.getNumeric(this.reader, this.field);
+    lastDocID = 0;
+  }
+
+  public void setCurrentValue(int docId) throws IOException {
+    if (docId < lastDocID) {
+      throw new AssertionError("docs were sent out-of-order: lastDocID=" + lastDocID + "
vs doc=" + docId);
+    }
+    lastDocID = docId;
+    int curDocID = vals.docID();
+    if (docId > curDocID) {
+      curDocID = vals.advance(docId);
+    }
+    if (docId == curDocID) {
+      currentValue = Double.longBitsToDouble(vals.longValue());
+    } else {
+      currentValue = 0f;
+    }
+  }
+
+  public void setCurrentValue(SortValue sv) {
+    DoubleValue dv = (DoubleValue)sv;
+    this.currentValue = dv.currentValue;
+  }
+
+  public void reset() {
+    this.currentValue = comp.resetValue();
+  }
+
+  public int compareTo(SortValue o) {
+    DoubleValue dv = (DoubleValue)o;
+    return comp.compare(currentValue, dv.currentValue);
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/877bde73/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
index 55efdee..8b7de24 100644
--- a/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
+++ b/solr/core/src/test/org/apache/solr/handler/export/TestExportWriter.java
@@ -22,13 +22,16 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4;
 import org.apache.solr.common.SolrInputDocument;
+import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.util.SuppressForbidden;
 import org.apache.solr.common.util.Utils;
 import org.apache.solr.request.SolrQueryRequest;
@@ -41,6 +44,7 @@ import org.codehaus.jackson.map.ObjectMapper;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.noggit.ObjectBuilder;
 
 public class TestExportWriter extends SolrTestCaseJ4 {
   
@@ -594,7 +598,7 @@ public class TestExportWriter extends SolrTestCaseJ4 {
           "field1_s_dv", String.valueOf(str_vals[number]),
           "field2_i_p", String.valueOf(number),
           "field3_l_p", String.valueOf(number)));
-      if (numDocs % 3000 ==0) {
+      if (numDocs % 300 ==0) {
         assertU(commit());
       }
     }
@@ -624,66 +628,56 @@ public class TestExportWriter extends SolrTestCaseJ4 {
     String fieldsStr = String.join(",", fieldStrs); // fl :  field1, field2
 
     String resp = h.query(req("q", "*:*", "qt", "/export", "fl", "id," + fieldsStr, "sort",
sortStr));
-
-    //We cannot compare /select vs /export as for docs with the same values ( ties ) the
ordering is different
-    SolrQueryRequest req = null;
-    try {
-      req = req("q", "*:*", "qt", "/select", "fl", "id," + fieldsStr, "sort", sortStr, "rows",
Integer.toString(numDocs));
-
-      SolrQueryResponse selectRsp = h.queryAndResponse("", req);
-      DocList selectDocList = ((ResultContext)selectRsp.getResponse()).getDocList();
-      assert selectDocList.size() == numDocs;
-      DocIterator selectDocListIter = selectDocList.iterator();
-
-      ObjectMapper mapper = new ObjectMapper();
-      HashMap respMap = mapper.readValue(resp, HashMap.class);
-      List docs = (ArrayList) ((HashMap) respMap.get("response")).get("docs");
-      assert docs.size() == numDocs;
-
-      for (int i = 0; i < docs.size() - 1; i++) { // docs..
-        assertEquals("Position:" + i + " has different id value" , String.valueOf(selectDocListIter.nextDoc()),
String.valueOf(((HashMap) docs.get(i)).get("id")));
-
-        for (int j = 0; j < fieldSorts.length; j++) { // fields ..
-          String field = fieldSorts[j].getField();
-          String sort = fieldSorts[j].getSort();
-          String fieldVal1 = String.valueOf(((HashMap) docs.get(i)).get(field)); // 1st doc
-          String fieldVal2 = String.valueOf(((HashMap) docs.get(i + 1)).get(field)); // 2nd
obj
-          if (fieldVal1.equals(fieldVal2)) {
-            continue;
+    ObjectMapper mapper = new ObjectMapper();
+    HashMap respMap = mapper.readValue(resp, HashMap.class);
+    List docs = (ArrayList) ((HashMap) respMap.get("response")).get("docs");
+
+    SolrQueryRequest selectReq = req("q", "*:*", "qt", "/select", "fl", "id," + fieldsStr,
"sort", sortStr, "rows", Integer.toString(numDocs), "wt", "json");
+    String response = h.query(selectReq);
+    Map rsp = (Map)ObjectBuilder.fromJSON(response);
+    List doclist = (List)(((Map)rsp.get("response")).get("docs"));
+
+    assert docs.size() == numDocs;
+
+    for (int i = 0; i < docs.size() - 1; i++) { // docs..
+      assertEquals("Position:" + i + " has different id value" , ((LinkedHashMap)doclist.get(i)).get("id"),
String.valueOf(((HashMap) docs.get(i)).get("id")));
+
+      for (int j = 0; j < fieldSorts.length; j++) { // fields ..
+        String field = fieldSorts[j].getField();
+        String sort = fieldSorts[j].getSort();
+        String fieldVal1 = String.valueOf(((HashMap) docs.get(i)).get(field)); // 1st doc
+        String fieldVal2 = String.valueOf(((HashMap) docs.get(i + 1)).get(field)); // 2nd
obj
+        if (fieldVal1.equals(fieldVal2)) {
+          continue;
+        } else {
+          if (sort.equals("asc")) {
+            if (field.equals("stringdv") || field.equals("field1_s_dv")|| field.equals("datedv")
|| field.equals("booleandv")) { // use string comparator
+              assertTrue(fieldVal1.compareTo(fieldVal2) < 0);
+            } else if (field.equals("doubledv")){
+              assertTrue(Double.compare(Double.valueOf(fieldVal1), Double.valueOf(fieldVal2))
<= 0);
+            } else if(field.equals("floatdv")) {
+              assertTrue(Float.compare(Float.valueOf(fieldVal1), Float.valueOf(fieldVal2))
<= 0);
+            } else if(field.equals("intdv") || "field2_i_p".equals(field)) {
+              assertTrue(Integer.compare(Integer.valueOf(fieldVal1), Integer.valueOf(fieldVal2))
<= 0);
+            } else if(field.equals("longdv") || field.equals("field3_l_p")) {
+              assertTrue(Long.compare(Integer.valueOf(fieldVal1), Long.valueOf(fieldVal2))
<= 0);
+            }
           } else {
-            if (sort.equals("asc")) {
-              if (field.equals("stringdv") || field.equals("field1_s_dv")|| field.equals("datedv")
|| field.equals("booleandv")) { // use string comparator
-                assertTrue(fieldVal1.compareTo(fieldVal2) < 0);
-              } else if (field.equals("doubledv")){
-                assertTrue(Double.compare(Double.valueOf(fieldVal1), Double.valueOf(fieldVal2))
<= 0);
-              } else if(field.equals("floatdv")) {
-                assertTrue(Float.compare(Float.valueOf(fieldVal1), Float.valueOf(fieldVal2))
<= 0);
-              } else if(field.equals("intdv") || "field2_i_p".equals(field)) {
-                assertTrue(Integer.compare(Integer.valueOf(fieldVal1), Integer.valueOf(fieldVal2))
<= 0);
-              } else if(field.equals("longdv") || field.equals("field3_l_p")) {
-                assertTrue(Long.compare(Integer.valueOf(fieldVal1), Long.valueOf(fieldVal2))
<= 0);
-              }
-            } else {
-              if (field.equals("stringdv") || field.equals("field1_s_dv")|| field.equals("datedv")
|| field.equals("booleandv")) { // use string comparator
-                assertTrue(fieldVal1.compareTo(fieldVal2) > 0);
-              } else if (field.equals("doubledv")){
-                assertTrue(Double.compare(Double.valueOf(fieldVal1), Double.valueOf(fieldVal2))
>= 0);
-              } else if(field.equals("floatdv")) {
-                assertTrue(Float.compare(Float.valueOf(fieldVal1), Float.valueOf(fieldVal2))
>= 0);
-              } else if(field.equals("intdv") || "field2_i_p".equals(field)) {
-                assertTrue(Integer.compare(Integer.valueOf(fieldVal1), Integer.valueOf(fieldVal2))
>= 0);
-              } else if(field.equals("longdv") || field.equals("field3_l_p")) {
-                assertTrue(Long.compare(Integer.valueOf(fieldVal1), Long.valueOf(fieldVal2))
>= 0);
-              }
+            if (field.equals("stringdv") || field.equals("field1_s_dv")|| field.equals("datedv")
|| field.equals("booleandv")) { // use string comparator
+              assertTrue(fieldVal1.compareTo(fieldVal2) > 0);
+            } else if (field.equals("doubledv")){
+              assertTrue(Double.compare(Double.valueOf(fieldVal1), Double.valueOf(fieldVal2))
>= 0);
+            } else if(field.equals("floatdv")) {
+              assertTrue(Float.compare(Float.valueOf(fieldVal1), Float.valueOf(fieldVal2))
>= 0);
+            } else if(field.equals("intdv") || "field2_i_p".equals(field)) {
+              assertTrue(Integer.compare(Integer.valueOf(fieldVal1), Integer.valueOf(fieldVal2))
>= 0);
+            } else if(field.equals("longdv") || field.equals("field3_l_p")) {
+              assertTrue(Long.compare(Integer.valueOf(fieldVal1), Long.valueOf(fieldVal2))
>= 0);
             }
-            break;
           }
+          break;
         }
       }
-    } finally {
-      if (req != null) {
-        req.close();
-      }
     }
   }
 


Mime
View raw message