SOLR-9059: NPE in SolrClientCache following collection reload

This commit is contained in:
jbernste 2016-05-03 13:03:57 -04:00
parent 184da9982c
commit fc6c24a9d4
2 changed files with 33 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import org.apache.solr.client.solrj.io.stream.SolrStream;
import org.apache.solr.client.solrj.io.stream.TupleStream;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.common.cloud.DocCollection;
import org.apache.solr.common.cloud.Replica;
import org.apache.solr.common.params.CommonParams;
import org.junit.After;
import org.junit.AfterClass;
@ -425,6 +426,36 @@ public class TestSQLHandler extends AbstractFullDistribZkTestBase {
assert(tuple.getLong("myInt") == 7);
assert(tuple.get("myString").equals("a"));
//Test after reload SOLR-9059//
Replica leader = getShardLeader("collection1", "shard1", 30 /* timeout secs */);
// reload collection and wait to see the core report it has been reloaded
boolean wasReloaded = reloadCollection(leader, "collection1");
assertTrue(wasReloaded);
params = new HashMap();
params.put(CommonParams.QT, "/sql");
params.put("stmt", "select id as myId, field_i as myInt, str_s as myString from collection1 where text='XXXX' AND id='(1 2 3)' order by field_i desc");
solrStream = new SolrStream(jetty.url, params);
tuples = getTuples(solrStream);
assert(tuples.size() == 3);
tuple = tuples.get(0);
assert(tuple.getLong("myId") == 3);
assert(tuple.getLong("myInt") == 20);
assert(tuple.get("myString").equals("a"));
tuple = tuples.get(1);
assert(tuple.getLong("myId") == 2);
assert(tuple.getLong("myInt") == 8);
assert(tuple.get("myString").equals("b"));
tuple = tuples.get(2);
assert(tuple.getLong("myId") == 1);
assert(tuple.getLong("myInt") == 7);
assert(tuple.get("myString").equals("a"));
} finally {
delete();

View File

@ -66,7 +66,7 @@ public class SolrClientCache implements Serializable {
return client;
}
public void close() {
public synchronized void close() {
for(Map.Entry<String, SolrClient> entry : solrClients.entrySet()) {
try {
entry.getValue().close();
@ -74,5 +74,6 @@ public class SolrClientCache implements Serializable {
log.error("Error closing SolrClient for " + entry.getKey(), e);
}
}
solrClients.clear();
}
}