use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.
the class TestCloudManagedSchemaConcurrent method validateZkVersion.
/**
* Sends a GET request to get the zk schema version from a specific replica.
*/
protected void validateZkVersion(Replica replica, int schemaZkVersion, int waitSecs, boolean retry) throws Exception {
final String replicaUrl = (new ZkCoreNodeProps(replica)).getCoreUrl();
RestTestHarness testHarness = new RestTestHarness(() -> replicaUrl.endsWith("/") ? replicaUrl.substring(0, replicaUrl.length() - 1) : replicaUrl);
try {
long waitMs = waitSecs * 1000L;
// wait a moment for the zk watcher to fire
if (waitMs > 0)
Thread.sleep(waitMs);
try {
testHarness.validateQuery("/schema/zkversion?wt=xml", "//zkversion=" + schemaZkVersion);
} catch (Exception exc) {
if (retry) {
// brief wait before retrying
Thread.sleep(waitMs > 0 ? waitMs : 2000L);
testHarness.validateQuery("/schema/zkversion?wt=xml", "//zkversion=" + schemaZkVersion);
} else {
throw exc;
}
}
} finally {
testHarness.close();
}
}
use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.
the class TestCloudManagedSchemaConcurrent method concurrentOperationsTest.
private void concurrentOperationsTest() throws Exception {
// First, add a bunch of fields and dynamic fields via PUT and POST, as well as copyFields,
// but do it fast enough and verify shards' schemas after all of them are added
int numFields = 100;
Info info = new Info("");
for (int fieldNum = 0; fieldNum <= numFields; ++fieldNum) {
RestTestHarness publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
Operation.randomOperation().execute(publisher, fieldNum, info);
}
String[] expectedAddFields = getExpectedFieldResponses(info);
String[] expectedAddDynamicFields = getExpectedDynamicFieldResponses(info);
String[] expectedCopyFields = getExpectedCopyFieldResponses(info);
String[] expectedAddFieldTypes = getExpectedFieldTypeResponses(info);
boolean success = false;
long maxTimeoutMillis = 100000;
long startTime = System.nanoTime();
String request = null;
String response = null;
String result = null;
while (!success && TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutMillis) {
Thread.sleep(100);
for (RestTestHarness client : restTestHarnesses) {
// verify addFieldTypePuts and addFieldTypePosts
request = "/schema/fieldtypes?wt=xml";
response = client.query(request);
result = BaseTestHarness.validateXPath(response, expectedAddFieldTypes);
if (result != null) {
break;
}
// verify addFieldPuts and addFieldPosts
request = "/schema/fields?wt=xml";
response = client.query(request);
result = BaseTestHarness.validateXPath(response, expectedAddFields);
if (result != null) {
break;
}
// verify addDynamicFieldPuts and addDynamicFieldPosts
request = "/schema/dynamicfields?wt=xml";
response = client.query(request);
result = BaseTestHarness.validateXPath(response, expectedAddDynamicFields);
if (result != null) {
break;
}
// verify copyFields
request = "/schema/copyfields?wt=xml";
response = client.query(request);
result = BaseTestHarness.validateXPath(response, expectedCopyFields);
if (result != null) {
break;
}
}
success = (result == null);
}
if (!success) {
String msg = "QUERY FAILED: xpath=" + result + " request=" + request + " response=" + response;
log.error(msg);
fail(msg);
}
}
use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.
the class TestBulkSchemaConcurrent method setupHarnesses.
private void setupHarnesses() {
for (final SolrClient client : clients) {
RestTestHarness harness = new RestTestHarness(() -> ((HttpSolrClient) client).getBaseURL());
restTestHarnesses.add(harness);
}
}
use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.
the class TestBulkSchemaConcurrent method invokeBulkReplaceCall.
private void invokeBulkReplaceCall(int seed, ArrayList<String> errs) throws Exception {
String payload = "{\n" + " 'replace-field' : {\n" + " 'name':'replaceFieldA',\n" + " 'type': 'text',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " },\n" + " 'replace-dynamic-field' : {\n" + " 'name' :'replaceDynamicField',\n" + " 'type':'text',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " },\n" + " 'replace-field-type' : {\n" + " 'name' :'myNewFieldTypeName',\n" + " 'class' : 'solr.TextField'\n" + " }\n" + " }";
String aField = "a" + seed;
String dynamicFldName = "*_lol" + seed;
String dynamicCopyFldDest = "hello_lol" + seed;
String newFieldTypeName = "mystr" + seed;
payload = payload.replace("replaceFieldA", aField);
payload = payload.replace("replaceDynamicField", dynamicFldName);
payload = payload.replace("myNewFieldTypeName", newFieldTypeName);
RestTestHarness publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
String response = publisher.post("/schema?wt=json", SolrTestCaseJ4.json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
Object errors = map.get("errors");
if (errors != null) {
errs.add(new String(Utils.toJSON(errors), StandardCharsets.UTF_8));
return;
}
//get another node
Set<String> errmessages = new HashSet<>();
RestTestHarness harness = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
try {
long startTime = System.nanoTime();
long maxTimeoutMillis = 100000;
while (TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutMillis) {
errmessages.clear();
Map m = getObj(harness, aField, "fields");
if (m == null)
errmessages.add(StrUtils.formatString("field {0} no longer present", aField));
m = getObj(harness, dynamicFldName, "dynamicFields");
if (m == null)
errmessages.add(StrUtils.formatString("dynamic field {0} no longer present", dynamicFldName));
List l = getSourceCopyFields(harness, aField);
if (!checkCopyField(l, aField, dynamicCopyFldDest))
errmessages.add(StrUtils.formatString("CopyField source={0},dest={1} no longer present", aField, dynamicCopyFldDest));
m = getObj(harness, newFieldTypeName, "fieldTypes");
if (m == null)
errmessages.add(StrUtils.formatString("new type {0} no longer present", newFieldTypeName));
if (errmessages.isEmpty())
break;
Thread.sleep(10);
}
} finally {
harness.close();
}
if (!errmessages.isEmpty()) {
errs.addAll(errmessages);
}
}
use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.
the class TestBulkSchemaConcurrent method invokeBulkAddCall.
private void invokeBulkAddCall(int seed, ArrayList<String> errs) throws Exception {
String payload = "{\n" + " 'add-field' : {\n" + " 'name':'replaceFieldA',\n" + " 'type': 'string',\n" + " 'stored':true,\n" + " 'indexed':false\n" + " },\n" + " 'add-dynamic-field' : {\n" + " 'name' :'replaceDynamicField',\n" + " 'type':'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " },\n" + " 'add-copy-field' : {\n" + " 'source' :'replaceFieldA',\n" + " 'dest':['replaceDynamicCopyFieldDest']\n" + " },\n" + " 'add-field-type' : {\n" + " 'name' :'myNewFieldTypeName',\n" + " 'class' : 'solr.StrField',\n" + " 'sortMissingLast':'true'\n" + " }\n" + " }";
String aField = "a" + seed;
String dynamicFldName = "*_lol" + seed;
String dynamicCopyFldDest = "hello_lol" + seed;
String newFieldTypeName = "mystr" + seed;
payload = payload.replace("replaceFieldA", aField);
payload = payload.replace("replaceDynamicField", dynamicFldName);
payload = payload.replace("replaceDynamicCopyFieldDest", dynamicCopyFldDest);
payload = payload.replace("myNewFieldTypeName", newFieldTypeName);
RestTestHarness publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
String response = publisher.post("/schema?wt=json", SolrTestCaseJ4.json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
Object errors = map.get("errors");
if (errors != null) {
errs.add(new String(Utils.toJSON(errors), StandardCharsets.UTF_8));
return;
}
//get another node
Set<String> errmessages = new HashSet<>();
RestTestHarness harness = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
try {
long startTime = System.nanoTime();
long maxTimeoutMillis = 100000;
while (TimeUnit.MILLISECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutMillis) {
errmessages.clear();
Map m = getObj(harness, aField, "fields");
if (m == null)
errmessages.add(StrUtils.formatString("field {0} not created", aField));
m = getObj(harness, dynamicFldName, "dynamicFields");
if (m == null)
errmessages.add(StrUtils.formatString("dynamic field {0} not created", dynamicFldName));
List l = getSourceCopyFields(harness, aField);
if (!checkCopyField(l, aField, dynamicCopyFldDest))
errmessages.add(StrUtils.formatString("CopyField source={0},dest={1} not created", aField, dynamicCopyFldDest));
m = getObj(harness, newFieldTypeName, "fieldTypes");
if (m == null)
errmessages.add(StrUtils.formatString("new type {0} not created", newFieldTypeName));
if (errmessages.isEmpty())
break;
Thread.sleep(10);
}
} finally {
harness.close();
}
if (!errmessages.isEmpty()) {
errs.addAll(errmessages);
}
}
Aggregations