Browse Source

Tests: fix test bugs so tests pass on IBM J9 (at least once)

Robert Muir 10 years ago
parent
commit
b2ced13f3d

+ 6 - 2
core/src/test/java/org/elasticsearch/script/GroovySecurityTests.java

@@ -27,6 +27,7 @@ import org.elasticsearch.test.ElasticsearchIntegrationTest;
 import org.junit.Test;
 
 import java.nio.file.Path;
+import java.util.Locale;
 
 import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
 import static org.hamcrest.CoreMatchers.equalTo;
@@ -121,9 +122,12 @@ public class GroovySecurityTests extends ElasticsearchIntegrationTest {
                             "; doc['foo'].value + 2\", \"type\": \"number\", \"lang\": \"groovy\"}}}").get();
         assertEquals(0, resp.getHits().getTotalHits());
         ShardSearchFailure fails[] = resp.getShardFailures();
-        // TODO: GroovyScriptExecutionException needs work
+        // TODO: GroovyScriptExecutionException needs work:
+        // fix it to preserve cause so we don't do this flaky string-check stuff
         for (ShardSearchFailure fail : fails) {
-            assertTrue(fail.getCause().toString().contains("AccessControlException[access denied"));
+            assertTrue("unexpected exception" + fail.getCause(),
+                       // different casing, depending on jvm impl...
+                       fail.getCause().toString().toLowerCase(Locale.ROOT).contains("accesscontrolexception[access denied"));
         }
     }
 }

+ 1 - 1
core/src/test/java/org/elasticsearch/search/highlight/HighlighterSearchTests.java

@@ -982,7 +982,7 @@ public class HighlighterSearchTests extends ElasticsearchIntegrationTest {
         assertHighlight(resp, 0, "bar", 0, equalTo("<em>resul</em>t"));
 
         assertFailures(req.setQuery(queryStringQuery("result").field("foo").field("foo.plain").field("bar").field("bar.plain")),
-                 RestStatus.INTERNAL_SERVER_ERROR, containsString("String index out of range"));
+                 RestStatus.INTERNAL_SERVER_ERROR, containsString("IndexOutOfBoundsException"));
     }
 
     @Test

+ 5 - 0
core/src/test/java/org/elasticsearch/test/ElasticsearchTestCase.java

@@ -21,6 +21,7 @@ package org.elasticsearch.test;
 import com.carrotsearch.randomizedtesting.RandomizedContext;
 import com.carrotsearch.randomizedtesting.RandomizedTest;
 import com.carrotsearch.randomizedtesting.annotations.Listeners;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakLingering;
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
 import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope.Scope;
@@ -79,6 +80,10 @@ import static com.google.common.collect.Lists.newArrayList;
         ReproduceInfoPrinter.class,
         LoggingListener.class
 })
+// remove this entire annotation on upgrade to 5.3!
+@ThreadLeakFilters(defaultFilters = true, filters = {
+        IBMJ9HackThreadFilters.class,
+})
 @ThreadLeakScope(Scope.SUITE)
 @ThreadLeakLingering(linger = 5000) // 5 sec lingering
 @TimeoutSuite(millis = 20 * TimeUnits.MINUTE)

+ 5 - 0
core/src/test/java/org/elasticsearch/test/ElasticsearchTokenStreamTestCase.java

@@ -20,6 +20,7 @@
 package org.elasticsearch.test;
 
 import com.carrotsearch.randomizedtesting.annotations.Listeners;
+import com.carrotsearch.randomizedtesting.annotations.ThreadLeakFilters;
 import com.carrotsearch.randomizedtesting.annotations.TimeoutSuite;
 
 import org.apache.lucene.analysis.BaseTokenStreamTestCase;
@@ -34,6 +35,10 @@ import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
 @Listeners({
         ReproduceInfoPrinter.class
 })
+//remove this entire annotation on upgrade to 5.3!
+@ThreadLeakFilters(defaultFilters = true, filters = {
+     IBMJ9HackThreadFilters.class,
+})
 @TimeoutSuite(millis = TimeUnits.HOUR)
 @LuceneTestCase.SuppressReproduceLine
 @LuceneTestCase.SuppressSysoutChecks(bugUrl = "we log a lot on purpose")

+ 53 - 0
core/src/test/java/org/elasticsearch/test/IBMJ9HackThreadFilters.java

@@ -0,0 +1,53 @@
+package org.elasticsearch.test;
+
+/*
+ * Licensed to Elasticsearch under one or more contributor
+ * license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright
+ * ownership. Elasticsearch 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.
+ */
+
+import com.carrotsearch.randomizedtesting.ThreadFilter;
+
+import org.apache.lucene.util.Constants;
+import org.apache.lucene.util.Version;
+
+/** temporary workaround for https://issues.apache.org/jira/browse/LUCENE-6518
+ *  remove me on upgrade to 5.3! I am just an updated version of QuickPatchThreadFilters from lucene */
+public class IBMJ9HackThreadFilters implements ThreadFilter {
+    static final boolean isJ9;
+    
+    static {
+        assert Version.LATEST.equals(Version.LUCENE_5_2_0) : "please remove this entire class for 5.3";
+        isJ9 = Constants.JAVA_VENDOR.startsWith("IBM");
+    }
+    
+    @Override
+    public boolean reject(Thread t) {
+        if (isJ9) {
+            // LUCENE-6518
+            if ("ClassCache Reaper".equals(t.getName())) {
+                return true;
+            }
+            
+            // LUCENE-4736
+            StackTraceElement [] stack = t.getStackTrace();
+            if (stack.length > 0 && stack[stack.length - 1].getClassName().equals("java.util.Timer$TimerImpl")) {
+                return true;
+            }
+        }
+        return false;
+    }
+}