You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by cp...@apache.org on 2022/07/29 14:47:47 UTC
[solr] branch branch_9x updated: SOLR-16217: SortingMergePolicy: test coverage for dual-field sort (#883)
This is an automated email from the ASF dual-hosted git repository.
cpoerschke pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 1d9abb1aea1 SOLR-16217: SortingMergePolicy: test coverage for dual-field sort (#883)
1d9abb1aea1 is described below
commit 1d9abb1aea11fe25667550df7d9ae687ae0c540f
Author: Christine Poerschke <cp...@apache.org>
AuthorDate: Fri Jul 29 15:42:48 2022 +0100
SOLR-16217: SortingMergePolicy: test coverage for dual-field sort (#883)
(cherry picked from commit 56a4f6a288f47a62278da9e727265659efefdce8)
---
.../conf/solrconfig-sortingmergepolicyfactory.xml | 2 +-
.../solr/cloud/SegmentTerminateEarlyTestState.java | 20 +++++++-----
.../org/apache/solr/cloud/TestSegmentSorting.java | 36 +++++++++++++++++++---
.../apache/solr/update/SolrIndexConfigTest.java | 21 ++++++++++---
4 files changed, 61 insertions(+), 18 deletions(-)
diff --git a/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingmergepolicyfactory.xml b/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingmergepolicyfactory.xml
index 17e6f4c7a56..5920348551a 100644
--- a/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingmergepolicyfactory.xml
+++ b/solr/core/src/test-files/solr/collection1/conf/solrconfig-sortingmergepolicyfactory.xml
@@ -26,7 +26,7 @@
<mergePolicyFactory class="org.apache.solr.index.SortingMergePolicyFactory">
<str name="wrapped.prefix">in</str>
<str name="in.class">org.apache.solr.util.RandomForceMergePolicyFactory</str>
- <str name="sort">timestamp_i_dvo desc</str>
+ <str name="sort">${mergePolicySort:timestamp_i_dvo desc}</str>
</mergePolicyFactory>
<lockType>${solr.tests.lockType:single}</lockType>
</indexConfig>
diff --git a/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java b/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
index e5c93141aa6..0a0e659963d 100644
--- a/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
+++ b/solr/core/src/test/org/apache/solr/cloud/SegmentTerminateEarlyTestState.java
@@ -129,13 +129,14 @@ class SegmentTerminateEarlyTestState {
.get(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY));
}
- void queryTimestampDescendingSegmentTerminateEarlyYes(CloudSolrClient cloudSolrClient)
- throws Exception {
+ void queryTimestampDescendingSegmentTerminateEarlyYes(
+ CloudSolrClient cloudSolrClient, boolean appendKeyDescendingToSort) throws Exception {
TestSegmentSorting.assertFalse(maxTimestampDocKeys.isEmpty());
TestSegmentSorting.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
final Long oddFieldValue = (long) (maxTimestampDocKeys.iterator().next() % 2);
final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.desc);
+ if (appendKeyDescendingToSort) query.addSort(KEY_FIELD, SolrQuery.ORDER.desc);
query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
final int rowsWanted = 1;
query.setRows(rowsWanted);
@@ -198,13 +199,14 @@ class SegmentTerminateEarlyTestState {
}
}
- void queryTimestampDescendingSegmentTerminateEarlyNo(CloudSolrClient cloudSolrClient)
- throws Exception {
+ void queryTimestampDescendingSegmentTerminateEarlyNo(
+ CloudSolrClient cloudSolrClient, boolean appendKeyDescendingToSort) throws Exception {
TestSegmentSorting.assertFalse(maxTimestampDocKeys.isEmpty());
TestSegmentSorting.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
final Long oddFieldValue = (long) (maxTimestampDocKeys.iterator().next() % 2);
final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.desc);
+ if (appendKeyDescendingToSort) query.addSort(KEY_FIELD, SolrQuery.ORDER.desc);
query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
query.setRows(1);
final Boolean shardsInfoWanted = (rand.nextBoolean() ? null : rand.nextBoolean());
@@ -263,13 +265,14 @@ class SegmentTerminateEarlyTestState {
}
}
- void queryTimestampDescendingSegmentTerminateEarlyYesGrouped(CloudSolrClient cloudSolrClient)
- throws Exception {
+ void queryTimestampDescendingSegmentTerminateEarlyYesGrouped(
+ CloudSolrClient cloudSolrClient, boolean appendKeyDescendingToSort) throws Exception {
TestSegmentSorting.assertFalse(maxTimestampDocKeys.isEmpty());
TestSegmentSorting.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
final Long oddFieldValue = (long) (maxTimestampDocKeys.iterator().next() % 2);
final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.desc);
+ if (appendKeyDescendingToSort) query.addSort(KEY_FIELD, SolrQuery.ORDER.desc);
query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
query.setRows(1);
query.set(CommonParams.SEGMENT_TERMINATE_EARLY, true);
@@ -307,14 +310,15 @@ class SegmentTerminateEarlyTestState {
.get(SolrQueryResponse.RESPONSE_HEADER_SEGMENT_TERMINATED_EARLY_KEY)));
}
- void queryTimestampAscendingSegmentTerminateEarlyYes(CloudSolrClient cloudSolrClient)
- throws Exception {
+ void queryTimestampAscendingSegmentTerminateEarlyYes(
+ CloudSolrClient cloudSolrClient, boolean appendKeyDescendingToSort) throws Exception {
TestSegmentSorting.assertFalse(minTimestampDocKeys.isEmpty());
TestSegmentSorting.assertTrue("numDocs=" + numDocs + " is not even", (numDocs % 2) == 0);
final Long oddFieldValue = (long) (minTimestampDocKeys.iterator().next() % 2);
final SolrQuery query = new SolrQuery(ODD_FIELD + ":" + oddFieldValue);
// a sort order that is _not_ compatible with the merge sort order
query.setSort(TIMESTAMP_FIELD, SolrQuery.ORDER.asc);
+ if (appendKeyDescendingToSort) query.addSort(KEY_FIELD, SolrQuery.ORDER.desc);
query.setFields(KEY_FIELD, ODD_FIELD, TIMESTAMP_FIELD);
query.setRows(1);
query.set(CommonParams.SEGMENT_TERMINATE_EARLY, true);
diff --git a/solr/core/src/test/org/apache/solr/cloud/TestSegmentSorting.java b/solr/core/src/test/org/apache/solr/cloud/TestSegmentSorting.java
index 8a8a361b1e0..efd22ac805e 100644
--- a/solr/core/src/test/org/apache/solr/cloud/TestSegmentSorting.java
+++ b/solr/core/src/test/org/apache/solr/cloud/TestSegmentSorting.java
@@ -41,8 +41,15 @@ public class TestSegmentSorting extends SolrCloudTestCase {
private static final int REPLICATION_FACTOR = 2;
private static final String configName = MethodHandles.lookup().lookupClass() + "_configSet";
+ private static boolean compoundMergePolicySort = false;
+
@BeforeClass
public static void setupCluster() throws Exception {
+ compoundMergePolicySort = random().nextBoolean();
+ if (compoundMergePolicySort) {
+ System.setProperty("mergePolicySort", "timestamp_i_dvo desc, id desc");
+ System.setProperty("solr.tests.id.docValues", "true");
+ }
configureCluster(NUM_SERVERS)
.addConfig(configName, Paths.get(TEST_HOME(), "collection1", "conf"))
.configure();
@@ -54,6 +61,8 @@ public class TestSegmentSorting extends SolrCloudTestCase {
public void ensureClusterEmpty() throws Exception {
cluster.deleteAllCollections();
cluster.getSolrClient().setDefaultCollection(null);
+ System.clearProperty("mergePolicySort");
+ System.clearProperty("solr.tests.id.docValues");
}
@Before
@@ -97,13 +106,32 @@ public class TestSegmentSorting extends SolrCloudTestCase {
tstes.addDocuments(cloudSolrClient, 2, 10, false);
// CommonParams.SEGMENT_TERMINATE_EARLY parameter now present
- tstes.queryTimestampDescendingSegmentTerminateEarlyYes(cloudSolrClient);
- tstes.queryTimestampDescendingSegmentTerminateEarlyNo(cloudSolrClient);
+ tstes.queryTimestampDescendingSegmentTerminateEarlyYes(
+ cloudSolrClient, false /* appendKeyDescendingToSort */);
+ tstes.queryTimestampDescendingSegmentTerminateEarlyNo(
+ cloudSolrClient, false /* appendKeyDescendingToSort */);
// CommonParams.SEGMENT_TERMINATE_EARLY parameter present, but it won't be used
- tstes.queryTimestampDescendingSegmentTerminateEarlyYesGrouped(cloudSolrClient);
+ tstes.queryTimestampDescendingSegmentTerminateEarlyYesGrouped(
+ cloudSolrClient, false /* appendKeyDescendingToSort */);
// uses a sort order that is _not_ compatible with the merge sort order
- tstes.queryTimestampAscendingSegmentTerminateEarlyYes(cloudSolrClient);
+ tstes.queryTimestampAscendingSegmentTerminateEarlyYes(
+ cloudSolrClient, false /* appendKeyDescendingToSort */);
+
+ if (compoundMergePolicySort) {
+ // CommonParams.SEGMENT_TERMINATE_EARLY parameter now present
+ tstes.queryTimestampDescendingSegmentTerminateEarlyYes(
+ cloudSolrClient, true /* appendKeyDescendingToSort */);
+ tstes.queryTimestampDescendingSegmentTerminateEarlyNo(
+ cloudSolrClient, true /* appendKeyDescendingToSort */);
+
+ // CommonParams.SEGMENT_TERMINATE_EARLY parameter present but it won't be used
+ tstes.queryTimestampDescendingSegmentTerminateEarlyYesGrouped(
+ cloudSolrClient, true /* appendKeyDescendingToSort */);
+ // uses a sort order that is _not_ compatible with the merge sort order
+ tstes.queryTimestampAscendingSegmentTerminateEarlyYes(
+ cloudSolrClient, true /* appendKeyDescendingToSort */);
+ }
}
/**
diff --git a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
index 79b166c3df7..0f8caaa755d 100644
--- a/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
+++ b/solr/core/src/test/org/apache/solr/update/SolrIndexConfigTest.java
@@ -57,13 +57,20 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
"solrconfig-sortingmergepolicyfactory.xml";
private static final String schemaFileName = "schema.xml";
+ private static boolean compoundMergePolicySort = false;
+
@BeforeClass
public static void beforeClass() throws Exception {
+ compoundMergePolicySort = random().nextBoolean();
+ if (compoundMergePolicySort) {
+ System.setProperty("mergePolicySort", "timestamp_i_dvo desc, id asc");
+ }
initCore(solrConfigFileName, schemaFileName);
}
@After
public void tearDown() throws Exception {
+ System.clearProperty("mergePolicySort");
System.clearProperty("solr.tests.maxCommitMergeWait");
super.tearDown();
}
@@ -132,9 +139,9 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
}
public void testSortingMPSolrIndexConfigCreation() throws Exception {
- final String expectedFieldName = "timestamp_i_dvo";
- final SortField.Type expectedFieldType = SortField.Type.INT;
- final boolean expectedFieldSortDescending = true;
+ final SortField sortField1 = new SortField("timestamp_i_dvo", SortField.Type.INT, true);
+ final SortField sortField2 = new SortField("id", SortField.Type.STRING, false);
+ sortField2.setMissingValue(SortField.STRING_LAST);
SolrConfig solrConfig =
new SolrConfig(instanceDir, solrConfigFileNameSortingMergePolicyFactory);
@@ -151,8 +158,12 @@ public class SolrIndexConfigTest extends SolrTestCaseJ4 {
"mergePolicy (" + mergePolicy + ") is not a SortingMergePolicy",
mergePolicy instanceof SortingMergePolicy);
final SortingMergePolicy sortingMergePolicy = (SortingMergePolicy) mergePolicy;
- final Sort expected =
- new Sort(new SortField(expectedFieldName, expectedFieldType, expectedFieldSortDescending));
+ final Sort expected;
+ if (compoundMergePolicySort) {
+ expected = new Sort(sortField1, sortField2);
+ } else {
+ expected = new Sort(sortField1);
+ }
final Sort actual = sortingMergePolicy.getSort();
assertEquals("SortingMergePolicy.getSort", expected, actual);
}