Skip to content

Apache Lucene open-source search software

SOLR-5837: Clean up issue: Add hashCode/equals to SolrDocument, SolrInputDocument and SolrInputField for testing purposes.

Mark Robert Miller54e100304716
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 32702dea847..773540fed95 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -190,6 +190,10 @@ Other Changes
* SOLR-5825: Separate http request creating and execution in SolrJ
(Steven Bower via Erick Erickson)
+
+* SOLR-5837: Add hashCode/equals to SolrDocument, SolrInputDocument
+ and SolrInputField for testing purposes. (Varun Thacker, Noble Paul,
+ Mark Miller)
================== 4.7.0 ==================
diff --git a/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java b/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
index f5e183fff72..50a302c7059 100644
--- a/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
+++ b/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
@@ -213,7 +213,12 @@ public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<Stri
public Iterator<Entry<String, Object>> iterator() {
return _fields.entrySet().iterator();
}
-
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -232,6 +237,12 @@ public class SolrDocument implements Map<String,Object>, Iterable<Map.Entry<Stri
return true;
}
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public int hashCode() {
return _fields.hashCode();
diff --git a/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java b/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
index 16e4270e812..99ec58e99ef 100644
--- a/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
+++ b/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
@@ -276,6 +276,12 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
return _fields.values();
}
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -300,6 +306,12 @@ public class SolrInputDocument implements Map<String,SolrInputField>, Iterable<S
return true;
}
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public int hashCode() {
int result = _fields.hashCode();
diff --git a/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java b/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
index 9e40183b4f1..f5cb5d1aff0 100644
--- a/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
+++ b/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
@@ -230,6 +230,12 @@ public class SolrInputField implements Iterable<Object>, Serializable
return clone;
}
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -256,6 +262,12 @@ public class SolrInputField implements Iterable<Object>, Serializable
return true;
}
+ /**
+ * This method is implemented for tests and should not be counted
+ * on in production code.
+ *
+ * @lucene.experimental
+ */
@Override
public int hashCode() {
int result = name.hashCode();
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index c17e4bceb8c..41e7f54d0c8 100644
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -510,7 +510,6 @@ public class JavaBinCodec {
public Map.Entry<Object,Object> readMapEntry(DataInputInputStream dis) throws IOException {
final Object key = readVal(dis);
final Object value = readVal(dis);
- //return new AbstractMap.SimpleImmutableEntry(key, value);
return new Map.Entry<Object,Object>() {
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java b/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
index d0a39e51eaa..3145d5181e5 100644
--- a/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
+++ b/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
@@ -17,15 +17,6 @@ package org.apache.solr.common.util;
* limitations under the License.
*/
-import org.apache.commons.io.IOUtils;
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
-import org.apache.solr.common.EnumFieldValue;
-import org.apache.solr.common.SolrDocument;
-import org.apache.solr.common.SolrDocumentList;
-import org.apache.solr.common.SolrInputDocument;
-import org.junit.Test;
-
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -37,17 +28,26 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.commons.io.IOUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+import org.apache.solr.common.EnumFieldValue;
+import org.apache.solr.common.SolrDocument;
+import org.apache.solr.common.SolrDocumentList;
+import org.apache.solr.common.SolrInputDocument;
+import org.junit.Test;
+
public class TestJavaBinCodec extends LuceneTestCase {
- private final String BIN_FILE_LOCATION = "./solr/solrj/src/test-files/solrj/javabin_backcompat.bin";
+ private static final String SOLRJ_JAVABIN_BACKCOMPAT_BIN = "/solrj/javabin_backcompat.bin";
+private final String BIN_FILE_LOCATION = "./solr/solrj/src/test-files/solrj/javabin_backcompat.bin";
public void testStrings() throws Exception {
JavaBinCodec javabin = new JavaBinCodec();
- for (int i = 0; i < 10000*RANDOM_MULTIPLIER; i++) {
+ for (int i = 0; i < 10000 * RANDOM_MULTIPLIER; i++) {
String s = TestUtil.randomUnicodeString(random());
ByteArrayOutputStream os = new ByteArrayOutputStream();
javabin.marshal(s, os);
@@ -95,9 +95,10 @@ public class TestJavaBinCodec extends LuceneTestCase {
types.add(new byte[] {1,2,3,4,5});
- List<String> list = new ArrayList<String>();
- list.add("one");
- //types.add(list.iterator());
+ // TODO?
+ // List<String> list = new ArrayList<String>();
+ // list.add("one");
+ // types.add(list.iterator());
types.add((byte) 15); //END
@@ -143,7 +144,7 @@ public class TestJavaBinCodec extends LuceneTestCase {
}
};
try {
- InputStream is = getClass().getResourceAsStream("/solrj/javabin_backcompat.bin");
+ InputStream is = getClass().getResourceAsStream(SOLRJ_JAVABIN_BACKCOMPAT_BIN);
List<Object> unmarshaledObj = (List<Object>) javabin.unmarshal(is);
List<Object> matchObj = generateAllDataTypes();
@@ -176,7 +177,7 @@ public class TestJavaBinCodec extends LuceneTestCase {
javabin.marshal(data, os);
byte[] newFormatBytes = os.toByteArray();
- InputStream is = getClass().getResourceAsStream("/solrj/javabin_backcompat.bin");
+ InputStream is = getClass().getResourceAsStream(SOLRJ_JAVABIN_BACKCOMPAT_BIN);
byte[] currentFormatBytes = IOUtils.toByteArray(is);
for (int i = 1; i < currentFormatBytes.length; i++) {//ignore the first byte. It is version information
@@ -184,30 +185,27 @@ public class TestJavaBinCodec extends LuceneTestCase {
}
} catch (IOException e) {
+ e.printStackTrace();
fail(e.getMessage());
}
}
- public void genBinaryFile() {
+ public void genBinaryFile() throws IOException {
JavaBinCodec javabin = new JavaBinCodec();
ByteArrayOutputStream os = new ByteArrayOutputStream();
-
+
Object data = generateAllDataTypes();
- try {
- javabin.marshal(data, os);
- byte[] out = os.toByteArray();
- FileOutputStream fs = new FileOutputStream(new File( BIN_FILE_LOCATION ));
- BufferedOutputStream bos = new BufferedOutputStream(fs);
- bos.write(out);
- bos.close();
- } catch (IOException e) {
- //TODO fail test?
- }
-
+
+ javabin.marshal(data, os);
+ byte[] out = os.toByteArray();
+ FileOutputStream fs = new FileOutputStream(new File(BIN_FILE_LOCATION));
+ BufferedOutputStream bos = new BufferedOutputStream(fs);
+ bos.write(out);
+ bos.close();
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws IOException {
TestJavaBinCodec test = new TestJavaBinCodec();
test.genBinaryFile();
}