diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/UgiBasedMetastoreClientFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/UgiBasedMetastoreClientFactory.java index 5408300b951d..000230b322c7 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/UgiBasedMetastoreClientFactory.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/UgiBasedMetastoreClientFactory.java @@ -18,8 +18,6 @@ import io.trino.spi.security.ConnectorIdentity; import org.apache.thrift.TException; -import java.io.Closeable; -import java.io.IOException; import java.util.Optional; import static java.util.Objects.requireNonNull; @@ -65,12 +63,9 @@ private static void setMetastoreUserOrClose(ThriftMetastoreClient client, String } catch (Throwable t) { // close client and suppress any error from close - try (Closeable ignored = client) { + try (var _ = client) { throw t; } - catch (IOException e) { - // impossible; will be suppressed - } } } } diff --git a/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/ReportOverriddenMethods.java b/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/ReportOverriddenMethods.java new file mode 100644 index 000000000000..fb0f930da29f --- /dev/null +++ b/testing/trino-testing-services/src/main/java/io/trino/testing/services/junit/ReportOverriddenMethods.java @@ -0,0 +1,71 @@ +/* + * Licensed 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 io.trino.testing.services.junit; + +import org.junit.platform.engine.support.descriptor.MethodSource; +import org.junit.platform.launcher.TestExecutionListener; +import org.junit.platform.launcher.TestIdentifier; +import org.junit.platform.launcher.TestPlan; + +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import static com.google.common.base.Throwables.getStackTraceAsString; +import static io.trino.testing.services.junit.Listeners.reportListenerFailure; +import static java.lang.String.format; + +public class ReportOverriddenMethods + implements TestExecutionListener +{ + @Override + public void testPlanExecutionStarted(TestPlan testPlan) + { + try { + testPlan.accept(new TestPlan.Visitor() + { + @Override + public void visit(TestIdentifier testIdentifier) + { + testIdentifier.getSource().ifPresent(source -> { + if (source instanceof MethodSource methodSource) { + if (!Modifier.isPublic(methodSource.getJavaMethod().getModifiers()) && + !Modifier.isProtected(methodSource.getJavaMethod().getModifiers())) { + List> declaringClasses = Stream.>iterate(methodSource.getJavaClass(), clazz -> clazz.getSuperclass() != null, Class::getSuperclass) + .filter(clazz -> + Arrays.stream(clazz.getDeclaredMethods()) + .anyMatch(method -> method.getName().equals(methodSource.getJavaMethod().getName()))) + .toList(); + if (declaringClasses.size() > 1) { + throw new IllegalStateException(format( + """ + Method %s is not public. Similar methods are defined by %s. \ + When tests are non-public, they do not @Override in Java sense, but they still interact with each other in JUnit, \ + and only one of declared tests gets executed. \ + This leads to tests being silently skipped without any source-level indication.""", + methodSource.getJavaMethod(), + declaringClasses)); + } + } + } + }); + } + }); + } + catch (RuntimeException | Error e) { + reportListenerFailure(getClass(), "%s", getStackTraceAsString(e)); + } + } +} diff --git a/testing/trino-testing-services/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener b/testing/trino-testing-services/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener index 618d40bf5a0a..670508fdd433 100644 --- a/testing/trino-testing-services/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener +++ b/testing/trino-testing-services/src/main/resources/META-INF/services/org.junit.platform.launcher.TestExecutionListener @@ -1 +1,2 @@ io.trino.testing.services.junit.LogTestDurationListener +io.trino.testing.services.junit.ReportOverriddenMethods