Search in sources :

Example 1 with TestBlobHandler.getAsString

use of org.apache.solr.handler.TestBlobHandler.getAsString in project lucene-solr by apache.

the class TestSolrConfigHandler method reqhandlertests.

public static void reqhandlertests(RestTestHarness writeHarness, String testServerBaseUrl, CloudSolrClient cloudSolrClient) throws Exception {
    String payload = "{\n" + "'create-requesthandler' : { 'name' : '/x', 'class': 'org.apache.solr.handler.DumpRequestHandler' , 'startup' : 'lazy'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudSolrClient, Arrays.asList("overlay", "requestHandler", "/x", "startup"), "lazy", 10);
    payload = "{\n" + "'update-requesthandler' : { 'name' : '/x', 'class': 'org.apache.solr.handler.DumpRequestHandler' ,registerPath :'/solr,/v2', " + " 'startup' : 'lazy' , 'a':'b' , 'defaults': {'def_a':'def A val', 'multival':['a','b','c']}}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudSolrClient, Arrays.asList("overlay", "requestHandler", "/x", "a"), "b", 10);
    payload = "{\n" + "'update-requesthandler' : { 'name' : '/dump', " + "'initParams': 'a'," + "'class': 'org.apache.solr.handler.DumpRequestHandler' ," + " 'defaults': {'a':'A','b':'B','c':'C'}}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudSolrClient, Arrays.asList("overlay", "requestHandler", "/dump", "defaults", "c"), "C", 10);
    testForResponseElement(writeHarness, testServerBaseUrl, "/x?wt=json&getdefaults=true&json.nl=map", cloudSolrClient, Arrays.asList("getdefaults", "def_a"), "def A val", 10);
    testForResponseElement(writeHarness, testServerBaseUrl, "/x?wt=json&param=multival&json.nl=map", cloudSolrClient, Arrays.asList("params", "multival"), Arrays.asList("a", "b", "c"), 10);
    payload = "{\n" + "'delete-requesthandler' : '/x'" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    boolean success = false;
    long startTime = System.nanoTime();
    int maxTimeoutSeconds = 10;
    while (TimeUnit.SECONDS.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS) < maxTimeoutSeconds) {
        String uri = "/config/overlay?wt=json";
        Map m = testServerBaseUrl == null ? getRespMap(uri, writeHarness) : TestSolrConfigHandlerConcurrent.getAsMap(testServerBaseUrl + uri, cloudSolrClient);
        if (null == Utils.getObjectByPath(m, true, Arrays.asList("overlay", "requestHandler", "/x", "a"))) {
            success = true;
            break;
        }
        Thread.sleep(100);
    }
    assertTrue("Could not delete requestHandler  ", success);
    payload = "{\n" + "'create-queryconverter' : { 'name' : 'qc', 'class': 'org.apache.solr.spelling.SpellingQueryConverter'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "queryConverter", "qc", "class"), "org.apache.solr.spelling.SpellingQueryConverter", 10);
    payload = "{\n" + "'update-queryconverter' : { 'name' : 'qc', 'class': 'org.apache.solr.spelling.SuggestQueryConverter'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "queryConverter", "qc", "class"), "org.apache.solr.spelling.SuggestQueryConverter", 10);
    payload = "{\n" + "'delete-queryconverter' : 'qc'" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "queryConverter", "qc"), null, 10);
    payload = "{\n" + "'create-searchcomponent' : { 'name' : 'tc', 'class': 'org.apache.solr.handler.component.TermsComponent'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "searchComponent", "tc", "class"), "org.apache.solr.handler.component.TermsComponent", 10);
    payload = "{\n" + "'update-searchcomponent' : { 'name' : 'tc', 'class': 'org.apache.solr.handler.component.TermVectorComponent' }\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "searchComponent", "tc", "class"), "org.apache.solr.handler.component.TermVectorComponent", 10);
    payload = "{\n" + "'delete-searchcomponent' : 'tc'" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "searchComponent", "tc"), null, 10);
    //<valueSourceParser name="countUsage" class="org.apache.solr.core.CountUsageValueSourceParser"/>
    payload = "{\n" + "'create-valuesourceparser' : { 'name' : 'cu', 'class': 'org.apache.solr.core.CountUsageValueSourceParser'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "valueSourceParser", "cu", "class"), "org.apache.solr.core.CountUsageValueSourceParser", 10);
    //  <valueSourceParser name="nvl" class="org.apache.solr.search.function.NvlValueSourceParser">
    //    <float name="nvlFloatValue">0.0</float>
    //    </valueSourceParser>
    payload = "{\n" + "'update-valuesourceparser' : { 'name' : 'cu', 'class': 'org.apache.solr.search.function.NvlValueSourceParser'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "valueSourceParser", "cu", "class"), "org.apache.solr.search.function.NvlValueSourceParser", 10);
    payload = "{\n" + "'delete-valuesourceparser' : 'cu'" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "valueSourceParser", "cu"), null, 10);
    //    <transformer name="mytrans2" class="org.apache.solr.response.transform.ValueAugmenterFactory" >
    //    <int name="value">5</int>
    //    </transformer>
    payload = "{\n" + "'create-transformer' : { 'name' : 'mytrans', 'class': 'org.apache.solr.response.transform.ValueAugmenterFactory', 'value':'5'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "transformer", "mytrans", "class"), "org.apache.solr.response.transform.ValueAugmenterFactory", 10);
    payload = "{\n" + "'update-transformer' : { 'name' : 'mytrans', 'class': 'org.apache.solr.response.transform.ValueAugmenterFactory', 'value':'6'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "transformer", "mytrans", "value"), "6", 10);
    payload = "{\n" + "'delete-transformer' : 'mytrans'," + "'create-initparams' : { 'name' : 'hello', 'key':'val'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    Map map = testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "transformer", "mytrans"), null, 10);
    List l = (List) Utils.getObjectByPath(map, false, Arrays.asList("config", "initParams"));
    assertNotNull("no object /config/initParams : " + TestBlobHandler.getAsString(map), l);
    assertEquals(2, l.size());
    assertEquals("val", ((Map) l.get(1)).get("key"));
    payload = "{\n" + "    'add-searchcomponent': {\n" + "        'name': 'myspellcheck',\n" + "        'class': 'solr.SpellCheckComponent',\n" + "        'queryAnalyzerFieldType': 'text_general',\n" + "        'spellchecker': {\n" + "            'name': 'default',\n" + "            'field': '_text_',\n" + "            'class': 'solr.DirectSolrSpellChecker'\n" + "        }\n" + "    }\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    map = testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "searchComponent", "myspellcheck", "spellchecker", "class"), "solr.DirectSolrSpellChecker", 10);
    payload = "{\n" + "    'add-requesthandler': {\n" + "        name : '/dump100',\n" + "       registerPath :'/solr,/v2'," + "        class : 'org.apache.solr.handler.DumpRequestHandler'," + "        suggester: [{name: s1,lookupImpl: FuzzyLookupFactory, dictionaryImpl : DocumentDictionaryFactory}," + "                    {name: s2,lookupImpl: FuzzyLookupFactory , dictionaryImpl : DocumentExpressionDictionaryFactory}]" + "    }\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    map = testForResponseElement(writeHarness, testServerBaseUrl, "/config?wt=json", cloudSolrClient, Arrays.asList("config", "requestHandler", "/dump100", "class"), "org.apache.solr.handler.DumpRequestHandler", 10);
    map = getRespMap("/dump100?wt=json&json.nl=arrmap&initArgs=true", writeHarness);
    List initArgs = (List) map.get("initArgs");
    assertNotNull(initArgs);
    assertTrue(initArgs.size() >= 2);
    assertTrue(((Map) initArgs.get(2)).containsKey("suggester"));
    assertTrue(((Map) initArgs.get(1)).containsKey("suggester"));
    payload = "{\n" + "'add-requesthandler' : { 'name' : '/dump101', 'class': " + "'" + CacheTest.class.getName() + "', " + "    registerPath :'/solr,/v2'" + ", 'startup' : 'lazy'}\n" + "}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudSolrClient, Arrays.asList("overlay", "requestHandler", "/dump101", "startup"), "lazy", 10);
    payload = "{\n" + "'add-cache' : {name:'lfuCacheDecayFalse', class:'solr.search.LFUCache', size:10 ,initialSize:9 , timeDecay:false }," + "'add-cache' : {name: 'perSegFilter', class: 'solr.search.LRUCache', size:10, initialSize:0 , autowarmCount:10}}";
    runConfigCommand(writeHarness, "/config?wt=json", payload);
    map = testForResponseElement(writeHarness, testServerBaseUrl, "/config/overlay?wt=json", cloudSolrClient, Arrays.asList("overlay", "cache", "lfuCacheDecayFalse", "class"), "solr.search.LFUCache", 10);
    assertEquals("solr.search.LRUCache", getObjectByPath(map, true, ImmutableList.of("overlay", "cache", "perSegFilter", "class")));
    map = getRespMap("/dump101?cacheNames=lfuCacheDecayFalse&cacheNames=perSegFilter&wt=json", writeHarness);
    assertEquals("Actual output " + Utils.toJSONString(map), "org.apache.solr.search.LRUCache", getObjectByPath(map, true, ImmutableList.of("caches", "perSegFilter")));
    assertEquals("Actual output " + Utils.toJSONString(map), "org.apache.solr.search.LFUCache", getObjectByPath(map, true, ImmutableList.of("caches", "lfuCacheDecayFalse")));
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) TestBlobHandler.getAsString(org.apache.solr.handler.TestBlobHandler.getAsString) HashMap(java.util.HashMap) Map(java.util.Map) ValidatingJsonMap(org.apache.solr.common.util.ValidatingJsonMap) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 ValidatingJsonMap (org.apache.solr.common.util.ValidatingJsonMap)1 TestBlobHandler.getAsString (org.apache.solr.handler.TestBlobHandler.getAsString)1