use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBlobHandler method postData.
public static void postData(CloudSolrClient cloudClient, String baseUrl, String blobName, ByteBuffer bytarr) throws IOException {
HttpPost httpPost = null;
HttpEntity entity;
String response = null;
try {
httpPost = new HttpPost(baseUrl + "/.system/blob/" + blobName);
httpPost.setHeader("Content-Type", "application/octet-stream");
httpPost.setEntity(new ByteArrayEntity(bytarr.array(), bytarr.arrayOffset(), bytarr.limit()));
entity = cloudClient.getLbClient().getHttpClient().execute(httpPost).getEntity();
try {
response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
Map m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertFalse("Error in posting blob " + getAsString(m), m.containsKey("error"));
} catch (JSONParser.ParseException e) {
log.error("$ERROR$", response, e);
fail();
}
} finally {
httpPost.releaseConnection();
}
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestUseDocValuesAsStored2 method testSchemaAPI.
public void testSchemaAPI() throws Exception {
RestTestHarness harness = restTestHarness;
String payload = "{\n" + " 'add-field' : {\n" + " 'name':'a1',\n" + " 'type': 'string',\n" + " 'stored':false,\n" + " 'docValues':true,\n" + " 'indexed':false\n" + " },\n" + " 'add-field' : {\n" + " 'name':'a2',\n" + " 'type': 'string',\n" + " 'stored':false,\n" + " 'useDocValuesAsStored':true,\n" + " 'docValues':true,\n" + " 'indexed':true\n" + " },\n" + " 'add-field' : {\n" + " 'name':'a3',\n" + " 'type': 'string',\n" + " 'stored':false,\n" + " 'useDocValuesAsStored':false,\n" + " 'docValues':true,\n" + " 'indexed':true\n" + " }\n" + " }\n";
String response = harness.post("/schema?wt=json", json(payload));
Map m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNull(response, m.get("errors"));
// default value of useDocValuesAsStored
m = TestBulkSchemaAPI.getObj(harness, "a1", "fields");
assertNotNull("field a1 not created", m);
assertNull(m.get("useDocValuesAsStored"));
// useDocValuesAsStored=true
m = TestBulkSchemaAPI.getObj(harness, "a2", "fields");
assertNotNull("field a2 not created", m);
assertEquals(Boolean.TRUE, m.get("useDocValuesAsStored"));
// useDocValuesAsStored=false
m = TestBulkSchemaAPI.getObj(harness, "a3", "fields");
assertNotNull("field a3 not created", m);
assertEquals(Boolean.FALSE, m.get("useDocValuesAsStored"));
// Index documents to check the effect
assertU(adoc("id", "myid1", "a1", "1", "a2", "2", "a3", "3"));
assertU(commit());
RestTestBase.assertJQ("/select?q=id:myid*&fl=*", "/response/docs==[{'id':'myid1', 'a1':'1', 'a2':'2'}]");
RestTestBase.assertJQ("/select?q=id:myid*&fl=id,a1,a2,a3", "/response/docs==[{'id':'myid1', 'a1':'1', 'a2':'2', 'a3':'3'}]");
RestTestBase.assertJQ("/select?q=id:myid*&fl=a3", "/response/docs==[{'a3':'3'}]");
// this will return a3 because it is explicitly requested even if '*' is specified
RestTestBase.assertJQ("/select?q=id:myid*&fl=*,a3", "/response/docs==[{'id':'myid1', 'a1':'1', 'a2':'2', 'a3':'3'}]");
// this will not return a3 because the glob 'a*' will match only stored + useDocValuesAsStored=true fields
RestTestBase.assertJQ("/select?q=id:myid*&fl=id,a*", "/response/docs==[{'id':'myid1', 'a1':'1', 'a2':'2'}]");
// Test replace-field
// Explicitly set useDocValuesAsStored to false
payload = "{\n" + " 'replace-field' : {\n" + " 'name':'a1',\n" + " 'type': 'string',\n" + " 'stored':false,\n" + " 'useDocValuesAsStored':false,\n" + " 'docValues':true,\n" + " 'indexed':false\n" + " }}";
response = harness.post("/schema?wt=json", json(payload));
m = TestBulkSchemaAPI.getObj(harness, "a1", "fields");
assertNotNull("field a1 doesn't exist any more", m);
assertEquals(Boolean.FALSE, m.get("useDocValuesAsStored"));
// Explicitly set useDocValuesAsStored to true
payload = "{\n" + " 'replace-field' : {\n" + " 'name':'a1',\n" + " 'type': 'string',\n" + " 'stored':false,\n" + " 'useDocValuesAsStored':true,\n" + " 'docValues':true,\n" + " 'indexed':false\n" + " }}";
response = harness.post("/schema?wt=json", json(payload));
m = TestBulkSchemaAPI.getObj(harness, "a1", "fields");
assertNotNull("field a1 doesn't exist any more", m);
assertEquals(Boolean.TRUE, m.get("useDocValuesAsStored"));
// add a field which is stored as well as docvalues
payload = "{ 'add-field' : {\n" + " 'name':'a4',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'useDocValuesAsStored':true,\n" + " 'docValues':true,\n" + " 'indexed':true\n" + " }}";
response = harness.post("/schema?wt=json", json(payload));
m = TestBulkSchemaAPI.getObj(harness, "a4", "fields");
assertNotNull("field a4 not found", m);
assertEquals(Boolean.TRUE, m.get("useDocValuesAsStored"));
assertU(adoc("id", "myid1", "a1", "1", "a2", "2", "a3", "3", "a4", "4"));
assertU(commit());
RestTestBase.assertJQ("/select?q=id:myid*&fl=*", "/response/docs==[{'id':'myid1', 'a1':'1', 'a2':'2', 'a4':'4'}]");
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestConfigSetsAPI method postDataAndGetResponse.
public static Map postDataAndGetResponse(CloudSolrClient cloudClient, String uri, ByteBuffer bytarr, String username, String password) throws IOException {
HttpPost httpPost = null;
HttpEntity entity;
String response = null;
Map m = null;
try {
httpPost = new HttpPost(uri);
if (username != null) {
String userPass = username + ":" + password;
String encoded = Base64.byteArrayToBase64(userPass.getBytes(UTF_8));
BasicHeader header = new BasicHeader("Authorization", "Basic " + encoded);
httpPost.setHeader(header);
}
httpPost.setHeader("Content-Type", "application/octet-stream");
httpPost.setEntity(new ByteArrayEntity(bytarr.array(), bytarr.arrayOffset(), bytarr.limit()));
entity = cloudClient.getLbClient().getHttpClient().execute(httpPost).getEntity();
try {
response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
m = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
} catch (JSONParser.ParseException e) {
fail(e.getMessage());
}
} finally {
httpPost.releaseConnection();
}
return m;
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestConfigSetImmutable method testSolrConfigHandlerImmutable.
@Test
public void testSolrConfigHandlerImmutable() throws Exception {
String payload = "{\n" + "'create-requesthandler' : { 'name' : '/x', 'class': 'org.apache.solr.handler.DumpRequestHandler' , 'startup' : 'lazy'}\n" + "}";
String uri = "/config?wt=json";
String response = restTestHarness.post(uri, SolrTestCaseJ4.json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNotNull(map.get("error"));
assertTrue(map.get("error").toString().contains("immutable"));
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestSolrConfigHandlerConcurrent method getAsMap.
public static Map getAsMap(String uri, CloudSolrClient cloudClient) throws Exception {
HttpGet get = new HttpGet(uri);
HttpEntity entity = null;
try {
entity = cloudClient.getLbClient().getHttpClient().execute(get).getEntity();
String response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
try {
return (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
} catch (JSONParser.ParseException e) {
log.error(response, e);
throw e;
}
} finally {
EntityUtils.consumeQuietly(entity);
get.releaseConnection();
}
}
Aggregations