You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/03/11 20:03:46 UTC

svn commit: r1576473 [2/2] - in /lucene/dev/branches/lucene5487: ./ lucene/ lucene/analysis/ lucene/analysis/common/ lucene/analysis/common/src/java/org/apache/lucene/analysis/hunspell/ lucene/analysis/common/src/test/org/apache/lucene/analysis/hunspel...

Modified: lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java (original)
+++ lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java Tue Mar 11 19:03:45 2014
@@ -29,12 +29,14 @@ class AssertingWeight extends Weight {
     return other instanceof AssertingWeight ? other : new AssertingWeight(random, other);
   }
 
+  final boolean scoresDocsOutOfOrder;
   final Random random;
   final Weight in;
 
   AssertingWeight(Random random, Weight in) {
     this.random = random;
     this.in = in;
+    scoresDocsOutOfOrder = in.scoresDocsOutOfOrder() || random.nextBoolean();
   }
 
   @Override
@@ -73,8 +75,21 @@ class AssertingWeight extends Weight {
     if (inScorer == null) {
       return null;
     }
+
     if (AssertingBulkScorer.shouldWrap(inScorer)) {
+      // The incoming scorer already has a specialized
+      // implementation for BulkScorer, so we should use it:
       return AssertingBulkScorer.wrap(new Random(random.nextLong()), inScorer);
+    } else if (scoreDocsInOrder == false && random.nextBoolean()) {
+      // The caller claims it can handle out-of-order
+      // docs; let's confirm that by pulling docs and
+      // randomly shuffling them before collection:
+      //Scorer scorer = in.scorer(context, acceptDocs);
+      Scorer scorer = scorer(context, acceptDocs);
+
+      // Scorer should not be null if bulkScorer wasn't:
+      assert scorer != null;
+      return new AssertingBulkOutOfOrderScorer(new Random(random.nextLong()), scorer);
     } else {
       // Let super wrap this.scorer instead, so we use
       // AssertingScorer:
@@ -84,8 +99,7 @@ class AssertingWeight extends Weight {
 
   @Override
   public boolean scoresDocsOutOfOrder() {
-    return in.scoresDocsOutOfOrder();
+    return scoresDocsOutOfOrder;
   }
-
 }
 

Modified: lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java (original)
+++ lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/QueryUtils.java Tue Mar 11 19:03:45 2014
@@ -329,7 +329,7 @@ public class QueryUtils {
 
           @Override
           public boolean acceptsDocsOutOfOrder() {
-            return true;
+            return false;
           }
         });
 

Modified: lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java (original)
+++ lucene/dev/branches/lucene5487/lucene/test-framework/src/java/org/apache/lucene/search/ShardSearchingTestBase.java Tue Mar 11 19:03:45 2014
@@ -449,7 +449,9 @@ public abstract class ShardSearchingTest
       myNodeID = nodeID;
       dir = newFSDirectory(TestUtil.getTempDir("ShardSearchingTestBase"));
       // TODO: set warmer
-      IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random));
+      MockAnalyzer analyzer = new MockAnalyzer(random());
+      analyzer.setMaxTokenLength(TestUtil.nextInt(random(), 1, IndexWriter.MAX_TERM_LENGTH));
+      IndexWriterConfig iwc = new IndexWriterConfig(TEST_VERSION_CURRENT, analyzer);
       iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
       if (VERBOSE) {
         iwc.setInfoStream(new PrintStreamInfoStream(System.out));

Modified: lucene/dev/branches/lucene5487/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/CHANGES.txt?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene5487/solr/CHANGES.txt Tue Mar 11 19:03:45 2014
@@ -138,6 +138,12 @@ Bug Fixes
 * SOLR-5818: distrib search with custom comparator does not quite work correctly
   (Ryan Ernst)
 
+* SOLR-5834: Overseer threads are only being interrupted and not closed.
+  (hossman, Mark Miller)
+
+* SOLR-5839: ZookeeperInfoServlet does not trim path properly.
+  (Furkan KAMACI via Mark Miller)
+
 Optimizations
 ----------------------
 * SOLR-1880: Distributed Search skips GET_FIELDS stage if EXECUTE_QUERY
@@ -181,6 +187,13 @@ Other Changes
 * SOLR-5796: Make how long we are willing to wait for a core to see the ZK
   advertised leader in it's local state configurable. 
   (Timothy Potter via Mark Miller)
+  
+* 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/lucene5487/solr/core/src/java/org/apache/solr/cloud/Overseer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/cloud/Overseer.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/cloud/Overseer.java (original)
+++ lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/cloud/Overseer.java Tue Mar 11 19:03:45 2014
@@ -81,8 +81,8 @@ public class Overseer {
     //Internal queue where overseer stores events that have not yet been published into cloudstate
     //If Overseer dies while extracting the main queue a new overseer will start from this queue 
     private final DistributedQueue workQueue;
-    private volatile boolean isClosed;
     private Map clusterProps;
+    private boolean isClosed = false;
 
     public ClusterStateUpdater(final ZkStateReader reader, final String myId) {
       this.zkClient = reader.getZkClient();
@@ -1030,20 +1030,22 @@ public class Overseer {
 
   class OverseerThread extends Thread implements ClosableThread {
 
-    private volatile boolean isClosed;
+    protected volatile boolean isClosed;
+    private ClosableThread thread;
 
-    public OverseerThread(ThreadGroup tg,
-        ClusterStateUpdater clusterStateUpdater) {
-      super(tg, clusterStateUpdater);
+    public OverseerThread(ThreadGroup tg, ClosableThread thread) {
+      super(tg, (Runnable) thread);
+      this.thread = thread;
     }
 
-    public OverseerThread(ThreadGroup ccTg,
-        OverseerCollectionProcessor overseerCollectionProcessor, String string) {
-      super(ccTg, overseerCollectionProcessor, string);
+    public OverseerThread(ThreadGroup ccTg, ClosableThread thread, String name) {
+      super(ccTg, (Runnable) thread, name);
+      this.thread = thread;
     }
 
     @Override
     public void close() {
+      thread.close();
       this.isClosed = true;
     }
 
@@ -1084,8 +1086,7 @@ public class Overseer {
     ThreadGroup ccTg = new ThreadGroup("Overseer collection creation process.");
 
     ocp = new OverseerCollectionProcessor(reader, id, shardHandler, adminPath);
-    ccThread = new OverseerThread(ccTg, ocp,
-        "Overseer-" + id);
+    ccThread = new OverseerThread(ccTg, ocp, "Overseer-" + id);
     ccThread.setDaemon(true);
     
     updaterThread.start();

Modified: lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java (original)
+++ lucene/dev/branches/lucene5487/solr/core/src/java/org/apache/solr/servlet/ZookeeperInfoServlet.java Tue Mar 11 19:03:45 2014
@@ -195,7 +195,7 @@ public final class ZookeeperInfoServlet 
       if (path == null) {
         path = "/";
       } else {
-        path.trim();
+        path = path.trim();
         if (path.length() == 0) {
           path = "/";
         }

Modified: lucene/dev/branches/lucene5487/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java (original)
+++ lucene/dev/branches/lucene5487/solr/core/src/test/org/apache/solr/update/DocumentBuilderTest.java Tue Mar 11 19:03:45 2014
@@ -23,7 +23,9 @@ import org.apache.lucene.index.AtomicRea
 import org.apache.lucene.index.NumericDocValues;
 import org.apache.lucene.index.SlowCompositeReaderWrapper;
 import org.apache.lucene.search.similarities.DefaultSimilarity;
+import org.apache.lucene.util.TestUtil;
 import org.apache.solr.SolrTestCaseJ4;
+import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.params.CommonParams;
 import org.apache.solr.common.SolrException;
 import org.apache.solr.common.SolrInputDocument;
@@ -394,4 +396,106 @@ public class DocumentBuilderTest extends
     assertNull(h.validateUpdate(add(xml, new String[0])));
   }
 
+  public void testSolrDocumentEquals() {
+
+    String randomString = TestUtil.randomSimpleString(random());
+
+    SolrDocument doc1 = new SolrDocument();
+    doc1.addField("foo", randomString);
+
+    SolrDocument doc2 = new SolrDocument();
+    doc2.addField("foo", randomString);
+
+    assertTrue(doc1.equals(doc2));
+
+    doc1.addField("foo", "bar");
+
+    assertFalse(doc1.equals(doc2));
+
+    doc1 = new SolrDocument();
+    doc1.addField("bar", randomString);
+
+    assertFalse(doc1.equals(doc2));
+
+    int randomInt = random().nextInt();
+    doc1 = new SolrDocument();
+    doc1.addField("foo", randomInt);
+    doc2 = new SolrDocument();
+    doc2.addField("foo", randomInt);
+
+    assertTrue(doc1.equals(doc2));
+
+    doc2 = new SolrDocument();
+    doc2.addField("bar", randomInt);
+
+    assertFalse(doc1.equals(doc2));
+
+  }
+
+  public void testSolrInputDocumentEquality() {
+
+    String randomString = TestUtil.randomSimpleString(random());
+
+    SolrInputDocument doc1 = new SolrInputDocument();
+    doc1.addField("foo", randomString);
+    SolrInputDocument doc2 = new SolrInputDocument();
+    doc2.addField("foo", randomString);
+
+    assertTrue(doc1.equals(doc2));
+
+    doc1.setDocumentBoost(1.1f);
+    assertFalse(doc1.equals(doc2));
+
+    doc2.setDocumentBoost(1.1f);
+    assertTrue(doc1.equals(doc2));
+
+    doc2.setDocumentBoost(20f);
+    assertFalse(doc1.equals(doc2));
+
+
+    doc1 = new SolrInputDocument();
+    doc1.addField("foo", randomString);
+    doc2 = new SolrInputDocument();
+    doc2.addField("foo", randomString);
+
+    SolrInputDocument childDoc = new SolrInputDocument();
+    childDoc.addField("foo", "bar");
+
+    doc1.addChildDocument(childDoc);
+    assertFalse(doc1.equals(doc2));
+
+    doc2.addChildDocument(childDoc);
+    assertTrue(doc1.equals(doc2));
+
+    SolrInputDocument childDoc1 = new SolrInputDocument();
+    childDoc.addField(TestUtil.randomSimpleString(random()), TestUtil.randomSimpleString(random()));
+    doc2.addChildDocument(childDoc1);
+    assertFalse(doc1.equals(doc2));
+
+  }
+
+  public void testSolrInputFieldEquality() {
+    String randomString = TestUtil.randomSimpleString(random(), 10, 20);
+
+    int val = random().nextInt();
+    SolrInputField sif1 = new SolrInputField(randomString);
+    sif1.setValue(val, 1.0f);
+    SolrInputField sif2 = new SolrInputField(randomString);
+    sif2.setValue(val, 1.0f);
+
+    assertTrue(sif1.equals(sif2));
+
+    sif1.setBoost(2.1f);
+    sif2.setBoost(2.1f);
+    assertTrue(sif1.equals(sif2));
+
+    sif2.setBoost(2.0f);
+    assertFalse(sif1.equals(sif2));
+
+    sif2.setName("foo");
+    assertFalse(sif1.equals(sif2));
+
+
+  }
+
 }

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrServer.java Tue Mar 11 19:03:45 2014
@@ -199,8 +199,11 @@ public class HttpSolrServer extends Solr
     return request(request, responseParser);
   }
   
-  public NamedList<Object> request(final SolrRequest request,
-      final ResponseParser processor) throws SolrServerException, IOException {
+  public NamedList<Object> request(final SolrRequest request, final ResponseParser processor) throws SolrServerException, IOException {
+    return executeMethod(createMethod(request),processor);
+  }
+  
+  protected HttpRequestBase createMethod(final SolrRequest request) throws IOException, SolrServerException {
     HttpRequestBase method = null;
     InputStream is = null;
     SolrParams params = request.getParams();
@@ -382,6 +385,10 @@ public class HttpSolrServer extends Solr
       throw new SolrServerException("error reading streams", ex);
     }
     
+    return method;
+  }
+  
+  protected NamedList<Object> executeMethod(HttpRequestBase method, final ResponseParser processor) throws SolrServerException {
     // XXX client already has this set, is this needed?
     method.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,
         followRedirects);

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrDocument.java Tue Mar 11 19:03:45 2014
@@ -213,7 +213,41 @@ 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) {
+      return true;
+    }
+    if (!(o instanceof SolrDocument)) {
+      return false;
+    }
+
+    SolrDocument solrDocument = (SolrDocument) o;
+
+    if (!_fields.equals(solrDocument._fields)) {
+      return false;
+    }
+
+    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();
+  }
+
   //-----------------------------------------------------------------------------------------
   // JSTL Helpers
   //-----------------------------------------------------------------------------------------

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputDocument.java Tue Mar 11 19:03:45 2014
@@ -275,7 +275,51 @@ public class SolrInputDocument implement
   public Collection<SolrInputField> values() {
     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) {
+      return true;
+    }
+    if (!(o instanceof SolrInputDocument)) {
+      return false;
+    }
+
+    SolrInputDocument sdoc = (SolrInputDocument) o;
+
+    if (!_fields.equals(sdoc._fields)) {
+      return false;
+    }
+    if (Float.compare(sdoc._documentBoost, _documentBoost) != 0) {
+      return false;
+    }
+    if (_childDocuments != null ? !_childDocuments.equals(sdoc._childDocuments) : sdoc._childDocuments != null) {
+      return false;
+    }
+
+    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();
+    result = 31 * result + (_documentBoost != +0.0f ? Float.floatToIntBits(_documentBoost) : 0);
+    result = 31 * result + (_childDocuments != null ? _childDocuments.hashCode() : 0);
+    return result;
+  }
+
   public void addChildDocument(SolrInputDocument child) {
    if (_childDocuments == null) {
      _childDocuments = new ArrayList<SolrInputDocument>();

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/SolrInputField.java Tue Mar 11 19:03:45 2014
@@ -229,4 +229,50 @@ 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) {
+      return true;
+    }
+    if (!(o instanceof SolrInputField)) {
+      return false;
+    }
+
+    SolrInputField sif = (SolrInputField) o;
+
+    if (!name.equals(sif.name)) {
+      return false;
+    }
+
+    if (!value.equals(sif.value)) {
+      return false;
+    }
+
+    if (Float.compare(sif.boost, boost) != 0) {
+      return false;
+    }
+
+    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();
+    result = 31 * result + value.hashCode();
+    result = 31 * result + (boost != +0.0f ? Float.floatToIntBits(boost) : 0);
+    return result;
+  }
 }

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java Tue Mar 11 19:03:45 2014
@@ -521,7 +521,7 @@ public class JavaBinCodec {
       public Object getValue() {
         return value;
       }
-      
+
       @Override
       public String toString() {
         return "MapEntry[" + key.toString() + ":" + value.toString() + "]";
@@ -530,7 +530,28 @@ public class JavaBinCodec {
       @Override
       public Object setValue(Object value) {
         throw new UnsupportedOperationException();
-      }};
+      }
+
+      @Override
+      public int hashCode() {
+        int result = 31;
+        result *=31 + getKey().hashCode();
+        result *=31 + getValue().hashCode();
+        return result;
+      }
+
+      @Override
+      public boolean equals(Object obj) {
+        if(this == obj) {
+          return true;
+        }
+        if(!(obj instanceof Entry)) {
+          return false;
+        }
+        Map.Entry<Object, Object> entry = (Entry<Object, Object>) obj;
+        return (this.getKey().equals(entry.getKey()) && this.getValue().equals(entry.getValue()));
+      }
+    };
   }
 
   /**

Modified: lucene/dev/branches/lucene5487/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5487/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java?rev=1576473&r1=1576472&r2=1576473&view=diff
==============================================================================
--- lucene/dev/branches/lucene5487/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java (original)
+++ lucene/dev/branches/lucene5487/solr/solrj/src/test/org/apache/solr/common/util/TestJavaBinCodec.java Tue Mar 11 19:03:45 2014
@@ -17,17 +17,37 @@ package org.apache.solr.common.util;
  * limitations under the License.
  */
 
+import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.HashMap;
+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 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);
@@ -36,4 +56,158 @@ public class TestJavaBinCodec extends Lu
       assertEquals(s, o);
     }
   }
