SOLR-9990: Avoid copyField in SolrExampleTests.testUpdateField

This commit is contained in:
Tomas Fernandez Lobbe 2017-03-16 15:10:48 -07:00 committed by Shalin Shekhar Mangar
parent 28ca4a6e1e
commit 1f585da2c1
1 changed files with 8 additions and 8 deletions

View File

@ -1613,16 +1613,16 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("name", "gadget");
doc.addField("price_f", 1);
doc.addField("price", 1);
client.add(doc);
client.commit();
SolrQuery q = new SolrQuery("*:*");
q.setFields("id","price_f","name", "_version_");
q.setFields("id","price","name", "_version_");
QueryResponse resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
Long version = (Long)resp.getResults().get(0).getFirstValue("_version_");
assertNotNull("no version returned", version);
assertEquals(1.0f, resp.getResults().get(0).getFirstValue("price_f"));
assertEquals(1.0f, resp.getResults().get(0).getFirstValue("price"));
//update "price" with incorrect version (optimistic locking)
HashMap<String, Object> oper = new HashMap<>(); //need better api for this???
@ -1631,7 +1631,7 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version+1);
doc.addField("price_f", oper);
doc.addField("price", oper);
try {
client.add(doc);
if(client instanceof HttpSolrClient) { //XXX concurrent client reports exceptions differently
@ -1650,24 +1650,24 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("_version_", version);
doc.addField("price_f", oper);
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 100.0f, resp.getResults().get(0).getFirstValue("price_f"));
assertEquals("price was not updated?", 100.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
//update "price", no version
oper.put("set", 200);
doc = new SolrInputDocument();
doc.addField("id", "unique");
doc.addField("price_f", oper);
doc.addField("price", oper);
client.add(doc);
client.commit();
resp = client.query(q);
assertEquals("Doc count does not match", 1, resp.getResults().getNumFound());
assertEquals("price was not updated?", 200.0f, resp.getResults().get(0).getFirstValue("price_f"));
assertEquals("price was not updated?", 200.0f, resp.getResults().get(0).getFirstValue("price"));
assertEquals("no name?", "gadget", resp.getResults().get(0).getFirstValue("name"));
}