You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2021/03/30 10:41:49 UTC
[lucene] 03/06: Remove exceptional test exclusions for forked
non-tests and inner classes.
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
commit 89024a466be71eae290e9246c9e7265cbc728e54
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Tue Mar 30 11:13:41 2021 +0200
Remove exceptional test exclusions for forked non-tests and inner classes.
---
build.gradle | 5 +-
gradle/ant-compat/misc.gradle | 10 ----
gradle/{ant-compat => java}/folder-layout.gradle | 6 +-
.../org/apache/lucene/util/TestVirtualMethod.java | 66 +++++++++++-----------
.../apache/lucene/replicator/nrt/SimpleServer.java | 9 ++-
5 files changed, 42 insertions(+), 54 deletions(-)
diff --git a/build.gradle b/build.gradle
index cfd8653..a288e0d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -109,12 +109,9 @@ ext {
apply from: file('gradle/generation/local-settings.gradle')
-// Ant-compatibility layer: apply folder layout early so that
-// evaluation of other scripts doesn't need to be deferred.
-apply from: file('gradle/ant-compat/folder-layout.gradle')
-
// Set up defaults and configure aspects for certain modules or functionality
// (java, tests)
+apply from: file('gradle/java/folder-layout.gradle')
apply from: file('gradle/java/javac.gradle')
apply from: file('gradle/testing/defaults-tests.gradle')
apply from: file('gradle/testing/randomization.gradle')
diff --git a/gradle/ant-compat/misc.gradle b/gradle/ant-compat/misc.gradle
index d50a80b..baefa2b 100644
--- a/gradle/ant-compat/misc.gradle
+++ b/gradle/ant-compat/misc.gradle
@@ -15,16 +15,6 @@
* limitations under the License.
*/
-// Exclude test classes that are not actually stand-alone tests (they're executed from other stuff).
-configure(project(":lucene:replicator")) {
- plugins.withType(JavaPlugin) {
- test {
- exclude "**/SimpleServer*"
- }
- }
-}
-
-
// Resources from top-level project folder are looked up via getClass(). Strange.
configure(project(":lucene:benchmark")) {
plugins.withType(JavaPlugin) {
diff --git a/gradle/ant-compat/folder-layout.gradle b/gradle/java/folder-layout.gradle
similarity index 94%
rename from gradle/ant-compat/folder-layout.gradle
rename to gradle/java/folder-layout.gradle
index c86f68b..11133aa 100644
--- a/gradle/ant-compat/folder-layout.gradle
+++ b/gradle/java/folder-layout.gradle
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-// Adapt to custom folder convention.
+// Adapt to custom, legacy folder convention.
allprojects {
plugins.withType(JavaPlugin) {
sourceSets {
@@ -32,11 +32,7 @@ allprojects {
into sourceSets.test.java.outputDir
}
processTestResources.dependsOn copyTestResources
- }
-}
-allprojects {
- plugins.withType(JavaPlugin) {
// if 'src/tools' exists, add it as a separate sourceSet.
if (file('src/tools/java').exists()) {
sourceSets {
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java b/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
index 3d3c270..45e706e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestVirtualMethod.java
@@ -17,17 +17,18 @@
package org.apache.lucene.util;
public class TestVirtualMethod extends LuceneTestCase {
+ private static final VirtualMethod<Base> publicTestMethod =
+ new VirtualMethod<>(Base.class, "publicTest", String.class);
+ private static final VirtualMethod<Base> protectedTestMethod =
+ new VirtualMethod<>(Base.class, "protectedTest", int.class);
- private static final VirtualMethod<TestVirtualMethod> publicTestMethod =
- new VirtualMethod<>(TestVirtualMethod.class, "publicTest", String.class);
- private static final VirtualMethod<TestVirtualMethod> protectedTestMethod =
- new VirtualMethod<>(TestVirtualMethod.class, "protectedTest", int.class);
-
- public void publicTest(String test) {}
+ static class Base {
+ public void publicTest(String test) {}
- protected void protectedTest(int test) {}
+ protected void protectedTest(int test) {}
+ }
- static class TestClass1 extends TestVirtualMethod {
+ static class Nested1 extends Base {
@Override
public void publicTest(String test) {}
@@ -35,74 +36,73 @@ public class TestVirtualMethod extends LuceneTestCase {
protected void protectedTest(int test) {}
}
- static class TestClass2 extends TestClass1 {
+ static class Nested2 extends Nested1 {
@Override // make it public here
public void protectedTest(int test) {}
}
- static class TestClass3 extends TestClass2 {
+ static class Nested3 extends Nested2 {
@Override
public void publicTest(String test) {}
}
- static class TestClass4 extends TestVirtualMethod {}
+ static class Nested4 extends Base {}
- static class TestClass5 extends TestClass4 {}
+ static class Nested5 extends Nested4 {}
public void testGeneral() {
- assertEquals(0, publicTestMethod.getImplementationDistance(this.getClass()));
- assertEquals(1, publicTestMethod.getImplementationDistance(TestClass1.class));
- assertEquals(1, publicTestMethod.getImplementationDistance(TestClass2.class));
- assertEquals(3, publicTestMethod.getImplementationDistance(TestClass3.class));
- assertFalse(publicTestMethod.isOverriddenAsOf(TestClass4.class));
- assertFalse(publicTestMethod.isOverriddenAsOf(TestClass5.class));
-
- assertEquals(0, protectedTestMethod.getImplementationDistance(this.getClass()));
- assertEquals(1, protectedTestMethod.getImplementationDistance(TestClass1.class));
- assertEquals(2, protectedTestMethod.getImplementationDistance(TestClass2.class));
- assertEquals(2, protectedTestMethod.getImplementationDistance(TestClass3.class));
- assertFalse(protectedTestMethod.isOverriddenAsOf(TestClass4.class));
- assertFalse(protectedTestMethod.isOverriddenAsOf(TestClass5.class));
+ assertEquals(0, publicTestMethod.getImplementationDistance(Base.class));
+ assertEquals(1, publicTestMethod.getImplementationDistance(Nested1.class));
+ assertEquals(1, publicTestMethod.getImplementationDistance(Nested2.class));
+ assertEquals(3, publicTestMethod.getImplementationDistance(Nested3.class));
+ assertFalse(publicTestMethod.isOverriddenAsOf(Nested4.class));
+ assertFalse(publicTestMethod.isOverriddenAsOf(Nested5.class));
+
+ assertEquals(0, protectedTestMethod.getImplementationDistance(Base.class));
+ assertEquals(1, protectedTestMethod.getImplementationDistance(Nested1.class));
+ assertEquals(2, protectedTestMethod.getImplementationDistance(Nested2.class));
+ assertEquals(2, protectedTestMethod.getImplementationDistance(Nested3.class));
+ assertFalse(protectedTestMethod.isOverriddenAsOf(Nested4.class));
+ assertFalse(protectedTestMethod.isOverriddenAsOf(Nested5.class));
assertTrue(
VirtualMethod.compareImplementationDistance(
- TestClass3.class, publicTestMethod, protectedTestMethod)
+ Nested3.class, publicTestMethod, protectedTestMethod)
> 0);
assertEquals(
0,
VirtualMethod.compareImplementationDistance(
- TestClass5.class, publicTestMethod, protectedTestMethod));
+ Nested5.class, publicTestMethod, protectedTestMethod));
}
@SuppressWarnings({"rawtypes", "unchecked"})
public void testExceptions() {
- // LuceneTestCase is not a subclass and can never override publicTest(String)
+ // Object is not a subclass and can never override publicTest(String)
expectThrows(
IllegalArgumentException.class,
() -> {
- // cast to Class to remove generics:
- publicTestMethod.getImplementationDistance((Class) LuceneTestCase.class);
+ publicTestMethod.getImplementationDistance((Class) Object.class);
});
// Method bogus() does not exist, so IAE should be thrown
expectThrows(
IllegalArgumentException.class,
() -> {
- new VirtualMethod<>(TestVirtualMethod.class, "bogus");
+ new VirtualMethod<>(Base.class, "bogus");
});
// Method publicTest(String) is not declared in TestClass2, so IAE should be thrown
expectThrows(
IllegalArgumentException.class,
() -> {
- new VirtualMethod<>(TestClass2.class, "publicTest", String.class);
+ new VirtualMethod<>(Nested2.class, "publicTest", String.class);
});
// try to create a second instance of the same baseClass / method combination
expectThrows(
UnsupportedOperationException.class,
() -> {
- new VirtualMethod<>(TestVirtualMethod.class, "publicTest", String.class);
+ new VirtualMethod<>(Base.class, "publicTest", String.class);
});
}
}
diff --git a/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleServer.java b/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleServer.java
index 4d91dfc..d5f51d7 100644
--- a/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleServer.java
+++ b/lucene/replicator/src/test/org/apache/lucene/replicator/nrt/SimpleServer.java
@@ -47,10 +47,11 @@ import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;
import org.apache.lucene.util.SuppressForbidden;
import org.apache.lucene.util.TestUtil;
+import org.junit.AssumptionViolatedException;
/**
* Child process with silly naive TCP socket server to handle between-node commands, launched for
- * each node by TestNRTReplication.
+ * each node by {@link TestNRTReplication}.
*/
@SuppressCodecs({"MockRandom", "Direct", "SimpleText"})
@SuppressSysoutChecks(bugUrl = "Stuff gets printed, important stuff for debugging a failure")
@@ -223,8 +224,12 @@ public class SimpleServer extends LuceneTestCase {
@SuppressWarnings("try")
public void test() throws Exception {
+ String nodeId = System.getProperty("tests.nrtreplication.nodeid");
+ if (nodeId == null) {
+ throw new AssumptionViolatedException("Not a stand-alone test.");
+ }
- int id = Integer.parseInt(System.getProperty("tests.nrtreplication.nodeid"));
+ int id = Integer.parseInt(nodeId);
Thread.currentThread().setName("main child " + id);
Path indexPath = Paths.get(System.getProperty("tests.nrtreplication.indexpath"));
boolean isPrimary = System.getProperty("tests.nrtreplication.isPrimary") != null;