mirror of https://github.com/apache/lucene.git
SOLR-696: fixed Iterable marshalling problem
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@685640 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a59dd7660
commit
4ede48a297
|
@ -524,6 +524,8 @@ Bug Fixes
|
|||
|
||||
45. SOLR-676: DataImportHandler should use UpdateRequestProcessor API instead of directly using UpdateHandler. (shalin)
|
||||
|
||||
46. SOLR-696: Fixed bug in NamedListCodec in regards to serializing Iterable objects. (gsingers)
|
||||
|
||||
Other Changes
|
||||
1. SOLR-135: Moved common classes to org.apache.solr.common and altered the
|
||||
build scripts to make two jars: apache-solr-1.3.jar and
|
||||
|
|
|
@ -222,6 +222,7 @@ public class NamedListCodec {
|
|||
}
|
||||
if (val instanceof Iterable) {
|
||||
writeIterator(((Iterable)val).iterator());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -22,9 +22,12 @@ import org.apache.solr.TestDistributedSearch;
|
|||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -122,9 +125,45 @@ public class TestNamedListCodec extends TestCase {
|
|||
assertEquals(list.size(), l.size());
|
||||
}
|
||||
|
||||
public void testIterable() throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
NamedList r = new NamedList();
|
||||
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("foo", "bar");
|
||||
map.put("junk", "funk");
|
||||
map.put("ham", "burger");
|
||||
|
||||
r.add("keys", map.keySet());
|
||||
r.add("more", "less");
|
||||
r.add("values", map.values());
|
||||
r.add("finally", "the end");
|
||||
new NamedListCodec(null).marshal(r,baos);
|
||||
byte[] arr = baos.toByteArray();
|
||||
|
||||
try {
|
||||
NamedList result = new NamedListCodec().unmarshal(new ByteArrayInputStream(arr));
|
||||
assertTrue("result is null and it shouldn't be", result != null);
|
||||
List keys = (List) result.get("keys");
|
||||
assertTrue("keys is null and it shouldn't be", keys != null);
|
||||
assertTrue("keys Size: " + keys.size() + " is not: " + 3, keys.size() == 3);
|
||||
String less = (String) result.get("more");
|
||||
assertTrue("less is null and it shouldn't be", less != null);
|
||||
assertTrue(less + " is not equal to " + "less", less.equals("less") == true);
|
||||
List values = (List) result.get("values");
|
||||
assertTrue("values is null and it shouldn't be", values != null);
|
||||
assertTrue("values Size: " + values.size() + " is not: " + 3, values.size() == 3);
|
||||
String theEnd = (String) result.get("finally");
|
||||
assertTrue("theEnd is null and it shouldn't be", theEnd != null);
|
||||
assertTrue(theEnd + " is not equal to " + "the end", theEnd.equals("the end") == true);
|
||||
} catch (ClassCastException e) {
|
||||
assertTrue("Received a CCE and we shouldn't have", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int rSz(int orderOfMagnitude) {
|
||||
int sz = r.nextInt(orderOfMagnitude);
|
||||
switch (sz) {
|
||||
|
|
Loading…
Reference in New Issue