Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
import java.util.Set;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.search.CallerSpecificQueryLimit;
import org.apache.solr.util.QueryLimitsTestInjectionRule;
import org.apache.solr.util.TestInjection;
import org.junit.After;
import org.junit.BeforeClass;
import org.junit.Test;

public class ExitableDirectoryReaderTest extends SolrTestCaseJ4 {
Expand All @@ -44,6 +46,11 @@ public static void createIndex() {
assertU(commit());
}

@BeforeClass
public static void beforeClass() throws Exception {
QueryLimitsTestInjectionRule.disable();
}

@After
public void tearDownCore() {
deleteCore();
Expand Down
11 changes: 9 additions & 2 deletions solr/core/src/test/org/apache/solr/search/TestRangeQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.solr.schema.FieldType;
import org.apache.solr.schema.NumberType;
import org.apache.solr.schema.StrField;
import org.apache.solr.util.QueryLimitsTestInjectionRule;
import org.apache.solr.util.TestInjection;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -463,8 +464,14 @@ public void testRangeQueryWithFilterCache() throws Exception {
queryService.awaitTermination(
1, TimeUnit.SECONDS)); // All queries after should be very fast

assertEquals(
"Create only one DocSet outside of cache", 1, TestInjection.countDocSetDelays.get());
if (QueryLimitsTestInjectionRule.isEnabled()) {
assertTrue(
"Create multiple DocSet-s outside of cache because of possible query timeouts",
TestInjection.countDocSetDelays.get() > 0);
} else {
assertEquals(
"Create only one DocSet outside of cache", 1, TestInjection.countDocSetDelays.get());
}
}
TestInjection.countDocSetDelays.set(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,7 @@ public void ltr_expensiveFeatureRescoringAndPartialResultsNotTolerated_shouldRai

assertJQ(
"/query" + query.toQueryString(),
"/error/msg=='org.apache.solr.search.QueryLimitsExceededException: Limits exceeded! (Learning To Rank rescoring - "
+ "The full reranking didn\\'t complete. "
+ "If partial results are tolerated the reranking got reverted and all documents preserved their original score and ranking.)"
+ ": Query limits: [TimeAllowedLimit:LIMIT EXCEEDED]'");
"/error/msg=='///regex:.*Limits exceeded\\!.*Learning To Rank rescoring.*///'");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.solr.core.ConfigSetService;
import org.apache.solr.util.ExternalPaths;
import org.apache.solr.util.LogLevelTestRule;
import org.apache.solr.util.QueryLimitsTestInjectionRule;
import org.apache.solr.util.RevertDefaultThreadHandlerRule;
import org.apache.solr.util.StartupLoggingUtils;
import org.hamcrest.Matcher;
Expand Down Expand Up @@ -91,6 +92,7 @@ public class SolrTestCase extends LuceneTestCase {
"org.apache.solr.ltr", NAMING_CONVENTION_TEST_PREFIX))
.around(new RevertDefaultThreadHandlerRule())
.around(new LogLevelTestRule())
.around(new QueryLimitsTestInjectionRule(rarely())) // sometimes use QueryLimits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsmiley you can't do this, there's no randomized context here yet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops!

.around(
new TestRuleAdapter() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.util;

import java.lang.invoke.MethodHandles;
import org.apache.solr.search.QueryLimit;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class QueryLimitsTestInjectionRule implements TestRule {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

private static boolean enabled;

public QueryLimitsTestInjectionRule(boolean enabled) {
QueryLimitsTestInjectionRule.enabled = enabled;
}

@Override
public Statement apply(final Statement base, final Description description) {
if (!enabled) {
return base;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (!enabled) {
base.evaluate();
return;
}
log.info("###Test is configured to use QueryLimits");
try {
assert TestInjection.queryTimeout == null : "Disabled too late, or was init'ed elsewhere";
TestInjection.queryTimeout =
new QueryLimit() {
@Override
public Object currentValue() {
return "No-Op injected QueryLimit";
}

@Override
public boolean shouldExit() {
return false;
}
};

base.evaluate();
} finally {
// always reset the queryTimeout
TestInjection.queryTimeout = null;
}
}
};
}

public static void disable() {
QueryLimitsTestInjectionRule.enabled = false;
}

public static boolean isEnabled() {
return enabled;
}
}
Loading