Skip to content

Commit b2ced13

Browse files
committed
Tests: fix test bugs so tests pass on IBM J9 (at least once)
1 parent 93beea1 commit b2ced13

File tree

5 files changed

+70
-3
lines changed

5 files changed

+70
-3
lines changed

core/src/test/java/org/elasticsearch/script/GroovySecurityTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.Test;
2828

2929
import java.nio.file.Path;
30+
import java.util.Locale;
3031

3132
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
3233
import static org.hamcrest.CoreMatchers.equalTo;
@@ -121,9 +122,12 @@ private void assertFailure(String script) {
121122
"; doc['foo'].value + 2\", \"type\": \"number\", \"lang\": \"groovy\"}}}").get();
122123
assertEquals(0, resp.getHits().getTotalHits());
123124
ShardSearchFailure fails[] = resp.getShardFailures();
124-
// TODO: GroovyScriptExecutionException needs work
125+
// TODO: GroovyScriptExecutionException needs work:
126+
// fix it to preserve cause so we don't do this flaky string-check stuff
125127
for (ShardSearchFailure fail : fails) {
126-
assertTrue(fail.getCause().toString().contains("AccessControlException[access denied"));
128+
assertTrue("unexpected exception" + fail.getCause(),
129+
// different casing, depending on jvm impl...
130+
fail.getCause().toString().toLowerCase(Locale.ROOT).contains("accesscontrolexception[access denied"));
127131
}
128132
}
129133
}

core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ private void checkMatchedFieldsCase(boolean requireFieldMatch) throws Exception
982982
assertHighlight(resp, 0, "bar", 0, equalTo("<em>resul</em>t"));
983983

984984
assertFailures(req.setQuery(queryStringQuery("result").field("foo").field("foo.plain").field("bar").field("bar.plain")),
985-
RestStatus.INTERNAL_SERVER_ERROR, containsString("String index out of range"));
985+
RestStatus.INTERNAL_SERVER_ERROR, containsString("IndexOutOfBoundsException"));
986986
}
987987

988988
@Test

core/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.carrotsearch.randomizedtesting.RandomizedContext;
2222
import com.carrotsearch.randomizedtesting.RandomizedTest;
2323
import com.carrotsearch.randomizedtesting.annotations.Listeners;
24+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
2425
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
2526
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
2627
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
@@ -79,6 +80,10 @@
7980
ReproduceInfoPrinter.class,
8081
LoggingListener.class
8182
})
83+
// remove this entire annotation on upgrade to 5.3!
84+
@ThreadLeakFilters(defaultFilters = true, filters = {
85+
IBMJ9HackThreadFilters.class,
86+
})
8287
@ThreadLeakScope(Scope.SUITE)
8388
@ThreadLeakLingering(linger = 5000) // 5 sec lingering
8489
@TimeoutSuite(millis = 20 * TimeUnits.MINUTE)

core/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.test;
2121

2222
import com.carrotsearch.randomizedtesting.annotations.Listeners;
23+
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
2324
import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
2425

2526
import org.apache.lucene.analysis.BaseTokenStreamTestCase;
@@ -34,6 +35,10 @@
3435
@Listeners({
3536
ReproduceInfoPrinter.class
3637
})
38+
//remove this entire annotation on upgrade to 5.3!
39+
@ThreadLeakFilters(defaultFilters = true, filters = {
40+
IBMJ9HackThreadFilters.class,
41+
})
3742
@TimeoutSuite(millis = TimeUnits.HOUR)
3843
@LuceneTestCase.SuppressReproduceLine
3944
@LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose")
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.elasticsearch.test;
2+
3+
/*
4+
* Licensed to Elasticsearch under one or more contributor
5+
* license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright
7+
* ownership. Elasticsearch licenses this file to you under
8+
* the Apache License, Version 2.0 (the "License"); you may
9+
* not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import com.carrotsearch.randomizedtesting.ThreadFilter;
23+
24+
import org.apache.lucene.util.Constants;
25+
import org.apache.lucene.util.Version;
26+
27+
/** temporary workaround for https://issues.apache.org/jira/browse/LUCENE-6518
28+
* remove me on upgrade to 5.3! I am just an updated version of QuickPatchThreadFilters from lucene */
29+
public class IBMJ9HackThreadFilters implements ThreadFilter {
30+
static final boolean isJ9;
31+
32+
static {
33+
assert Version.LATEST.equals(Version.LUCENE_5_2_0) : "please remove this entire class for 5.3";
34+
isJ9 = Constants.JAVA_VENDOR.startsWith("IBM");
35+
}
36+
37+
@Override
38+
public boolean reject(Thread t) {
39+
if (isJ9) {
40+
// LUCENE-6518
41+
if ("ClassCache Reaper".equals(t.getName())) {
42+
return true;
43+
}
44+
45+
// LUCENE-4736
46+
StackTraceElement [] stack = t.getStackTrace();
47+
if (stack.length > 0 && stack[stack.length - 1].getClassName().equals("java.util.Timer$TimerImpl")) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
}
53+
}

0 commit comments

Comments
 (0)