Search in sources :

Example 11 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SolrTestCaseJ4 method jsonDelQ.

/** Creates a JSON deleteByQuery command */
public static String jsonDelQ(String... queries) {
    CharArr out = new CharArr();
    try {
        out.append('{');
        boolean first = true;
        for (Object q : queries) {
            if (first)
                first = false;
            else
                out.append(',');
            out.append("\"delete\":{\"query\":");
            out.append(JSONUtil.toJSON(q));
            out.append('}');
        }
        out.append('}');
    } catch (IOException e) {
    // should never happen
    }
    return out.toString();
}
Also used : IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 12 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class TestJavaBinCodec method testPerf.

private void testPerf() throws InterruptedException {
    final ArrayList<JavaBinCodec.StringBytes> l = new ArrayList<>();
    Cache<JavaBinCodec.StringBytes, String> cache = null;
    /* cache = new ConcurrentLRUCache<JavaBinCodec.StringBytes,String>(10000, 9000, 10000, 1000, false, true, null){
      @Override
      public String put(JavaBinCodec.StringBytes key, String val) {
        l.add(key);
        return super.put(key, val);
      }
    };*/
    Runtime.getRuntime().gc();
    printMem("before cache init");
    Cache<JavaBinCodec.StringBytes, String> cache1 = new MapBackedCache<>(new HashMap<>());
    final JavaBinCodec.StringCache STRING_CACHE = new JavaBinCodec.StringCache(cache1);
    //    STRING_CACHE = new JavaBinCodec.StringCache(cache);
    byte[] bytes = new byte[0];
    JavaBinCodec.StringBytes stringBytes = new JavaBinCodec.StringBytes(null, 0, 0);
    for (int i = 0; i < 10000; i++) {
        String s = String.valueOf(random().nextLong());
        int end = s.length();
        int maxSize = end * 4;
        if (bytes == null || bytes.length < maxSize)
            bytes = new byte[maxSize];
        int sz = ByteUtils.UTF16toUTF8(s, 0, end, bytes, 0);
        STRING_CACHE.get(stringBytes.reset(bytes, 0, sz));
    }
    printMem("after cache init");
    RTimer timer = new RTimer();
    final int ITERS = 1000000;
    int THREADS = 10;
    runInThreads(THREADS, () -> {
        JavaBinCodec.StringBytes stringBytes1 = new JavaBinCodec.StringBytes(new byte[0], 0, 0);
        for (int i = 0; i < ITERS; i++) {
            JavaBinCodec.StringBytes b = l.get(i % l.size());
            stringBytes1.reset(b.bytes, 0, b.bytes.length);
            if (STRING_CACHE.get(stringBytes1) == null)
                throw new RuntimeException("error");
        }
    });
    printMem("after cache test");
    System.out.println("time taken by LRUCACHE " + timer.getTime());
    timer = new RTimer();
    runInThreads(THREADS, () -> {
        String a = null;
        CharArr arr = new CharArr();
        for (int i = 0; i < ITERS; i++) {
            JavaBinCodec.StringBytes sb = l.get(i % l.size());
            arr.reset();
            ByteUtils.UTF8toUTF16(sb.bytes, 0, sb.bytes.length, arr);
            a = arr.toString();
        }
    });
    printMem("after new string test");
    System.out.println("time taken by string creation " + timer.getTime());
}
Also used : ArrayList(java.util.ArrayList) RTimer(org.apache.solr.util.RTimer) CharArr(org.noggit.CharArr)

Example 13 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class SolrTestCaseJ4 method jsonAdd.

/** Creates a JSON add command from a SolrInputDocument list.  Doesn't currently handle boosts. */
public static String jsonAdd(SolrInputDocument... docs) {
    CharArr out = new CharArr();
    try {
        out.append('[');
        boolean firstField = true;
        for (SolrInputDocument doc : docs) {
            if (firstField)
                firstField = false;
            else
                out.append(',');
            out.append(json(doc));
        }
        out.append(']');
    } catch (IOException e) {
    // should never happen
    }
    return out.toString();
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) IOException(java.io.IOException) CharArr(org.noggit.CharArr)

Example 14 with CharArr

use of org.noggit.CharArr in project lucene-solr by apache.

the class TestDelegationTokenResponse method getMapJson.

private String getMapJson(String key, Object value) {
    CharArr out = new CharArr();
    JSONWriter w = new JSONWriter(out, 2);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(key, value);
    w.write(map);
    return out.toString();
}
Also used : JSONWriter(org.noggit.JSONWriter) HashMap(java.util.HashMap) CharArr(org.noggit.CharArr)

Aggregations

CharArr (org.noggit.CharArr)14 IOException (java.io.IOException)6 JSONWriter (org.noggit.JSONWriter)6 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONParser (org.noggit.JSONParser)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 SolrInputDocument (org.apache.solr.common.SolrInputDocument)1 ClusterState (org.apache.solr.common.cloud.ClusterState)1 DocCollection (org.apache.solr.common.cloud.DocCollection)1 LocalSolrQueryRequest (org.apache.solr.request.LocalSolrQueryRequest)1 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)1 RTimer (org.apache.solr.util.RTimer)1 Test (org.junit.Test)1