You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2016/10/15 14:35:27 UTC
lucene-solr:branch_6x: SOLR-9625: Add HelloWorldSolrCloudTestCase
class (Christine Poerschke, Alan Woodward, Alexandre Rafalovitch)
Repository: lucene-solr
Updated Branches:
refs/heads/branch_6x bc5e06e34 -> c620fc295
SOLR-9625: Add HelloWorldSolrCloudTestCase class (Christine Poerschke, Alan Woodward, Alexandre Rafalovitch)
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/c620fc29
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/c620fc29
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/c620fc29
Branch: refs/heads/branch_6x
Commit: c620fc2954090d7cfc38988c7e490113ee3ce4a4
Parents: bc5e06e
Author: Christine Poerschke <cp...@apache.org>
Authored: Sat Oct 15 09:44:37 2016 -0400
Committer: Christine Poerschke <cp...@apache.org>
Committed: Sat Oct 15 10:18:17 2016 -0400
----------------------------------------------------------------------
solr/CHANGES.txt | 2 +
.../solr/HelloWorldSolrCloudTestCase.java | 94 ++++++++++++++++++++
2 files changed, 96 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c620fc29/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c1d2ea9..51f5eda 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -242,6 +242,8 @@ Other Changes
* SOLR-9639: Test only fix. Prevent CDCR tests from removing collection during recovery that used to blow up jvm (Mikhail Khludnev)
+* SOLR-9625: Add HelloWorldSolrCloudTestCase class (Christine Poerschke, Alan Woodward, Alexandre Rafalovitch)
+
================== 6.2.1 ==================
Bug Fixes
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/c620fc29/solr/core/src/test/org/apache/solr/HelloWorldSolrCloudTestCase.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/HelloWorldSolrCloudTestCase.java b/solr/core/src/test/org/apache/solr/HelloWorldSolrCloudTestCase.java
new file mode 100644
index 0000000..56a813c
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/HelloWorldSolrCloudTestCase.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr;
+
+import org.apache.solr.client.solrj.SolrQuery;
+import org.apache.solr.client.solrj.impl.CloudSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.UpdateRequest;
+import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.cloud.SolrCloudTestCase;
+import org.apache.solr.common.SolrInputDocument;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * How to use this test class:
+ * #1 Run the test, e.g.
+ * in Eclipse 'Run As JUnit Test' or
+ * on the command line: cd solr/core ; ant test -Dtestcase=HelloWorldSolrCloudTestCase
+ * #2 Modify the test, e.g.
+ * in setupCluster add further documents and then re-run the test.
+ */
+public class HelloWorldSolrCloudTestCase extends SolrCloudTestCase {
+
+ private static final String COLLECTION = "hello_world" ;
+
+ private static final int numShards = 3;
+ private static final int numReplicas = 2;
+ private static final int maxShardsPerNode = 2;
+ private static final int nodeCount = (numShards*numReplicas + (maxShardsPerNode-1))/maxShardsPerNode;
+
+ private static final String id = "id";
+
+ @BeforeClass
+ public static void setupCluster() throws Exception {
+
+ // create and configure cluster
+ configureCluster(nodeCount)
+ .addConfig("conf", configset("cloud-dynamic"))
+ .configure();
+
+ // create an empty collection
+ CollectionAdminRequest.createCollection(COLLECTION, "conf", numShards, numReplicas)
+ .setMaxShardsPerNode(maxShardsPerNode)
+ .process(cluster.getSolrClient());
+
+ // add a document
+ final SolrInputDocument doc1 = sdoc(id, "1",
+ "title_s", "Here comes the sun",
+ "artist_s", "The Beatles",
+ "popularity_i", "123");
+ new UpdateRequest()
+ .add(doc1)
+ .commit(cluster.getSolrClient(), COLLECTION);
+
+ // add further document(s) here
+ // TODO
+ }
+
+ @Test
+ public void testHighestScoring() throws Exception {
+ final SolrQuery solrQuery = new SolrQuery("q", "*:*", "fl", "id,popularity_i", "sort", "popularity_i desc", "rows", "1");
+ final CloudSolrClient cloudSolrClient = cluster.getSolrClient();
+ final QueryResponse rsp = cloudSolrClient.query(COLLECTION, solrQuery);
+ assertEquals(1, rsp.getResults().size());
+ assertEquals("1", rsp.getResults().get(0).getFieldValue(id));
+ }
+
+ @Test
+ public void testLowestScoring() throws Exception {
+ final SolrQuery solrQuery = new SolrQuery("q", "*:*", "fl", "id,popularity_i", "sort", "popularity_i asc", "rows", "1");
+ final CloudSolrClient cloudSolrClient = cluster.getSolrClient();
+ final QueryResponse rsp = cloudSolrClient.query(COLLECTION, solrQuery);
+ assertEquals(1, rsp.getResults().size());
+ assertEquals("1", rsp.getResults().get(0).getFieldValue(id));
+ }
+
+}
+