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, Iterable> 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, Iterable, Iterable, Iterable, 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, 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 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() { @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 list = new ArrayList(); - list.add("one"); - //types.add(list.iterator()); + // TODO? + // List list = new ArrayList(); + // 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 unmarshaledObj = (List) javabin.unmarshal(is); List 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(); }