You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2014/03/10 18:14:16 UTC
svn commit: r1576005 - in /lucene/dev/branches/branch_4x: ./ solr/
solr/solrj/ solr/solrj/src/java/org/apache/solr/common/
solr/solrj/src/java/org/apache/solr/common/util/
solr/solrj/src/test/org/apache/solr/common/util/
Author: markrmiller
Date: Mon Mar 10 17:14:15 2014
New Revision: 1576005
URL: http://svn.apache.org/r1576005
Log:
SOLR-5837: Clean up issue: Add hashCode/equals to SolrDocument, SolrInputDocument and SolrInputField for testing purposes.
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/solr/ (props changed)
lucene/dev/branches/branch_4x/solr/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/solr/solrj/ (props changed)
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
Modified: lucene/dev/branches/branch_4x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/CHANGES.txt?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/solr/CHANGES.txt Mon Mar 10 17:14:15 2014
@@ -144,6 +144,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 ==================
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java Mon Mar 10 17:14:15 2014
@@ -213,7 +213,12 @@ public class SolrDocument implements Map
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
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();
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Mon Mar 10 17:14:15 2014
@@ -276,6 +276,12 @@ public class SolrInputDocument implement
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 implement
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();
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java Mon Mar 10 17:14:15 2014
@@ -230,6 +230,12 @@ public class SolrInputField implements I
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 I
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();
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java Mon Mar 10 17:14:15 2014
@@ -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
Modified: lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java?rev=1576005&r1=1576004&r2=1576005&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java (original)
+++ lucene/dev/branches/branch_4x/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java Mon Mar 10 17:14:15 2014
@@ -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 Lu
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 Lu
}
};
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 Lu
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 Lu
}
} 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();
}