You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2016/04/23 03:51:38 UTC

[1/8] lucene-solr:branch_5x: SOLR-8838: java8 date handling -> java7

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_5x 5f471fb60 -> 33462956c


SOLR-8838: java8 date handling -> java7


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/33462956
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/33462956
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/33462956

Branch: refs/heads/branch_5x
Commit: 33462956c6e2e1cc1d23afeb947c9688f00ba490
Parents: 496a753
Author: Steve Rowe <sa...@apache.org>
Authored: Wed Mar 16 21:01:13 2016 -0400
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 .../solr/schema/TestUseDocValuesAsStored.java       | 16 +++++-----------
 1 file changed, 5 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33462956/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
index 6352e99..417c10f 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
@@ -25,12 +25,8 @@ import java.io.File;
 
 import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
-import java.time.Instant;
-import java.time.LocalDateTime;
-import java.time.Month;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.regex.Pattern;
@@ -40,6 +36,7 @@ import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.TestUtil;
 import org.apache.solr.core.AbstractBadConfigTestBase;
 import org.apache.solr.util.DOMUtil;
+import org.apache.solr.util.DateFormatUtil;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -71,11 +68,9 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
   private static final Pattern STORED_FIELD_NAME_PATTERN = Pattern.compile("_dv$");
 
   static {
-    START_RANDOM_EPOCH_MILLIS = LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0)
-        .toInstant(ZoneOffset.UTC).toEpochMilli();
-    END_RANDOM_EPOCH_MILLIS = LocalDateTime.of(2030, Month.DECEMBER, 31, 23, 59, 59, 999_000_000)
-        .toInstant(ZoneOffset.UTC).toEpochMilli();
     try {
+      START_RANDOM_EPOCH_MILLIS = DateFormatUtil.parseDate("1970-01-01T00:00:00").getTime();
+      END_RANDOM_EPOCH_MILLIS = DateFormatUtil.parseDate("2030-12-31T23:59:59.999").getTime();
       DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
       InputStream stream = TestUseDocValuesAsStored.class.getResourceAsStream("/solr/collection1/conf/enumsConfig.xml");
       Document doc = builder.parse(new InputSource(IOUtils.getDecodingReader(stream, StandardCharsets.UTF_8)));
@@ -216,8 +211,7 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
         }
         case "date": {
           long epochMillis = TestUtil.nextLong(random(), START_RANDOM_EPOCH_MILLIS, END_RANDOM_EPOCH_MILLIS);
-          LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC);
-          values[i] = dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z';
+          values[i] = DateFormatUtil.formatExternal(new Date(epochMillis));
           break;
         }
         default: throw new Exception("unknown type '" + valueType + "'");


[2/8] lucene-solr:branch_5x: SOLR-8838: Returning non-stored docValues is incorrect for negative floats and doubles.

Posted by an...@apache.org.
SOLR-8838: Returning non-stored docValues is incorrect for negative floats and doubles.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/404a3f99
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/404a3f99
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/404a3f99

Branch: refs/heads/branch_5x
Commit: 404a3f995673d54bc7565dea934332e1cd37d4c3
Parents: db853d4
Author: Steve Rowe <sa...@apache.org>
Authored: Wed Mar 16 18:56:23 2016 -0400
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                                 | 3 +++
 solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java | 4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/404a3f99/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 9b113e1..19b2d59 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -131,6 +131,9 @@ Bug Fixes
 * SOLR-8804: Fix a race condition in the ClusterStatus API call whereby the call would fail when a concurrent delete
   collection api command was executed (Alexey Serba, Varun Thacker)
 
