Search in sources :

Example 36 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestCloudManagedSchemaConcurrent method schemaLockTest.

private void schemaLockTest() throws Exception {
    // First, add a bunch of 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 = 5;
    Info info = new Info("Thread");
    for (int i = 0; i <= numFields; ++i) {
        // System.err.println("###ITERATION: " + i);
        RestTestHarness publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PostFieldThread postFieldThread = new PostFieldThread(publisher, info);
        postFieldThread.start();
        publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PutFieldThread putFieldThread = new PutFieldThread(publisher, info);
        putFieldThread.start();
        publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PostDynamicFieldThread postDynamicFieldThread = new PostDynamicFieldThread(publisher, info);
        postDynamicFieldThread.start();
        publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PutDynamicFieldThread putDynamicFieldThread = new PutDynamicFieldThread(publisher, info);
        putDynamicFieldThread.start();
        publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PostFieldTypeThread postFieldTypeThread = new PostFieldTypeThread(publisher, info);
        postFieldTypeThread.start();
        publisher = restTestHarnesses.get(r.nextInt(restTestHarnesses.size()));
        PutFieldTypeThread putFieldTypeThread = new PutFieldTypeThread(publisher, info);
        putFieldTypeThread.start();
        postFieldThread.join();
        putFieldThread.join();
        postDynamicFieldThread.join();
        putDynamicFieldThread.join();
        postFieldTypeThread.join();
        putFieldTypeThread.join();
        String[] expectedAddFields = getExpectedFieldResponses(info);
        String[] expectedAddFieldTypes = getExpectedFieldTypeResponses(info);
        String[] expectedAddDynamicFields = getExpectedDynamicFieldResponses(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(10);
            // int j = 0;
            for (RestTestHarness client : restTestHarnesses) {
                // System.err.println("###CHECKING HARNESS: " + j++ + " for iteration: " + i);
                // verify addFieldPuts and addFieldPosts
                request = "/schema/fields?wt=xml";
                response = client.query(request);
                //System.err.println("###RESPONSE: " + response);
                result = BaseTestHarness.validateXPath(response, expectedAddFields);
                if (result != null) {
                    // System.err.println("###FAILURE!");
                    break;
                }
                // verify addDynamicFieldPuts and addDynamicFieldPosts
                request = "/schema/dynamicfields?wt=xml";
                response = client.query(request);
                //System.err.println("###RESPONSE: " + response);
                result = BaseTestHarness.validateXPath(response, expectedAddDynamicFields);
                if (result != null) {
                    // System.err.println("###FAILURE!");
                    break;
                }
                request = "/schema/fieldtypes?wt=xml";
                response = client.query(request);
                //System.err.println("###RESPONSE: " + response);
                result = BaseTestHarness.validateXPath(response, expectedAddFieldTypes);
                if (result != null) {
                    // System.err.println("###FAILURE!");
                    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 37 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestBulkSchemaConcurrent method invokeBulkDeleteCall.

private void invokeBulkDeleteCall(int seed, ArrayList<String> errs) throws Exception {
    String payload = "{\n" + "          'delete-copy-field' : {\n" + "                       'source' :'replaceFieldA',\n" + "                       'dest':['replaceDynamicCopyFieldDest']\n" + "                       },\n" + "          'delete-field' : {'name':'replaceFieldA'},\n" + "          'delete-dynamic-field' : {'name' :'replaceDynamicField'},\n" + "          'delete-field-type' : {'name' :'myNewFieldTypeName'}\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} still exists", aField));
            m = getObj(harness, dynamicFldName, "dynamicFields");
            if (m != null)
                errmessages.add(StrUtils.formatString("dynamic field {0} still exists", dynamicFldName));
            List l = getSourceCopyFields(harness, aField);
            if (checkCopyField(l, aField, dynamicCopyFldDest))
                errmessages.add(StrUtils.formatString("CopyField source={0},dest={1} still exists", aField, dynamicCopyFldDest));
            m = getObj(harness, newFieldTypeName, "fieldTypes");
            if (m != null)
                errmessages.add(StrUtils.formatString("new type {0} still exists", 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 38 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestBulkSchemaAPI method testMultipleCommands.

public void testMultipleCommands() throws Exception {
    RestTestHarness harness = restTestHarness;
    Map m = getObj(harness, "wdf_nocase", "fields");
    assertNotNull("'wdf_nocase' field does not exist in the schema", m);
    m = getObj(harness, "wdf_nocase", "fieldTypes");
    assertNotNull("'wdf_nocase' field type does not exist in the schema", m);
    m = getObj(harness, "boolean", "fieldTypes");
    assertNotNull("'boolean' field type does not exist in the schema", m);
    assertNull(m.get("sortMissingFirst"));
    assertTrue((Boolean) m.get("sortMissingLast"));
    m = getObj(harness, "name", "fields");
    assertNotNull("'name' field does not exist in the schema", m);
    assertEquals("nametext", m.get("type"));
    m = getObj(harness, "bind", "fields");
    assertNotNull("'bind' field does not exist in the schema", m);
    assertEquals("boolean", m.get("type"));
    m = getObj(harness, "attr_*", "dynamicFields");
    assertNotNull("'attr_*' dynamic field does not exist in the schema", m);
    assertEquals("text", m.get("type"));
    List l = getSourceCopyFields(harness, "*_i");
    Set s = new HashSet();
    assertEquals(4, l.size());
    s.add(((Map) l.get(0)).get("dest"));
    s.add(((Map) l.get(1)).get("dest"));
    s.add(((Map) l.get(2)).get("dest"));
    s.add(((Map) l.get(3)).get("dest"));
    assertTrue(s.contains("title"));
    assertTrue(s.contains("*_s"));
    String payload = "{\n" + "          'add-field' : {\n" + "                       'name':'a1',\n" + "                       'type': 'string',\n" + "                       'stored':true,\n" + "                       'indexed':false\n" + "                       },\n" + "          'add-field' : {\n" + "                       'name':'a2',\n" + "                       'type': 'string',\n" + "                       'stored':true,\n" + "                       'indexed':true\n" + "                       },\n" + "          'add-dynamic-field' : {\n" + "                       'name' :'*_lol',\n" + "                       'type':'string',\n" + "                       'stored':true,\n" + "                       'indexed':true\n" + "                       },\n" + "          'add-copy-field' : {\n" + "                       'source' :'a1',\n" + "                       'dest':['a2','hello_lol']\n" + "                       },\n" + "          'add-field-type' : {\n" + "                       'name' :'mystr',\n" + "                       'class' : 'solr.StrField',\n" + "                       'sortMissingLast':'true'\n" + "                       },\n" + "          'add-field-type' : {" + "                       'name' : 'myNewTxtField',\n" + "                       'class':'solr.TextField',\n" + "                       'positionIncrementGap':'100',\n" + "                       'indexAnalyzer' : {\n" + "                               'charFilters':[\n" + "                                          {\n" + "                                           'class':'solr.PatternReplaceCharFilterFactory',\n" + "                                           'replacement':'$1$1',\n" + "                                           'pattern':'([a-zA-Z])\\\\\\\\1+'\n" + "                                          }\n" + "                                         ],\n" + "                               'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'},\n" + "                               'filters':[\n" + "                                          {\n" + "                                           'class':'solr.WordDelimiterGraphFilterFactory',\n" + "                                           'preserveOriginal':'0'\n" + "                                          },\n" + "                                          {\n" + "                                           'class':'solr.StopFilterFactory',\n" + "                                           'words':'stopwords.txt',\n" + "                                           'ignoreCase':'true'\n" + "                                          },\n" + "                                          {'class':'solr.LowerCaseFilterFactory'},\n" + "                                          {'class':'solr.ASCIIFoldingFilterFactory'},\n" + "                                          {'class':'solr.KStemFilterFactory'},\n" + "                                          {'class':'solr.FlattenGraphFilterFactory'}\n" + "                                         ]\n" + "                               },\n" + "                       'queryAnalyzer' : {\n" + "                               'charFilters':[\n" + "                                          {\n" + "                                           'class':'solr.PatternReplaceCharFilterFactory',\n" + "                                           'replacement':'$1$1',\n" + "                                           'pattern':'([a-zA-Z])\\\\\\\\1+'\n" + "                                          }\n" + "                                         ],\n" + "                               'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'},\n" + "                               'filters':[\n" + "                                          {\n" + "                                           'class':'solr.WordDelimiterGraphFilterFactory',\n" + "                                           'preserveOriginal':'0'\n" + "                                          },\n" + "                                          {\n" + "                                           'class':'solr.StopFilterFactory',\n" + "                                           'words':'stopwords.txt',\n" + "                                           'ignoreCase':'true'\n" + "                                          },\n" + "                                          {'class':'solr.LowerCaseFilterFactory'},\n" + "                                          {'class':'solr.ASCIIFoldingFilterFactory'},\n" + "                                          {'class':'solr.KStemFilterFactory'}\n" + "                                         ]\n" + "                               }\n" + "                       },\n" + "          'add-field' : {\n" + "                       'name':'a3',\n" + "                       'type': 'myNewTxtField',\n" + "                       'stored':true,\n" + "                       'indexed':true\n" + "                       },\n" + "          'add-field-type' : {" + "                       'name' : 'myWhitespaceTxtField',\n" + "                       'class':'solr.TextField',\n" + "                       'analyzer' : {'class' : 'org.apache.lucene.analysis.core.WhitespaceAnalyzer'}\n" + "                       },\n" + "          'add-field' : {\n" + "                       'name':'a5',\n" + "                       'type': 'myWhitespaceTxtField',\n" + "                       'stored':true\n" + "                       },\n" + "          'add-field-type' : {" + "                       'name' : 'mySimField',\n" + "                       'class':'solr.TextField',\n" + "                       'analyzer' : {'tokenizer':{'class':'solr.WhitespaceTokenizerFactory'}},\n" + "                       'similarity' : {'class':'org.apache.lucene.misc.SweetSpotSimilarity'}\n" + "                       },\n" + "          'add-field' : {\n" + "                       'name':'a4',\n" + "                       'type': 'mySimField',\n" + "                       'stored':true,\n" + "                       'indexed':true\n" + "                       },\n" + "          'delete-field' : {'name':'wdf_nocase'},\n" + "          'delete-field-type' : {'name':'wdf_nocase'},\n" + "          'delete-dynamic-field' : {'name':'*_tt'},\n" + "          'delete-copy-field' : {'source':'a1', 'dest':'a2'},\n" + "          'delete-copy-field' : {'source':'*_i', 'dest':['title', '*_s']},\n" + "          'replace-field-type' : {\n" + "                       'name':'boolean',\n" + "                       'class':'solr.BoolField',\n" + "                       'sortMissingFirst':true\n" + "                       },\n" + "          'replace-field' : {\n" + "                       'name':'name',\n" + "                       'type':'string',\n" + "                       'indexed':true,\n" + "                       'stored':true\n" + "                       },\n" + "          'replace-dynamic-field' : {\n" + "                       'name':'attr_*',\n" + "                       'type':'string',\n" + "                       'indexed':true,\n" + "                       'stored':true,\n" + "                       'multiValued':true\n" + "                       }\n" + "          }\n";
    String response = harness.post("/schema?wt=json", json(payload));
    Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
    assertNull(response, map.get("errors"));
    m = getObj(harness, "a1", "fields");
    assertNotNull("field a1 not created", m);
    assertEquals("string", m.get("type"));
    assertEquals(Boolean.TRUE, m.get("stored"));
    assertEquals(Boolean.FALSE, m.get("indexed"));
    m = getObj(harness, "a2", "fields");
    assertNotNull("field a2 not created", m);
    assertEquals("string", m.get("type"));
    assertEquals(Boolean.TRUE, m.get("stored"));
    assertEquals(Boolean.TRUE, m.get("indexed"));
    m = getObj(harness, "*_lol", "dynamicFields");
    assertNotNull("field *_lol not created", m);
    assertEquals("string", m.get("type"));
    assertEquals(Boolean.TRUE, m.get("stored"));
    assertEquals(Boolean.TRUE, m.get("indexed"));
    l = getSourceCopyFields(harness, "a1");
    s = new HashSet();
    assertEquals(1, l.size());
    s.add(((Map) l.get(0)).get("dest"));
    assertTrue(s.contains("hello_lol"));
    l = getSourceCopyFields(harness, "*_i");
    s = new HashSet();
    assertEquals(2, l.size());
    s.add(((Map) l.get(0)).get("dest"));
    s.add(((Map) l.get(1)).get("dest"));
    assertFalse(s.contains("title"));
    assertFalse(s.contains("*_s"));
    m = getObj(harness, "mystr", "fieldTypes");
    assertNotNull(m);
    assertEquals("solr.StrField", m.get("class"));
    assertEquals("true", String.valueOf(m.get("sortMissingLast")));
    m = getObj(harness, "myNewTxtField", "fieldTypes");
    assertNotNull(m);
    m = getObj(harness, "a3", "fields");
    assertNotNull("field a3 not created", m);
    assertEquals("myNewTxtField", m.get("type"));
    m = getObj(harness, "mySimField", "fieldTypes");
    assertNotNull(m);
    m = (Map) m.get("similarity");
    assertNotNull(m);
    assertEquals(SweetSpotSimilarity.class.getName(), m.get("class"));
    m = getObj(harness, "a4", "fields");
    assertNotNull("field a4 not created", m);
    assertEquals("mySimField", m.get("type"));
    assertFieldSimilarity("a4", SweetSpotSimilarity.class);
    m = getObj(harness, "myWhitespaceTxtField", "fieldTypes");
    assertNotNull(m);
    // unspecified, expect default
    assertNull(m.get("similarity"));
    m = getObj(harness, "a5", "fields");
    assertNotNull("field a5 not created", m);
    assertEquals("myWhitespaceTxtField", m.get("type"));
    // unspecified, expect default
    assertFieldSimilarity("a5", BM25Similarity.class);
    m = getObj(harness, "wdf_nocase", "fields");
    assertNull("field 'wdf_nocase' not deleted", m);
    m = getObj(harness, "wdf_nocase", "fieldTypes");
    assertNull("field type 'wdf_nocase' not deleted", m);
    m = getObj(harness, "*_tt", "dynamicFields");
    assertNull("dynamic field '*_tt' not deleted", m);
    m = getObj(harness, "boolean", "fieldTypes");
    assertNotNull("'boolean' field type does not exist in the schema", m);
    assertNull(m.get("sortMissingLast"));
    assertTrue((Boolean) m.get("sortMissingFirst"));
    // this field will be rebuilt when "boolean" field type is replaced
    m = getObj(harness, "bind", "fields");
    assertNotNull("'bind' field does not exist in the schema", m);
    m = getObj(harness, "name", "fields");
    assertNotNull("'name' field does not exist in the schema", m);
    assertEquals("string", m.get("type"));
    m = getObj(harness, "attr_*", "dynamicFields");
    assertNotNull("'attr_*' dynamic field does not exist in the schema", m);
    assertEquals("string", m.get("type"));
}
Also used : SweetSpotSimilarity(org.apache.lucene.misc.SweetSpotSimilarity) HashSet(java.util.HashSet) Set(java.util.Set) RestTestHarness(org.apache.solr.util.RestTestHarness) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) JSONParser(org.noggit.JSONParser) Map(java.util.Map) HashSet(java.util.HashSet)

Example 39 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestBulkSchemaAPI method testAddFieldMatchingExistingDynamicField.

public void testAddFieldMatchingExistingDynamicField() throws Exception {
    RestTestHarness harness = restTestHarness;
    String newFieldName = "attr_non_dynamic";
    Map map = getObj(harness, newFieldName, "fields");
    assertNull("Field '" + newFieldName + "' already exists in the schema", map);
    map = getObj(harness, "attr_*", "dynamicFields");
    assertNotNull("'attr_*' dynamic field does not exist in the schema", map);
    map = getObj(harness, "boolean", "fieldTypes");
    assertNotNull("'boolean' field type does not exist in the schema", map);
    String payload = "{\n" + "    'add-field' : {\n" + "                 'name':'" + newFieldName + "',\n" + "                 'type':'boolean',\n" + "                 'stored':true,\n" + "                 'indexed':true\n" + "                 }\n" + "    }";
    String response = harness.post("/schema?wt=json", json(payload));
    map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
    assertNull(response, map.get("errors"));
    map = getObj(harness, newFieldName, "fields");
    assertNotNull("Field '" + newFieldName + "' is not in the schema", map);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) StringReader(java.io.StringReader) JSONParser(org.noggit.JSONParser) Map(java.util.Map)

Example 40 with RestTestHarness

use of org.apache.solr.util.RestTestHarness in project lucene-solr by apache.

the class TestBulkSchemaAPI method testAddIllegalDynamicField.

public void testAddIllegalDynamicField() throws Exception {
    RestTestHarness harness = restTestHarness;
    String newFieldName = "illegal";
    String payload = "{\n" + "    'add-dynamic-field' : {\n" + "                 'name':'" + newFieldName + "',\n" + "                 'type':'string',\n" + "                 'stored':true,\n" + "                 'indexed':true\n" + "                 }\n" + "    }";
    String response = harness.post("/schema?wt=json", json(payload));
    Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
    assertNotNull(response, map.get("errors"));
    map = getObj(harness, newFieldName, "dynamicFields");
    assertNull(newFieldName + " illegal dynamic field should not have been added to schema", map);
}
Also used : RestTestHarness(org.apache.solr.util.RestTestHarness) StringReader(java.io.StringReader) JSONParser(org.noggit.JSONParser) Map(java.util.Map)

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