You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by tf...@apache.org on 2016/10/15 23:55:31 UTC

[19/24] lucene-solr:jira/solr-8396: SOLR-9625: Add HelloWorldSolrCloudTestCase class (Christine Poerschke, Alan Woodward, Alexandre Rafalovitch)

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/5261eb0a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5261eb0a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5261eb0a

Branch: refs/heads/jira/solr-8396
Commit: 5261eb0acd54848a5aafb542990d7391d77f94c1
Parents: 33db4de
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 09:44:37 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/5261eb0a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 2bee12e..4f8d682 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -275,6 +275,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/5261eb0a/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));
+  }
+
+}
+