Search in sources :

Example 16 with RestTestHarness

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();
    }
}
Also used : ZkCoreNodeProps(org.apache.solr.common.cloud.ZkCoreNodeProps) RestTestHarness(org.apache.solr.util.RestTestHarness)

Example 17 with RestTestHarness

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);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness)

Example 18 with RestTestHarness

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);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) SolrClient(org.apache.solr.client.solrj.SolrClient) HttpSolrClient(org.apache.solr.client.solrj.impl.HttpSolrClient)

Example 19 with RestTestHarness

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);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) StringReader(java.io.StringReader) JSONParser(org.noggit.JSONParser) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Example 20 with RestTestHarness

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);
    }
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) StringReader(java.io.StringReader) JSONParser(org.noggit.JSONParser) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

RestTestHarness (org.apache.solr.util.RestTestHarness)40 Map (java.util.Map)19 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)15 StringReader (java.io.StringReader)12 JSONParser (org.noggit.JSONParser)12 SolrClient (org.apache.solr.client.solrj.SolrClient)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)6 List (java.util.List)6 TestBlobHandler.getAsString (org.apache.solr.handler.TestBlobHandler.getAsString)6 Test (org.junit.Test)6 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)5 Replica (org.apache.solr.common.cloud.Replica)4 Slice (org.apache.solr.common.cloud.Slice)4 HashMap (java.util.HashMap)3 SortedMap (java.util.SortedMap)3 TreeMap (java.util.TreeMap)3 DocCollection (org.apache.solr.common.cloud.DocCollection)3 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)3 ByteBuffer (java.nio.ByteBuffer)2