|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.solr.handler.component; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 20 | +import org.apache.commons.io.input.ReversedLinesFileReader; |
| 21 | +import org.apache.lucene.tests.util.LuceneTestCase; |
| 22 | +import org.apache.solr.client.solrj.io.SolrClientCache; |
| 23 | +import org.apache.solr.client.solrj.io.Tuple; |
| 24 | +import org.apache.solr.client.solrj.io.stream.*; |
| 25 | +import org.apache.solr.client.solrj.io.stream.expr.StreamExpression; |
| 26 | +import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParser; |
| 27 | +import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; |
| 28 | +import org.apache.solr.client.solrj.request.CollectionAdminRequest; |
| 29 | +import org.apache.solr.client.solrj.request.UpdateRequest; |
| 30 | +import org.apache.solr.client.solrj.response.QueryResponse; |
| 31 | +import org.apache.solr.cloud.AbstractDistribZkTestBase; |
| 32 | +import org.apache.solr.cloud.SolrCloudTestCase; |
| 33 | +import org.apache.solr.common.SolrInputDocument; |
| 34 | +import org.apache.solr.common.params.MapSolrParams; |
| 35 | +import org.apache.solr.common.params.SolrParams; |
| 36 | +import org.apache.solr.core.SolrCore; |
| 37 | +import org.apache.solr.embedded.JettySolrRunner; |
| 38 | +import org.apache.solr.handler.LoggingStream; |
| 39 | +import org.junit.Before; |
| 40 | +import org.junit.BeforeClass; |
| 41 | +import org.junit.Test; |
| 42 | + |
| 43 | +import java.io.IOException; |
| 44 | +import java.nio.charset.StandardCharsets; |
| 45 | +import java.nio.file.Path; |
| 46 | +import java.time.Instant; |
| 47 | +import java.util.*; |
| 48 | + |
| 49 | +@LuceneTestCase.SuppressCodecs({"Lucene3x", "Lucene40", "Lucene41", "Lucene42", "Lucene45"}) |
| 50 | +public class UBIComponentDistrQueriesTest extends SolrCloudTestCase { |
| 51 | + |
| 52 | + private static final String COLLECTIONORALIAS = "collection1"; |
| 53 | + private static final int TIMEOUT = DEFAULT_TIMEOUT; |
| 54 | + private static final String id = "id"; |
| 55 | + |
| 56 | + private static boolean useAlias; |
| 57 | + |
| 58 | + @BeforeClass |
| 59 | + public static void setupCluster() throws Exception { |
| 60 | + configureCluster(4) |
| 61 | + .addConfig( |
| 62 | + "conf", TEST_PATH().resolve("configsets").resolve("ubi-enabled").resolve("conf")) |
| 63 | + .configure(); |
| 64 | + |
| 65 | + String collection; |
| 66 | + useAlias = random().nextBoolean(); |
| 67 | + if (useAlias) { |
| 68 | + collection = COLLECTIONORALIAS + "_collection"; |
| 69 | + } else { |
| 70 | + collection = COLLECTIONORALIAS; |
| 71 | + } |
| 72 | + |
| 73 | + CollectionAdminRequest.createCollection(collection, "conf", 2, 1) |
| 74 | + .process(cluster.getSolrClient()); |
| 75 | + |
| 76 | + cluster.waitForActiveCollection(collection, 2, 2); |
| 77 | + |
| 78 | + AbstractDistribZkTestBase.waitForRecoveriesToFinish( |
| 79 | + collection, cluster.getZkStateReader(), false, true, TIMEOUT); |
| 80 | + if (useAlias) { |
| 81 | + CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection) |
| 82 | + .process(cluster.getSolrClient()); |
| 83 | + } |
| 84 | + |
| 85 | + // ------------------- |
| 86 | + |
| 87 | + CollectionAdminRequest.createCollection("ubi_queries", "_default", 1, 1) |
| 88 | + .process(cluster.getSolrClient()); |
| 89 | + |
| 90 | + cluster.waitForActiveCollection("ubi_queries", 1, 1); |
| 91 | + |
| 92 | + AbstractDistribZkTestBase.waitForRecoveriesToFinish( |
| 93 | + "ubi_queries", cluster.getZkStateReader(), false, true, TIMEOUT); |
| 94 | + } |
| 95 | + |
| 96 | + @Before |
| 97 | + public void cleanIndex() throws Exception { |
| 98 | + new UpdateRequest().deleteByQuery("*:*").commit(cluster.getSolrClient(), COLLECTIONORALIAS); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testUBIQueryStream() throws Exception { |
| 103 | + cluster.getSolrClient(COLLECTIONORALIAS).add(List.of(new SolrInputDocument("id", "1", "subject", "aa"), |
| 104 | + new SolrInputDocument("id", "two", "subject", "aa"), |
| 105 | + new SolrInputDocument("id", "3", "subject", "aa"))); |
| 106 | + cluster.getSolrClient(COLLECTIONORALIAS).commit(true, true); |
| 107 | + QueryResponse queryResponse = cluster.getSolrClient(COLLECTIONORALIAS).query(new MapSolrParams(Map.of("q", "aa", "rows", "2", "ubi", "true"))); |
| 108 | + System.out.println(queryResponse); |
| 109 | + } |
| 110 | +} |
0 commit comments