+
+  private List<Object> generateAllDataTypes() {
+    List<Object> types = new ArrayList<>();
+
+    types.add(null); //NULL
+    types.add(true);
+    types.add(false);
+    types.add((byte) 1);
+    types.add((short) 2);
+    types.add((double) 3);
+
+    types.add(-4);
+    types.add(4);
+    types.add(42);
+
+    types.add((long) -5);
+    types.add((long) 5);
+    types.add((long) 50);
+
+    types.add((float) 6);
+    types.add(new Date(0));
+
+    Map<Integer, Integer> map = new HashMap<>();
+    map.put(1, 2);
+    types.add(map);
+
+    SolrDocument doc = new SolrDocument();
+    doc.addField("foo", "bar");
+    types.add(doc);
+
+    SolrDocumentList solrDocs = new SolrDocumentList();
+    solrDocs.setMaxScore(1.0f);
+    solrDocs.setNumFound(1);
+    solrDocs.setStart(0);
+    solrDocs.add(0, doc);
+    types.add(solrDocs);
+
+    types.add(new byte[] {1,2,3,4,5});
+
+    // TODO?
+    // List<String> list = new ArrayList<String>();
+    // list.add("one");
+    // types.add(list.iterator());
+
+    types.add((byte) 15); //END
+
+    SolrInputDocument idoc = new SolrInputDocument();
+    idoc.addField("foo", "bar");
+    types.add(idoc);
+
+    SolrInputDocument parentDoc = new SolrInputDocument();
+    parentDoc.addField("foo", "bar");
+    SolrInputDocument childDoc = new SolrInputDocument();
+    childDoc.addField("foo", "bar");
+    parentDoc.addChildDocument(childDoc);
+    types.add(parentDoc);
+
+    types.add(new EnumFieldValue(1, "foo"));
+
+    types.add(map.entrySet().iterator().next()); //Map.Entry
+
+    types.add((byte) (1 << 5)); //TAG_AND_LEN
+
+    types.add("foo");
+    types.add(1);
+    types.add((long) 2);
+
+    SimpleOrderedMap simpleOrderedMap = new SimpleOrderedMap();
+    simpleOrderedMap.add("bar", "barbar");
+    types.add(simpleOrderedMap);
+
+    NamedList<String> nl = new NamedList<>();
+    nl.add("foo", "barbar");
+    types.add(nl);
+
+    return types;
+  }
+
+  @Test
+  public void testBackCompat() {
+    List iteratorAsList = null;
+    JavaBinCodec javabin = new JavaBinCodec(){
+      @Override
+      public List<Object> readIterator(DataInputInputStream fis) throws IOException {
+        return super.readIterator(fis);
+      }
+    };
+    try {
+      InputStream is = getClass().getResourceAsStream(SOLRJ_JAVABIN_BACKCOMPAT_BIN);
+      List<Object> unmarshaledObj = (List<Object>) javabin.unmarshal(is);
+      List<Object> matchObj = generateAllDataTypes();
+
+      assertEquals(unmarshaledObj.size(), matchObj.size());
+      for(int i=0; i < unmarshaledObj.size(); i++) {
+
+        if(unmarshaledObj.get(i) instanceof byte[] && matchObj.get(i) instanceof byte[]) {
+          byte[] b1 = (byte[]) unmarshaledObj.get(i);
+          byte[] b2 = (byte[]) matchObj.get(i);
+          assertTrue(Arrays.equals(b1, b2));
+
+        } else {
+          assertEquals(unmarshaledObj.get(i), matchObj.get(i));
+        }
+
+      }
+    } catch (IOException e) {
+      fail(e.getMessage());
+    }
+
+  }
+
+  @Test
+  public void testForwardCompat() {
+    JavaBinCodec javabin = new JavaBinCodec();
+    ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+    Object data = generateAllDataTypes();
+    try {
+      javabin.marshal(data, os);
+      byte[] newFormatBytes = os.toByteArray();
+
+      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
+        assertEquals(currentFormatBytes[i], newFormatBytes[i]);
+      }
+
+    } catch (IOException e) {
+      e.printStackTrace();
+      fail(e.getMessage());
+    }
+
+  }
+
+  public void genBinaryFile() throws IOException {
+    JavaBinCodec javabin = new JavaBinCodec();
+    ByteArrayOutputStream os = new ByteArrayOutputStream();
+    
+    Object data = generateAllDataTypes();
+    
+    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) throws IOException {
+    TestJavaBinCodec test = new TestJavaBinCodec();
+    test.genBinaryFile();
+  }
+
 }