+* SOLR-8838: Returning non-stored docValues is incorrect for negative floats and doubles.
+  (Ishan Chattopadhyaya, Steve Rowe)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/404a3f99/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
index a811f0d..084117b 100644
--- a/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
+++ b/solr/core/src/java/org/apache/solr/search/SolrIndexSearcher.java
@@ -839,9 +839,9 @@ public class SolrIndexSearcher extends IndexSearcher implements Closeable,SolrIn
               if (schemaField.getType() instanceof TrieIntField) {
                 val = ((Long) val).intValue();
               } else if (schemaField.getType() instanceof TrieFloatField) {
-                val = NumericUtils.sortableIntToFloat(((Long) val).intValue());
+                val = Float.intBitsToFloat(((Long)val).intValue());
               } else if (schemaField.getType() instanceof TrieDoubleField) {
-                val = NumericUtils.sortableLongToDouble((long) val);
+                val = Double.longBitsToDouble((long) val);
               } else if (schemaField.getType() instanceof TrieDateField) {
                 val = new Date((long) val);
               } else if (schemaField.getType() instanceof EnumField) {


[8/8] lucene-solr:branch_5x: SOLR-8838: Returning non-stored docValues is incorrect for negative floats and doubles.

Posted by an...@apache.org.
SOLR-8838: Returning non-stored docValues is incorrect for negative floats and doubles.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/db853d49
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/db853d49
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/db853d49

Branch: refs/heads/branch_5x
Commit: db853d4983f3d7b6b55f70f3025444e733d44250
Parents: bf8a2c7
Author: Steve Rowe <sa...@apache.org>
Authored: Wed Mar 16 18:56:23 2016 -0400
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 .../solr/schema/TestUseDocValuesAsStored.java   | 158 +++++++++++++++----
 1 file changed, 123 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/db853d49/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
index 46f76ab..270745c 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
@@ -16,15 +16,36 @@
  */
 package org.apache.solr.schema;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
 import java.io.File;
 
-import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.Month;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.apache.commons.io.FileUtils;
+import org.apache.lucene.util.IOUtils;
+import org.apache.lucene.util.TestUtil;
 import org.apache.solr.core.AbstractBadConfigTestBase;
+import org.apache.solr.util.DOMUtil;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
 
 /**
  * Tests the useDocValuesAsStored functionality.
@@ -38,30 +59,56 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
   
   private static final String collection = "collection1";
   private static final String confDir = collection + "/conf";
-  
+
+  private static final long START_RANDOM_EPOCH_MILLIS;
+  private static final long END_RANDOM_EPOCH_MILLIS;
+  private static final String[] SEVERITY;
+
+  // http://www.w3.org/TR/2006/REC-xml-20060816/#charsets
+  private static final String NON_XML_CHARS = "\u0000-\u0008\u000B-\u000C\u000E-\u001F\uFFFE\uFFFF";
+  // Avoid single quotes (problematic in XPath literals) and carriage returns (XML roundtripping fails)
+  private static final Pattern BAD_CHAR_PATTERN = Pattern.compile("[\'\r" + NON_XML_CHARS + "]");
+  private static final Pattern STORED_FIELD_NAME_PATTERN = Pattern.compile("_dv$");
+
+  static {
+    // Copy of DateTimeFormatter.ISO_INSTANT with fixed 3 digit milliseconds
+    START_RANDOM_EPOCH_MILLIS = LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0)
+        .toInstant(ZoneOffset.UTC).toEpochMilli();
+    END_RANDOM_EPOCH_MILLIS = LocalDateTime.of(2030, Month.DECEMBER, 31, 23, 59, 59, 999_000_000)
+        .toInstant(ZoneOffset.UTC).toEpochMilli();
+    try {
+      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+      InputStream stream = TestUseDocValuesAsStored.class.getResourceAsStream("/solr/collection1/conf/enumsConfig.xml");
+      Document doc = builder.parse(new InputSource(IOUtils.getDecodingReader(stream, StandardCharsets.UTF_8)));
+      XPath xpath = XPathFactory.newInstance().newXPath();
+      NodeList nodes = (NodeList)xpath.evaluate
+          ("/enumsConfig/enum[@name='severity']/value", doc, XPathConstants.NODESET);
+      SEVERITY = new String[nodes.getLength()];
+      for (int i = 0 ; i < nodes.getLength() ; ++i) {
+        SEVERITY[i] = DOMUtil.getText(nodes.item(i));
+      }
+    } catch (Exception e) {
+      throw new RuntimeException(e);
+    }
+  }
+
   @Before
   private void initManagedSchemaCore() throws Exception {
     tmpSolrHome = createTempDir().toFile();
     tmpConfDir = new File(tmpSolrHome, confDir);
     File testHomeConfDir = new File(TEST_HOME(), confDir);
     FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-managed-schema.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig-basic.xml"), tmpConfDir);
     FileUtils.copyFileToDirectory(new File(testHomeConfDir, "solrconfig.snippet.randomindexconfig.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-one-field-no-dynamic-field-unique-key.xml"), tmpConfDir);
     FileUtils.copyFileToDirectory(new File(testHomeConfDir, "enumsConfig.xml"), tmpConfDir);
     FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-non-stored-docvalues.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-minimal.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema_codec.xml"), tmpConfDir);
-    FileUtils.copyFileToDirectory(new File(testHomeConfDir, "schema-bm25.xml"), tmpConfDir);
-    
+
     // initCore will trigger an upgrade to managed schema, since the solrconfig has
     // <schemaFactory class="ManagedIndexSchemaFactory" ... />
     System.setProperty("enable.update.log", "false");
     System.setProperty("managed.schema.mutable", "true");
     initCore("solrconfig-managed-schema.xml", "schema-non-stored-docvalues.xml", tmpSolrHome.getPath());
   }
-  
+
   @After
   private void afterClass() throws Exception {
     deleteCore();
@@ -116,31 +163,68 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
   }
 
   @Test
-  public void testSinglyValued() throws IOException {
-    clearIndex();
-    doTest("check string value is correct", "test_s_dvo", "str", "keyword");
-    doTest("check int value is correct", "test_i_dvo", "int", "1234");
-    doTest("check double value is correct", "test_d_dvo", "double", "1.234");
-    doTest("check long value is correct", "test_l_dvo", "long", "12345");
-    doTest("check float value is correct", "test_f_dvo", "float", "1.234");
-    doTest("check dt value is correct", "test_dt_dvo", "date", "1976-07-04T12:08:56.235Z");
-    doTest("check stored and docValues value is correct", "test_s_dv", "str", "storedAndDocValues");
-    doTest("check non-stored and non-indexed is accessible", "test_s_dvo2", "str", "gotIt");
-    doTest("enumField", "enum_dvo", "str", "Critical");
+  public void testRandomSingleAndMultiValued() throws Exception {
+    for (int c = 0 ; c < 10 * RANDOM_MULTIPLIER ; ++c) {
+      clearIndex();
+      int[] arity = new int[9];
+      for (int a = 0 ; a < arity.length ; ++a) {
+        // Single-valued 50% of the time; other 50%: 2-10 values equally likely
+        arity[a] = random().nextBoolean() ? 1 : TestUtil.nextInt(random(), 2, 10);
+      }
+      doTest("check string value is correct", dvStringFieldName(arity[0], true, false), "str", nextValues(arity[0], "str"));
+      doTest("check int value is correct", "test_i" + plural(arity[1]) + "_dvo", "int", nextValues(arity[1], "int"));
+      doTest("check double value is correct", "test_d" + plural(arity[2]) + "_dvo", "double", nextValues(arity[2], "double"));
+      doTest("check long value is correct", "test_l" + plural(arity[3]) + "_dvo", "long", nextValues(arity[3], "long"));
+      doTest("check float value is correct", "test_f" + plural(arity[4]) + "_dvo", "float", nextValues(arity[4], "float"));
+      doTest("check date value is correct", "test_dt" + plural(arity[5]) + "_dvo", "date", nextValues(arity[5], "date"));
+      doTest("check stored and docValues value is correct", dvStringFieldName(arity[6], true, true), "str", nextValues(arity[6], "str"));
+      doTest("check non-stored and non-indexed is accessible", dvStringFieldName(arity[7], false, false), "str", nextValues(arity[7], "str"));
+      doTest("enumField", "enum" + plural(arity[8]) + "_dvo", "str", nextValues(arity[8], "enum"));
+    }
   }
 
-  @Test
-  public void testMultiValued() throws IOException {
-    clearIndex();
-    doTest("check string value is correct", "test_ss_dvo", "str", "keyword", "keyword2");
-    doTest("check int value is correct", "test_is_dvo", "int", "1234", "12345");
-    doTest("check double value is correct", "test_ds_dvo", "double", "1.234", "12.34", "123.4");
-    doTest("check long value is correct", "test_ls_dvo", "long", "12345", "123456");
-    doTest("check float value is correct", "test_fs_dvo", "float", "1.234", "12.34");
-    doTest("check dt value is correct", "test_dts_dvo", "date", "1976-07-04T12:08:56.235Z", "1978-07-04T12:08:56.235Z");
-    doTest("check stored and docValues value is correct", "test_ss_dv", "str", "storedAndDocValues", "storedAndDocValues2");
-    doTest("check non-stored and non-indexed is accessible", "test_ss_dvo2", "str", "gotIt", "gotIt2");
-    doTest("enumField", "enums_dvo", "str", "High", "Critical");
+  private String plural(int arity) {
+    return arity > 1 ? "s" : "";
+  }
+
+  private static boolean isStoredField(String fieldName) {
+    return STORED_FIELD_NAME_PATTERN.matcher(fieldName).find();
+  }
+
+  private String dvStringFieldName(int arity, boolean indexed, boolean stored) {
+    String base = "test_s" + (arity > 1 ? "s": "");
+    String suffix = "";
+    if (indexed && stored) suffix = "_dv";
+    else if (indexed && ! stored) suffix = "_dvo";
+    else if ( ! indexed && ! stored) suffix = "_dvo2";
+    else assertTrue("unsupported dv string field combination: stored and not indexed", false);
+    return base + suffix;
+  }
+
+  private String[] nextValues(int arity, String valueType) throws Exception {
+    String[] values = new String[arity];
+    for (int i = 0 ; i < arity ; ++i) {
+      switch (valueType) {
+        case "int": values[i] = String.valueOf(random().nextInt()); break;
+        case "double": values[i] = String.valueOf(Double.longBitsToDouble(random().nextLong())); break;
+        case "long": values[i] = String.valueOf(random().nextLong()); break;
+        case "float": values[i] = String.valueOf(Float.intBitsToFloat(random().nextInt())); break;
+        case "enum": values[i] = SEVERITY[TestUtil.nextInt(random(), 0, SEVERITY.length - 1)]; break;
+        case "str": {
+          String str = TestUtil.randomRealisticUnicodeString(random());
+          values[i] = BAD_CHAR_PATTERN.matcher(str).replaceAll("\uFFFD");
+          break;
+        }
+        case "date": {
+          long epochMillis = TestUtil.nextLong(random(), START_RANDOM_EPOCH_MILLIS, END_RANDOM_EPOCH_MILLIS);
+          LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneOffset.UTC);
+          values[i] = dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + 'Z';
+          break;
+        }
+        default: throw new Exception("unknown type '" + valueType + "'");
+      }
+    }
+    return values;
   }
 
   @Test
@@ -198,6 +282,8 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
     String[] xpaths = new String[value.length + 1];
 
     if (value.length > 1) {
+      Set<String> valueSet = new HashSet<>();
+      valueSet.addAll(Arrays.asList(value));
       String[] fieldAndValues = new String[value.length * 2 + 2];
       fieldAndValues[0] = "id";
       fieldAndValues[1] = id;
@@ -205,10 +291,12 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
       for (int i = 0; i < value.length; ++i) {
         fieldAndValues[i * 2 + 2] = field;
         fieldAndValues[i * 2 + 3] = value[i];
-        xpaths[i] = "//arr[@name='" + field + "']/" + type + "[" + (i + 1) + "][.='" + value[i] + "']";
+        xpaths[i] = "//arr[@name='" + field + "']/" + type + "[.='" + value[i] + "']";
       }
 
-      xpaths[value.length] = "*[count(//arr[@name='" + field + "']/" + type + ") = " + value.length + "]";
+      // Docvalues are sets, but stored values are ordered multisets, so cardinality depends on the value source
+      xpaths[value.length] = "*[count(//arr[@name='" + field + "']/" + type + ") = "
+          + (isStoredField(field) ? value.length : valueSet.size()) + "]";
       assertU(adoc(fieldAndValues));
 
     } else {


[7/8] lucene-solr:branch_5x: SOLR-8838: Remove obsolete comment

Posted by an...@apache.org.
SOLR-8838: Remove obsolete comment


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/496a7535
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/496a7535
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/496a7535

Branch: refs/heads/branch_5x
Commit: 496a7535115c13c25fe6c12b7f463477c9426098
Parents: 404a3f9
Author: Steve Rowe <sa...@apache.org>
Authored: Wed Mar 16 18:58:41 2016 -0400
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 .../src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java   | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/496a7535/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
index 270745c..6352e99 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestUseDocValuesAsStored.java
@@ -71,7 +71,6 @@ public class TestUseDocValuesAsStored extends AbstractBadConfigTestBase {
   private static final Pattern STORED_FIELD_NAME_PATTERN = Pattern.compile("_dv$");
 
   static {
-    // Copy of DateTimeFormatter.ISO_INSTANT with fixed 3 digit milliseconds
     START_RANDOM_EPOCH_MILLIS = LocalDateTime.of(1970, Month.JANUARY, 1, 0, 0)
         .toInstant(ZoneOffset.UTC).toEpochMilli();
     END_RANDOM_EPOCH_MILLIS = LocalDateTime.of(2030, Month.DECEMBER, 31, 23, 59, 59, 999_000_000)


[4/8] lucene-solr:branch_5x: SOLR-8789: Remove the *Tests regular expression from the build xml, and instead rename CollectionsAPISolrJTests to CollectionsAPISolrJTest

Posted by an...@apache.org.
SOLR-8789: Remove the *Tests regular expression from the build xml, and instead rename CollectionsAPISolrJTests to CollectionsAPISolrJTest


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/1fb79c94
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/1fb79c94
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/1fb79c94

Branch: refs/heads/branch_5x
Commit: 1fb79c94b182e0fbe4c5f90033cd6d34033c773a
Parents: 87f9901
Author: anshum <an...@apache.org>
Authored: Fri Mar 4 16:34:44 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 lucene/common-build.xml                         |   1 -
 .../solr/cloud/CollectionsAPISolrJTest.java     | 473 +++++++++++++++++++
 .../solr/cloud/CollectionsAPISolrJTests.java    | 473 -------------------
 3 files changed, 473 insertions(+), 474 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1fb79c94/lucene/common-build.xml
----------------------------------------------------------------------
diff --git a/lucene/common-build.xml b/lucene/common-build.xml
index 771d076..9e259e9 100644
--- a/lucene/common-build.xml
+++ b/lucene/common-build.xml
@@ -1226,7 +1226,6 @@
               <fileset dir="@{testsDir}">
                 <include name="**/Test*.class" />
                 <include name="**/*Test.class" />
-                <include name="**/*Tests.class" />
                 <include name="${tests.explicitclass}" if="tests.explicitclass" />
                 <exclude name="**/*$*" />
               </fileset>

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1fb79c94/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
new file mode 100644
index 0000000..d346faa
--- /dev/null
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTest.java
@@ -0,0 +1,473 @@
+/*
+ * 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.cloud;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.codec.binary.StringUtils;
+import org.apache.lucene.util.LuceneTestCase;
+import org.apache.lucene.util.TestUtil;
+import org.apache.solr.client.solrj.SolrServerException;
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
+import org.apache.solr.client.solrj.request.CollectionAdminRequest;
+import org.apache.solr.client.solrj.request.CoreAdminRequest;
+import org.apache.solr.client.solrj.response.CollectionAdminResponse;
+import org.apache.solr.client.solrj.response.CoreAdminResponse;
+import org.apache.solr.common.cloud.ClusterState;
+import org.apache.solr.common.cloud.DocCollection;
+import org.apache.solr.common.cloud.Replica;
+import org.apache.solr.common.cloud.Slice;
+import org.apache.solr.common.cloud.ZkStateReader;
+import org.apache.solr.common.params.CoreAdminParams;
+import org.apache.solr.common.util.NamedList;
+import org.apache.solr.util.TimeOut;
+import org.apache.zookeeper.KeeperException;
+import org.junit.Test;
+
+import static org.apache.solr.cloud.ReplicaPropertiesBase.verifyUniqueAcrossCollection;
+
+@LuceneTestCase.Slow
+public class CollectionsAPISolrJTest extends AbstractFullDistribZkTestBase {
+
+  @Test
+  public void test() throws Exception {
+    testCreateAndDeleteCollection();
+    testCreateAndDeleteShard();
+    testReloadCollection();
+    testCreateAndDeleteAlias();
+    testSplitShard();
+    testCreateCollectionWithPropertyParam();
+    testAddAndDeleteReplica();
+    testClusterProp();
+    testAddAndRemoveRole();
+    testOverseerStatus();
+    testList();
+    testAddAndDeleteReplicaProp();
+    testBalanceShardUnique();
+  }
+
+  protected void testCreateAndDeleteCollection() throws Exception {
+    String collectionName = "solrj_test";
+    CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
+            .setCollectionName(collectionName)
+            .setNumShards(2)
+            .setReplicationFactor(2)
+            .setConfigName("conf1")
+            .setRouterField("myOwnField")
+            .setStateFormat(1);
+
+    CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
+    assertEquals(4, coresStatus.size());
+    for (int i=0; i<4; i++) {
+      NamedList<Integer> status = coresStatus.get(collectionName + "_shard" + (i/2+1) + "_replica" + (i%2+1));
+      assertEquals(0, (int)status.get("status"));
+      assertTrue(status.get("QTime") > 0);
+    }
+
+    cloudClient.setDefaultCollection(collectionName);
+    CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete()
+            .setCollectionName(collectionName);
+    response = deleteCollectionRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String,NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
+    assertNull("Deleted collection " + collectionName + "still exists",
+        cloudClient.getZkStateReader().getClusterState().getCollectionOrNull(collectionName));
+    assertEquals(4, nodesStatus.size());
+    
+    // Test Creating a collection with new stateformat.
+    collectionName = "solrj_newstateformat";
+    createCollectionRequest = new CollectionAdminRequest.Create()
+            .setCollectionName(collectionName)
+            .setNumShards(2)
+            .setConfigName("conf1")
+            .setStateFormat(2);
+
+    response = createCollectionRequest.process(cloudClient);
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+
+    waitForRecoveriesToFinish(collectionName, false);
+    assertTrue("Collection state does not exist",
+        cloudClient.getZkStateReader().getZkClient()
+            .exists(ZkStateReader.getCollectionPath(collectionName), true));
+
+  }
+  
+  protected void testCreateAndDeleteShard() throws IOException, SolrServerException {
+    // Create an implicit collection
+    String collectionName = "solrj_implicit";
+    CollectionAdminResponse response = new CollectionAdminRequest.Create()
+            .setCollectionName(collectionName)
+            .setShards("shardA,shardB")
+            .setConfigName("conf1")
+            .setRouterName("implicit").process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
+    assertEquals(2, coresStatus.size());
+
+    cloudClient.setDefaultCollection(collectionName);
+    // Add a shard to the implicit collection
+    response = new CollectionAdminRequest
+        .CreateShard()
+            .setCollectionName(collectionName)
+            .setShardName("shardC").process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    coresStatus = response.getCollectionCoresStatus();
+    assertEquals(1, coresStatus.size());
+    assertEquals(0, (int) coresStatus.get(collectionName + "_shardC_replica1").get("status"));
+
+    CollectionAdminRequest.DeleteShard deleteShardRequest = new CollectionAdminRequest
+        .DeleteShard()
+            .setCollectionName(collectionName)
+            .setShardName("shardC");
+    response = deleteShardRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
+    assertEquals(1, nodesStatus.size());
+  }
+  
+  protected void testReloadCollection() throws IOException, SolrServerException {
+    cloudClient.setDefaultCollection(DEFAULT_COLLECTION);
+    CollectionAdminRequest.Reload reloadCollectionRequest = new CollectionAdminRequest.Reload()
+            .setCollectionName("collection1");
+    CollectionAdminResponse response = reloadCollectionRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+  }
+  
+  protected void testCreateAndDeleteAlias() throws IOException, SolrServerException {
+    CollectionAdminRequest.CreateAlias createAliasRequest = new CollectionAdminRequest
+        .CreateAlias()
+            .setAliasName("solrj_alias")
+            .setAliasedCollections(DEFAULT_COLLECTION);
+    CollectionAdminResponse response = createAliasRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+
+    CollectionAdminRequest.DeleteAlias deleteAliasRequest = new CollectionAdminRequest.DeleteAlias()
+            .setAliasName("solrj_alias");
+    deleteAliasRequest.process(cloudClient);
+    
+    assertEquals(0, response.getStatus());
+  }
+  
+  protected void testSplitShard() throws Exception {
+    String collectionName = "solrj_test_splitshard";
+    cloudClient.setDefaultCollection(collectionName);
+    
+    CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
+            .setConfigName("conf1")
+            .setNumShards(2)
+            .setCollectionName(collectionName);
+    createCollectionRequest.process(cloudClient);
+    
+    CollectionAdminRequest.SplitShard splitShardRequest = new CollectionAdminRequest.SplitShard()
+            .setCollectionName(collectionName)
+            .setShardName("shard1");
+    CollectionAdminResponse response = splitShardRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
+    assertEquals(0, (int) coresStatus.get(collectionName + "_shard1_0_replica1").get("status"));
+    assertEquals(0, (int) coresStatus.get(collectionName + "_shard1_1_replica1").get("status"));
+
+    waitForRecoveriesToFinish(collectionName, false);
+    waitForThingsToLevelOut(10);
+    
+    // Test splitting using split.key
+    splitShardRequest = new CollectionAdminRequest.SplitShard()
+            .setCollectionName(collectionName)
+            .setSplitKey("b!");
+    response = splitShardRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+
+    waitForRecoveriesToFinish(collectionName, false);
+    waitForThingsToLevelOut(10);
+    
+    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
+    Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
+    assertEquals("ClusterState: "+ clusterState.getActiveSlices(collectionName), 5, slices.size());  
+    
+  }
+
+  private void testCreateCollectionWithPropertyParam() throws Exception {
+    String collectionName = "solrj_test_core_props";
+    
+    File tmpDir = createTempDir("testPropertyParamsForCreate").toFile();
+    File dataDir = new File(tmpDir, "dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
+    File ulogDir = new File(tmpDir, "ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
+
+    Properties properties = new Properties();
+    properties.put(CoreAdminParams.DATA_DIR, dataDir.getAbsolutePath());
+    properties.put(CoreAdminParams.ULOG_DIR, ulogDir.getAbsolutePath());
+
+    CollectionAdminRequest.Create createReq = new CollectionAdminRequest.Create()
+            .setCollectionName(collectionName)
+            .setNumShards(1)
+            .setConfigName("conf1")
+            .setProperties(properties);
+
+    CollectionAdminResponse response = createReq.process(cloudClient);
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
+    assertEquals(1, coresStatus.size());
+
+    DocCollection testCollection = cloudClient.getZkStateReader()
+        .getClusterState().getCollection(collectionName);
+
+    Replica replica1 = testCollection.getReplica("core_node1");
+
+    try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) {
+      CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client);
+      NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
+      String dataDirStr = (String) coreStatus.get("dataDir");
+      assertEquals("Data dir does not match param given in property.dataDir syntax",
+          new File(dataDirStr).getAbsolutePath(), dataDir.getAbsolutePath());
+    }
+
+    CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete();
+    deleteCollectionRequest.setCollectionName(collectionName);
+    deleteCollectionRequest.process(cloudClient);
+  }
+
+  private void testAddAndDeleteReplica() throws Exception {
+    String collectionName = "solrj_replicatests";
+    createCollection(collectionName, cloudClient, 1, 2);
+
+    cloudClient.setDefaultCollection(collectionName);
+
+    String newReplicaName = Assign.assignNode(collectionName, cloudClient.getZkStateReader().getClusterState());
+    ArrayList<String> nodeList = new ArrayList<>(cloudClient.getZkStateReader().getClusterState().getLiveNodes());
+    Collections.shuffle(nodeList, random());
+    CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica()
+            .setCollectionName(collectionName)
+            .setShardName("shard1")
+            .setNode(nodeList.get(0));
+    CollectionAdminResponse response = addReplica.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+    assertTrue(response.isSuccess());
+
+    TimeOut timeout = new TimeOut(3, TimeUnit.SECONDS);
+    Replica newReplica = null;
+
+    while (! timeout.hasTimedOut() && newReplica == null) {
+      Slice slice = cloudClient.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
+      newReplica = slice.getReplica(newReplicaName);
+    }
+
+    assertNotNull(newReplica);
+
+    assertEquals("Replica should be created on the right node",
+        cloudClient.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)),
+        newReplica.getStr(ZkStateReader.BASE_URL_PROP)
+    );
+    
+    // Test DELETEREPLICA
+    CollectionAdminRequest.DeleteReplica deleteReplicaRequest = new CollectionAdminRequest.DeleteReplica()
+            .setCollectionName(collectionName)
+            .setShardName("shard1")
+            .setReplica(newReplicaName);
+    response = deleteReplicaRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+
+    timeout = new TimeOut(3, TimeUnit.SECONDS);
+
+    while (! timeout.hasTimedOut() && newReplica != null) {
+      Slice slice = cloudClient.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
+      newReplica = slice.getReplica(newReplicaName);
+    }
+
+    assertNull(newReplica);
+  }
+
+  private void testClusterProp() throws InterruptedException, IOException, SolrServerException {
+    CollectionAdminRequest.ClusterProp clusterPropRequest = new CollectionAdminRequest.ClusterProp()
+            .setPropertyName(ZkStateReader.LEGACY_CLOUD)
+            .setPropertyValue("false");
+    CollectionAdminResponse response = clusterPropRequest.process(cloudClient);
+
+    assertEquals(0, response.getStatus());
+
+    TimeOut timeout = new TimeOut(3, TimeUnit.SECONDS);
+    boolean changed = false;
+    
+    while(! timeout.hasTimedOut()){
+      Thread.sleep(10);
+      changed = Objects.equals("false",
+          cloudClient.getZkStateReader().getClusterProps().get(ZkStateReader.LEGACY_CLOUD));
+      if(changed) break;
+    }
+    assertTrue("The Cluster property wasn't set", changed);
+    
+    // Unset ClusterProp that we set.
+    clusterPropRequest = new CollectionAdminRequest.ClusterProp()
+            .setPropertyName(ZkStateReader.LEGACY_CLOUD)
+            .setPropertyValue(null);
+    clusterPropRequest.process(cloudClient);
+
+    timeout = new TimeOut(3, TimeUnit.SECONDS);
+    changed = false;
+    while(! timeout.hasTimedOut()) {
+      Thread.sleep(10);
+      changed = (cloudClient.getZkStateReader().getClusterProps().get(ZkStateReader.LEGACY_CLOUD) == null);
+      if(changed)  
+        break;
+    }
+    assertTrue("The Cluster property wasn't unset", changed);
+  }
+
+  private void testAddAndRemoveRole() throws InterruptedException, IOException, SolrServerException {
+    cloudClient.setDefaultCollection(DEFAULT_COLLECTION);
+    Replica replica = cloudClient.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
+    CollectionAdminRequest.AddRole addRoleRequest = new CollectionAdminRequest.AddRole()
+            .setNode(replica.getNodeName())
+            .setRole("overseer");
+    addRoleRequest.process(cloudClient);
+
+    CollectionAdminRequest.ClusterStatus clusterStatusRequest = new CollectionAdminRequest.ClusterStatus()
+            .setCollectionName(DEFAULT_COLLECTION);
+    CollectionAdminResponse response = clusterStatusRequest.process(cloudClient);
+
+    NamedList<Object> rsp = response.getResponse();
+    NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
+    assertNotNull("Cluster state should not be null", cluster);
+    Map<String, Object> roles = (Map<String, Object>) cluster.get("roles");
+    assertNotNull("Role information should not be null", roles);
+    List<String> overseer = (List<String>) roles.get("overseer");
+    assertNotNull(overseer);
+    assertEquals(1, overseer.size());
+    assertTrue(overseer.contains(replica.getNodeName()));
+    
+    // Remove role
+    new CollectionAdminRequest.RemoveRole()
+            .setNode(replica.getNodeName())
+            .setRole("overseer")
+            .process(cloudClient);
+
+    clusterStatusRequest = new CollectionAdminRequest.ClusterStatus();
+    clusterStatusRequest.setCollectionName(DEFAULT_COLLECTION);
+    response = clusterStatusRequest.process(cloudClient);
+
+    rsp = response.getResponse();
+    cluster = (NamedList<Object>) rsp.get("cluster");
+    assertNotNull("Cluster state should not be null", cluster);
+    roles = (Map<String, Object>) cluster.get("roles");
+    assertNotNull("Role information should not be null", roles);
+    overseer = (List<String>) roles.get("overseer");
+    assertFalse(overseer.contains(replica.getNodeName()));
+  }
+  
+  private void testOverseerStatus() throws IOException, SolrServerException {
+    CollectionAdminResponse response = new CollectionAdminRequest.OverseerStatus().process(cloudClient);
+    assertEquals(0, response.getStatus());
+    assertNotNull("overseer_operations shouldn't be null", response.getResponse().get("overseer_operations"));
+  }
+  
+  private void testList() throws IOException, SolrServerException {
+    CollectionAdminResponse response = new CollectionAdminRequest.List().process(cloudClient);
+    assertEquals(0, response.getStatus());
+    assertNotNull("collection list should not be null", response.getResponse().get("collections"));
+  }
+  
+  private void testAddAndDeleteReplicaProp() throws InterruptedException, IOException, SolrServerException {
+    Replica replica = cloudClient.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
+    CollectionAdminResponse response = new CollectionAdminRequest.AddReplicaProp()
+            .setCollectionName(DEFAULT_COLLECTION)
+            .setShardName(SHARD1)
+            .setReplica(replica.getName())
+            .setPropertyName("preferredleader")
+            .setPropertyValue("true").process(cloudClient);
+    assertEquals(0, response.getStatus());
+
+    TimeOut timeout = new TimeOut(20, TimeUnit.SECONDS);
+    String propertyValue = null;
+    
+    String replicaName = replica.getName();
+    while (! timeout.hasTimedOut()) {
+      ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
+      replica = clusterState.getReplica(DEFAULT_COLLECTION, replicaName);
+      propertyValue = replica.getStr("property.preferredleader"); 
+      if(StringUtils.equals("true", propertyValue))
+        break;
+      Thread.sleep(50);
+    }
+    
+    assertEquals("Replica property was not updated, Latest value: " +
+        cloudClient.getZkStateReader().getClusterState().getReplica(DEFAULT_COLLECTION, replicaName),
+        "true",
+        propertyValue);
+
+    response = new CollectionAdminRequest.DeleteReplicaProp()
+            .setCollectionName(DEFAULT_COLLECTION)
+            .setShardName(SHARD1)
+            .setReplica(replicaName)
+            .setPropertyName("property.preferredleader").process(cloudClient);
+    assertEquals(0, response.getStatus());
+
+    timeout = new TimeOut(20, TimeUnit.SECONDS);
+    boolean updated = false;
+
+    while (! timeout.hasTimedOut()) {
+      ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
+      replica = clusterState.getReplica(DEFAULT_COLLECTION, replicaName);
+      updated = replica.getStr("property.preferredleader") == null;
+      if(updated)
+        break;
+      Thread.sleep(50);
+    }
+
+    assertTrue("Replica property was not removed", updated);
+    
+  }
+  
+  private void testBalanceShardUnique() throws IOException,
+      SolrServerException, KeeperException, InterruptedException {
+    CollectionAdminResponse response = new CollectionAdminRequest.BalanceShardUnique()
+            .setCollection(DEFAULT_COLLECTION)
+            .setPropertyName("preferredLeader").process(cloudClient);
+    assertEquals(0, response.getStatus());
+
+    verifyUniqueAcrossCollection(cloudClient, DEFAULT_COLLECTION, "property.preferredleader");    
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1fb79c94/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
deleted file mode 100644
index 55c45f0..0000000
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * 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.cloud;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.codec.binary.StringUtils;
-import org.apache.lucene.util.LuceneTestCase;
-import org.apache.lucene.util.TestUtil;
-import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.HttpSolrClient;
-import org.apache.solr.client.solrj.request.CollectionAdminRequest;
-import org.apache.solr.client.solrj.request.CoreAdminRequest;
-import org.apache.solr.client.solrj.response.CollectionAdminResponse;
-import org.apache.solr.client.solrj.response.CoreAdminResponse;
-import org.apache.solr.common.cloud.ClusterState;
-import org.apache.solr.common.cloud.DocCollection;
-import org.apache.solr.common.cloud.Replica;
-import org.apache.solr.common.cloud.Slice;
-import org.apache.solr.common.cloud.ZkStateReader;
-import org.apache.solr.common.params.CoreAdminParams;
-import org.apache.solr.common.util.NamedList;
-import org.apache.solr.util.TimeOut;
-import org.apache.zookeeper.KeeperException;
-import org.junit.Test;
-
-import static org.apache.solr.cloud.ReplicaPropertiesBase.verifyUniqueAcrossCollection;
-
-@LuceneTestCase.Slow
-public class CollectionsAPISolrJTests extends AbstractFullDistribZkTestBase {
-
-  @Test
-  public void test() throws Exception {
-    testCreateAndDeleteCollection();
-    testCreateAndDeleteShard();
-    testReloadCollection();
-    testCreateAndDeleteAlias();
-    testSplitShard();
-    testCreateCollectionWithPropertyParam();
-    testAddAndDeleteReplica();
-    testClusterProp();
-    testAddAndRemoveRole();
-    testOverseerStatus();
-    testList();
-    testAddAndDeleteReplicaProp();
-    testBalanceShardUnique();
-  }
-
-  protected void testCreateAndDeleteCollection() throws Exception {
-    String collectionName = "solrj_test";
-    CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
-            .setCollectionName(collectionName)
-            .setNumShards(2)
-            .setReplicationFactor(2)
-            .setConfigName("conf1")
-            .setRouterField("myOwnField")
-            .setStateFormat(1);
-
-    CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
-    assertEquals(4, coresStatus.size());
-    for (int i=0; i<4; i++) {
-      NamedList<Integer> status = coresStatus.get(collectionName + "_shard" + (i/2+1) + "_replica" + (i%2+1));
-      assertEquals(0, (int)status.get("status"));
-      assertTrue(status.get("QTime") > 0);
-    }
-
-    cloudClient.setDefaultCollection(collectionName);
-    CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete()
-            .setCollectionName(collectionName);
-    response = deleteCollectionRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String,NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
-    assertNull("Deleted collection " + collectionName + "still exists",
-        cloudClient.getZkStateReader().getClusterState().getCollectionOrNull(collectionName));
-    assertEquals(4, nodesStatus.size());
-    
-    // Test Creating a collection with new stateformat.
-    collectionName = "solrj_newstateformat";
-    createCollectionRequest = new CollectionAdminRequest.Create()
-            .setCollectionName(collectionName)
-            .setNumShards(2)
-            .setConfigName("conf1")
-            .setStateFormat(2);
-
-    response = createCollectionRequest.process(cloudClient);
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-
-    waitForRecoveriesToFinish(collectionName, false);
-    assertTrue("Collection state does not exist",
-        cloudClient.getZkStateReader().getZkClient()
-            .exists(ZkStateReader.getCollectionPath(collectionName), true));
-
-  }
-  
-  protected void testCreateAndDeleteShard() throws IOException, SolrServerException {
-    // Create an implicit collection
-    String collectionName = "solrj_implicit";
-    CollectionAdminResponse response = new CollectionAdminRequest.Create()
-            .setCollectionName(collectionName)
-            .setShards("shardA,shardB")
-            .setConfigName("conf1")
-            .setRouterName("implicit").process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
-    assertEquals(2, coresStatus.size());
-
-    cloudClient.setDefaultCollection(collectionName);
-    // Add a shard to the implicit collection
-    response = new CollectionAdminRequest
-        .CreateShard()
-            .setCollectionName(collectionName)
-            .setShardName("shardC").process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    coresStatus = response.getCollectionCoresStatus();
-    assertEquals(1, coresStatus.size());
-    assertEquals(0, (int) coresStatus.get(collectionName + "_shardC_replica1").get("status"));
-
-    CollectionAdminRequest.DeleteShard deleteShardRequest = new CollectionAdminRequest
-        .DeleteShard()
-            .setCollectionName(collectionName)
-            .setShardName("shardC");
-    response = deleteShardRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String, NamedList<Integer>> nodesStatus = response.getCollectionNodesStatus();
-    assertEquals(1, nodesStatus.size());
-  }
-  
-  protected void testReloadCollection() throws IOException, SolrServerException {
-    cloudClient.setDefaultCollection(DEFAULT_COLLECTION);
-    CollectionAdminRequest.Reload reloadCollectionRequest = new CollectionAdminRequest.Reload()
-            .setCollectionName("collection1");
-    CollectionAdminResponse response = reloadCollectionRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-  }
-  
-  protected void testCreateAndDeleteAlias() throws IOException, SolrServerException {
-    CollectionAdminRequest.CreateAlias createAliasRequest = new CollectionAdminRequest
-        .CreateAlias()
-            .setAliasName("solrj_alias")
-            .setAliasedCollections(DEFAULT_COLLECTION);
-    CollectionAdminResponse response = createAliasRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-
-    CollectionAdminRequest.DeleteAlias deleteAliasRequest = new CollectionAdminRequest.DeleteAlias()
-            .setAliasName("solrj_alias");
-    deleteAliasRequest.process(cloudClient);
-    
-    assertEquals(0, response.getStatus());
-  }
-  
-  protected void testSplitShard() throws Exception {
-    String collectionName = "solrj_test_splitshard";
-    cloudClient.setDefaultCollection(collectionName);
-    
-    CollectionAdminRequest.Create createCollectionRequest = new CollectionAdminRequest.Create()
-            .setConfigName("conf1")
-            .setNumShards(2)
-            .setCollectionName(collectionName);
-    createCollectionRequest.process(cloudClient);
-    
-    CollectionAdminRequest.SplitShard splitShardRequest = new CollectionAdminRequest.SplitShard()
-            .setCollectionName(collectionName)
-            .setShardName("shard1");
-    CollectionAdminResponse response = splitShardRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
-    assertEquals(0, (int) coresStatus.get(collectionName + "_shard1_0_replica1").get("status"));
-    assertEquals(0, (int) coresStatus.get(collectionName + "_shard1_1_replica1").get("status"));
-
-    waitForRecoveriesToFinish(collectionName, false);
-    waitForThingsToLevelOut(10);
-    
-    // Test splitting using split.key
-    splitShardRequest = new CollectionAdminRequest.SplitShard()
-            .setCollectionName(collectionName)
-            .setSplitKey("b!");
-    response = splitShardRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-
-    waitForRecoveriesToFinish(collectionName, false);
-    waitForThingsToLevelOut(10);
-    
-    ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
-    Collection<Slice> slices = clusterState.getActiveSlices(collectionName);
-    assertEquals("ClusterState: "+ clusterState.getActiveSlices(collectionName), 5, slices.size());  
-    
-  }
-
-  private void testCreateCollectionWithPropertyParam() throws Exception {
-    String collectionName = "solrj_test_core_props";
-    
-    File tmpDir = createTempDir("testPropertyParamsForCreate").toFile();
-    File dataDir = new File(tmpDir, "dataDir-" + TestUtil.randomSimpleString(random(), 1, 5));
-    File ulogDir = new File(tmpDir, "ulogDir-" + TestUtil.randomSimpleString(random(), 1, 5));
-
-    Properties properties = new Properties();
-    properties.put(CoreAdminParams.DATA_DIR, dataDir.getAbsolutePath());
-    properties.put(CoreAdminParams.ULOG_DIR, ulogDir.getAbsolutePath());
-
-    CollectionAdminRequest.Create createReq = new CollectionAdminRequest.Create()
-            .setCollectionName(collectionName)
-            .setNumShards(1)
-            .setConfigName("conf1")
-            .setProperties(properties);
-
-    CollectionAdminResponse response = createReq.process(cloudClient);
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-    Map<String, NamedList<Integer>> coresStatus = response.getCollectionCoresStatus();
-    assertEquals(1, coresStatus.size());
-
-    DocCollection testCollection = cloudClient.getZkStateReader()
-        .getClusterState().getCollection(collectionName);
-
-    Replica replica1 = testCollection.getReplica("core_node1");
-
-    try (HttpSolrClient client = new HttpSolrClient(replica1.getStr("base_url"))) {
-      CoreAdminResponse status = CoreAdminRequest.getStatus(replica1.getStr("core"), client);
-      NamedList<Object> coreStatus = status.getCoreStatus(replica1.getStr("core"));
-      String dataDirStr = (String) coreStatus.get("dataDir");
-      assertEquals("Data dir does not match param given in property.dataDir syntax",
-          new File(dataDirStr).getAbsolutePath(), dataDir.getAbsolutePath());
-    }
-
-    CollectionAdminRequest.Delete deleteCollectionRequest = new CollectionAdminRequest.Delete();
-    deleteCollectionRequest.setCollectionName(collectionName);
-    deleteCollectionRequest.process(cloudClient);
-  }
-
-  private void testAddAndDeleteReplica() throws Exception {
-    String collectionName = "solrj_replicatests";
-    createCollection(collectionName, cloudClient, 1, 2);
-
-    cloudClient.setDefaultCollection(collectionName);
-
-    String newReplicaName = Assign.assignNode(collectionName, cloudClient.getZkStateReader().getClusterState());
-    ArrayList<String> nodeList = new ArrayList<>(cloudClient.getZkStateReader().getClusterState().getLiveNodes());
-    Collections.shuffle(nodeList, random());
-    CollectionAdminRequest.AddReplica addReplica = new CollectionAdminRequest.AddReplica()
-            .setCollectionName(collectionName)
-            .setShardName("shard1")
-            .setNode(nodeList.get(0));
-    CollectionAdminResponse response = addReplica.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-    assertTrue(response.isSuccess());
-
-    TimeOut timeout = new TimeOut(3, TimeUnit.SECONDS);
-    Replica newReplica = null;
-
-    while (! timeout.hasTimedOut() && newReplica == null) {
-      Slice slice = cloudClient.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
-      newReplica = slice.getReplica(newReplicaName);
-    }
-
-    assertNotNull(newReplica);
-
-    assertEquals("Replica should be created on the right node",
-        cloudClient.getZkStateReader().getBaseUrlForNodeName(nodeList.get(0)),
-        newReplica.getStr(ZkStateReader.BASE_URL_PROP)
-    );
-    
-    // Test DELETEREPLICA
-    CollectionAdminRequest.DeleteReplica deleteReplicaRequest = new CollectionAdminRequest.DeleteReplica()
-            .setCollectionName(collectionName)
-            .setShardName("shard1")
-            .setReplica(newReplicaName);
-    response = deleteReplicaRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-
-    timeout = new TimeOut(3, TimeUnit.SECONDS);
-
-    while (! timeout.hasTimedOut() && newReplica != null) {
-      Slice slice = cloudClient.getZkStateReader().getClusterState().getSlice(collectionName, "shard1");
-      newReplica = slice.getReplica(newReplicaName);
-    }
-
-    assertNull(newReplica);
-  }
-
-  private void testClusterProp() throws InterruptedException, IOException, SolrServerException {
-    CollectionAdminRequest.ClusterProp clusterPropRequest = new CollectionAdminRequest.ClusterProp()
-            .setPropertyName(ZkStateReader.LEGACY_CLOUD)
-            .setPropertyValue("false");
-    CollectionAdminResponse response = clusterPropRequest.process(cloudClient);
-
-    assertEquals(0, response.getStatus());
-
-    TimeOut timeout = new TimeOut(3, TimeUnit.SECONDS);
-    boolean changed = false;
-    
-    while(! timeout.hasTimedOut()){
-      Thread.sleep(10);
-      changed = Objects.equals("false",
-          cloudClient.getZkStateReader().getClusterProps().get(ZkStateReader.LEGACY_CLOUD));
-      if(changed) break;
-    }
-    assertTrue("The Cluster property wasn't set", changed);
-    
-    // Unset ClusterProp that we set.
-    clusterPropRequest = new CollectionAdminRequest.ClusterProp()
-            .setPropertyName(ZkStateReader.LEGACY_CLOUD)
-            .setPropertyValue(null);
-    clusterPropRequest.process(cloudClient);
-
-    timeout = new TimeOut(3, TimeUnit.SECONDS);
-    changed = false;
-    while(! timeout.hasTimedOut()) {
-      Thread.sleep(10);
-      changed = (cloudClient.getZkStateReader().getClusterProps().get(ZkStateReader.LEGACY_CLOUD) == null);
-      if(changed)  
-        break;
-    }
-    assertTrue("The Cluster property wasn't unset", changed);
-  }
-
-  private void testAddAndRemoveRole() throws InterruptedException, IOException, SolrServerException {
-    cloudClient.setDefaultCollection(DEFAULT_COLLECTION);
-    Replica replica = cloudClient.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
-    CollectionAdminRequest.AddRole addRoleRequest = new CollectionAdminRequest.AddRole()
-            .setNode(replica.getNodeName())
-            .setRole("overseer");
-    addRoleRequest.process(cloudClient);
-
-    CollectionAdminRequest.ClusterStatus clusterStatusRequest = new CollectionAdminRequest.ClusterStatus()
-            .setCollectionName(DEFAULT_COLLECTION);
-    CollectionAdminResponse response = clusterStatusRequest.process(cloudClient);
-
-    NamedList<Object> rsp = response.getResponse();
-    NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
-    assertNotNull("Cluster state should not be null", cluster);
-    Map<String, Object> roles = (Map<String, Object>) cluster.get("roles");
-    assertNotNull("Role information should not be null", roles);
-    List<String> overseer = (List<String>) roles.get("overseer");
-    assertNotNull(overseer);
-    assertEquals(1, overseer.size());
-    assertTrue(overseer.contains(replica.getNodeName()));
-    
-    // Remove role
-    new CollectionAdminRequest.RemoveRole()
-            .setNode(replica.getNodeName())
-            .setRole("overseer")
-            .process(cloudClient);
-
-    clusterStatusRequest = new CollectionAdminRequest.ClusterStatus();
-    clusterStatusRequest.setCollectionName(DEFAULT_COLLECTION);
-    response = clusterStatusRequest.process(cloudClient);
-
-    rsp = response.getResponse();
-    cluster = (NamedList<Object>) rsp.get("cluster");
-    assertNotNull("Cluster state should not be null", cluster);
-    roles = (Map<String, Object>) cluster.get("roles");
-    assertNotNull("Role information should not be null", roles);
-    overseer = (List<String>) roles.get("overseer");
-    assertFalse(overseer.contains(replica.getNodeName()));
-  }
-  
-  private void testOverseerStatus() throws IOException, SolrServerException {
-    CollectionAdminResponse response = new CollectionAdminRequest.OverseerStatus().process(cloudClient);
-    assertEquals(0, response.getStatus());
-    assertNotNull("overseer_operations shouldn't be null", response.getResponse().get("overseer_operations"));
-  }
-  
-  private void testList() throws IOException, SolrServerException {
-    CollectionAdminResponse response = new CollectionAdminRequest.List().process(cloudClient);
-    assertEquals(0, response.getStatus());
-    assertNotNull("collection list should not be null", response.getResponse().get("collections"));
-  }
-  
-  private void testAddAndDeleteReplicaProp() throws InterruptedException, IOException, SolrServerException {
-    Replica replica = cloudClient.getZkStateReader().getLeaderRetry(DEFAULT_COLLECTION, SHARD1);
-    CollectionAdminResponse response = new CollectionAdminRequest.AddReplicaProp()
-            .setCollectionName(DEFAULT_COLLECTION)
-            .setShardName(SHARD1)
-            .setReplica(replica.getName())
-            .setPropertyName("preferredleader")
-            .setPropertyValue("true").process(cloudClient);
-    assertEquals(0, response.getStatus());
-
-    TimeOut timeout = new TimeOut(20, TimeUnit.SECONDS);
-    String propertyValue = null;
-    
-    String replicaName = replica.getName();
-    while (! timeout.hasTimedOut()) {
-      ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
-      replica = clusterState.getReplica(DEFAULT_COLLECTION, replicaName);
-      propertyValue = replica.getStr("property.preferredleader"); 
-      if(StringUtils.equals("true", propertyValue))
-        break;
-      Thread.sleep(50);
-    }
-    
-    assertEquals("Replica property was not updated, Latest value: " +
-        cloudClient.getZkStateReader().getClusterState().getReplica(DEFAULT_COLLECTION, replicaName),
-        "true",
-        propertyValue);
-
-    response = new CollectionAdminRequest.DeleteReplicaProp()
-            .setCollectionName(DEFAULT_COLLECTION)
-            .setShardName(SHARD1)
-            .setReplica(replicaName)
-            .setPropertyName("property.preferredleader").process(cloudClient);
-    assertEquals(0, response.getStatus());
-
-    timeout = new TimeOut(20, TimeUnit.SECONDS);
-    boolean updated = false;
-
-    while (! timeout.hasTimedOut()) {
-      ClusterState clusterState = cloudClient.getZkStateReader().getClusterState();
-      replica = clusterState.getReplica(DEFAULT_COLLECTION, replicaName);
-      updated = replica.getStr("property.preferredleader") == null;
-      if(updated)
-        break;
-      Thread.sleep(50);
-    }
-
-    assertTrue("Replica property was not removed", updated);
-    
-  }
-  
-  private void testBalanceShardUnique() throws IOException,
-      SolrServerException, KeeperException, InterruptedException {
-    CollectionAdminResponse response = new CollectionAdminRequest.BalanceShardUnique()
-            .setCollection(DEFAULT_COLLECTION)
-            .setPropertyName("preferredLeader").process(cloudClient);
-    assertEquals(0, response.getStatus());
-
-    verifyUniqueAcrossCollection(cloudClient, DEFAULT_COLLECTION, "property.preferredleader");    
-  }
-}


[6/8] lucene-solr:branch_5x: SOLR-8804: Fix a race condition in the ClusterStatus API call

Posted by an...@apache.org.
SOLR-8804: Fix a race condition in the ClusterStatus API call


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/bf8a2c7c
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/bf8a2c7c
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/bf8a2c7c

Branch: refs/heads/branch_5x
Commit: bf8a2c7caa2350e4764a0791cbee0c6764995e76
Parents: 1fb79c9
Author: Varun Thacker <va...@gmail.com>
Authored: Fri Mar 11 14:01:01 2016 +0530
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                 |  3 +++
 .../apache/solr/handler/admin/ClusterStatus.java | 16 ++++++++++++----
 .../org/apache/solr/cloud/TestCollectionAPI.java | 19 +++++++++++++++++++
 3 files changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bf8a2c7c/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index e2ca3a7..9b113e1 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -128,6 +128,9 @@ Bug Fixes
 * SOLR-8790: Collections API responses contain node name in the core-level responses that are
   returned. (Anshum Gupta)
 
+* SOLR-8804: Fix a race condition in the ClusterStatus API call whereby the call would fail when a concurrent delete
+  collection api command was executed (Alexey Serba, Varun Thacker)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bf8a2c7c/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
index 667d9fa..5248159 100644
--- a/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
+++ b/solr/core/src/java/org/apache/solr/handler/admin/ClusterStatus.java
@@ -92,7 +92,7 @@ public class ClusterStatus {
     byte[] bytes = Utils.toJSON(clusterState);
     Map<String, Object> stateMap = (Map<String,Object>) Utils.fromJSON(bytes);
 
-    Set<String> collections = new HashSet<>();
+    Set<String> collections;
     String routeKey = message.getStr(ShardParams._ROUTE_);
     String shard = message.getStr(ZkStateReader.SHARD_ID_PROP);
     if (collection == null) {
@@ -101,11 +101,19 @@ public class ClusterStatus {
       collections = Collections.singleton(collection);
     }
 
-    NamedList<Object> collectionProps = new SimpleOrderedMap<Object>();
+    NamedList<Object> collectionProps = new SimpleOrderedMap<>();
 
     for (String name : collections) {
-      Map<String, Object> collectionStatus = null;
-      DocCollection clusterStateCollection = clusterState.getCollection(name);
+      Map<String, Object> collectionStatus;
+      DocCollection clusterStateCollection = clusterState.getCollectionOrNull(name);
+      if (clusterStateCollection == null) {
+        if (collection != null) {
+          throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Collection: " + name + " not found");
+        } else {
+          //collection might have got deleted at the same time
+          continue;
+        }
+      }
 
       Set<String> requestedShards = new HashSet<>();
       if (routeKey != null) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/bf8a2c7c/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
index 353c708..304890c 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestCollectionAPI.java
@@ -77,6 +77,7 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
     clusterStatusWithRouteKey();
     clusterStatusAliasTest();
     clusterStatusRolesTest();
+    clusterStatusBadCollectionTest();
     replicaPropTest();
     clusterStatusZNodeVersion();
     testClusterStateMigration();
@@ -318,6 +319,24 @@ public class TestCollectionAPI extends ReplicaPropertiesBase {
     }
   }
 
+  private void clusterStatusBadCollectionTest() throws Exception {
+    try (CloudSolrClient client = createCloudClient(null)) {
+      ModifiableSolrParams params = new ModifiableSolrParams();
+      params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
+      params.set("collection", "bad_collection_name");
+      SolrRequest request = new QueryRequest(params);
+      request.setPath("/admin/collections");
+
+      try {
+        client.request(request);
+        fail("Collection does not exist. An exception should be thrown");
+      } catch (SolrException e) {
+        //expected
+        assertTrue(e.getMessage().contains("Collection: bad_collection_name not found"));
+      }
+    }
+  }
+
   private void replicaPropTest() throws Exception {
     try (CloudSolrClient client = createCloudClient(null)) {
       client.connect();


[5/8] lucene-solr:branch_5x: SOLR-8790: Add the node name to core responses in calls from the Overseer

Posted by an...@apache.org.
SOLR-8790: Add the node name to core responses in calls from the Overseer


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/cbb29d2a
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/cbb29d2a
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/cbb29d2a

Branch: refs/heads/branch_5x
Commit: cbb29d2a5ae4ab8741aab6c9f0806d4236c0cad0
Parents: 5f471fb
Author: anshum <an...@apache.org>
Authored: Thu Mar 10 12:22:23 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 solr/CHANGES.txt                                                  | 3 +++
 .../org/apache/solr/cloud/OverseerCollectionMessageHandler.java   | 1 +
 .../src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java  | 1 +
 3 files changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cbb29d2a/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 37558c2..e2ca3a7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -125,6 +125,9 @@ Bug Fixes
 * SOLR-8449: Fix the core restore functionality to allow restoring multiple times on the same core
   (Johannes Brucher, Varun Thacker)
 
+* SOLR-8790: Collections API responses contain node name in the core-level responses that are
+  returned. (Anshum Gupta)
+
 Other Changes
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cbb29d2a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java
index 7adf25f..10c2bb6 100644
--- a/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java
+++ b/solr/core/src/java/org/apache/solr/cloud/OverseerCollectionMessageHandler.java
@@ -1847,6 +1847,7 @@ public class OverseerCollectionMessageHandler implements OverseerMessageHandler
     String replica = zkStateReader.getBaseUrlForNodeName(nodeName);
     sreq.shards = new String[]{replica};
     sreq.actualShards = sreq.shards;
+    sreq.nodeName = nodeName;
     sreq.params = params;
 
     shardHandler.submit(sreq, replica, sreq.params);

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/cbb29d2a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
----------------------------------------------------------------------
diff --git a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
index 557d878..55c45f0 100644
--- a/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
+++ b/solr/core/src/test/org/apache/solr/cloud/CollectionsAPISolrJTests.java
@@ -78,6 +78,7 @@ public class CollectionsAPISolrJTests extends AbstractFullDistribZkTestBase {
             .setConfigName("conf1")
             .setRouterField("myOwnField")
             .setStateFormat(1);
+
     CollectionAdminResponse response = createCollectionRequest.process(cloudClient);
 
     assertEquals(0, response.getStatus());


[3/8] lucene-solr:branch_5x: SOLR-8789: Fix common-build.xml to run tests in classes that end in *Tests.java

Posted by an...@apache.org.
SOLR-8789: Fix common-build.xml to run tests in classes that end in *Tests.java


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/87f99019
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/87f99019
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/87f99019

Branch: refs/heads/branch_5x
Commit: 87f99019acd8a82756ee930a1b088f9a514e0f75
Parents: cbb29d2
Author: anshum <an...@apache.org>
Authored: Fri Mar 4 16:23:29 2016 -0800
Committer: anshum <an...@apache.org>
Committed: Fri Apr 22 18:50:49 2016 -0700

----------------------------------------------------------------------
 lucene/common-build.xml | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/87f99019/lucene/common-build.xml
----------------------------------------------------------------------
diff --git a/lucene/common-build.xml b/lucene/common-build.xml
index 9e259e9..771d076 100644
--- a/lucene/common-build.xml
+++ b/lucene/common-build.xml
@@ -1226,6 +1226,7 @@
               <fileset dir="@{testsDir}">
                 <include name="**/Test*.class" />
                 <include name="**/*Test.class" />
+                <include name="**/*Tests.class" />
                 <include name="${tests.explicitclass}" if="tests.explicitclass" />
                 <exclude name="**/*$*" />
               </fileset>