Skip to content

Commit 1765d59

Browse files
authored
Merge branch 'apache:master' into RATIS-2251
2 parents 3e136af + 59f1992 commit 1765d59

File tree

32 files changed

+270
-162
lines changed

32 files changed

+270
-162
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
- grpc
8484
- server
8585
- misc
86+
- flaky
8687
fail-fast: false
8788
uses: ./.github/workflows/check.yaml
8889
with:

dev-support/checks/unit.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ mkdir -p "$REPORT_DIR"
3636
export MAVEN_OPTS="-Xmx4096m"
3737
MAVEN_OPTIONS='-V -B'
3838

39+
if [[ "$@" =~ "-Pflaky-tests" ]]; then
40+
MAVEN_OPTIONS="${MAVEN_OPTIONS} -Dsurefire.rerunFailingTestsCount=5 -Dsurefire.timeout=1200"
41+
fi
42+
3943
if [[ "${FAIL_FAST}" == "true" ]]; then
4044
MAVEN_OPTIONS="${MAVEN_OPTIONS} --fail-fast -Dsurefire.skipAfterFailureCount=1"
4145
else

pom.xml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
<slf4j.version>2.0.7</slf4j.version>
223223
<junit-bom.version>5.11.2</junit-bom.version>
224224
<jacoco.version>0.8.12</jacoco.version>
225+
<flaky-test-groups>flaky | org.apache.ratis.test.tag.FlakyTest</flaky-test-groups>
225226
</properties>
226227

227228
<dependencyManagement>
@@ -654,12 +655,6 @@
654655
<exclude>**/Test*$*.java</exclude>
655656
<exclude>${test.exclude.pattern}</exclude>
656657
</excludes>
657-
<properties>
658-
<property>
659-
<name>listener</name>
660-
<value>org.apache.ratis.JUnitRunListener</value>
661-
</property>
662-
</properties>
663658
</configuration>
664659
</plugin>
665660
<plugin>
@@ -1124,6 +1119,7 @@
11241119
<includes>
11251120
<include>org.apache.ratis.grpc.**</include>
11261121
</includes>
1122+
<excludedGroups>${flaky-test-groups}</excludedGroups>
11271123
</configuration>
11281124
</plugin>
11291125
</plugins>
@@ -1141,6 +1137,7 @@
11411137
<include>org.apache.ratis.datastream.**</include>
11421138
<include>org.apache.ratis.server.**</include>
11431139
</includes>
1140+
<excludedGroups>${flaky-test-groups}</excludedGroups>
11441141
</configuration>
11451142
</plugin>
11461143
</plugins>
@@ -1159,6 +1156,21 @@
11591156
<exclude>org.apache.ratis.grpc.**</exclude>
11601157
<exclude>org.apache.ratis.server.**</exclude>
11611158
</excludes>
1159+
<excludedGroups>${flaky-test-groups}</excludedGroups>
1160+
</configuration>
1161+
</plugin>
1162+
</plugins>
1163+
</build>
1164+
</profile>
1165+
<profile>
1166+
<id>flaky-tests</id>
1167+
<build>
1168+
<plugins>
1169+
<plugin>
1170+
<groupId>org.apache.maven.plugins</groupId>
1171+
<artifactId>maven-surefire-plugin</artifactId>
1172+
<configuration>
1173+
<groups>${flaky-test-groups}</groups>
11621174
</configuration>
11631175
</plugin>
11641176
</plugins>

ratis-assembly/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
<test.cache.data>${project.build.directory}/test-classes</test.cache.data>
3434
<test.build.classes>${project.build.directory}/test-classes</test.build.classes>
3535
<license.bundles.dependencies>true</license.bundles.dependencies>
36+
<!-- no testable code in this module -->
37+
<skipTests>true</skipTests>
3638
</properties>
3739

3840
<build>

ratis-client/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<artifactId>ratis-client</artifactId>
2424
<name>Apache Ratis Client</name>
2525

26+
<properties>
27+
<!-- no tests in this module so far -->
28+
<skipTests>true</skipTests>
29+
</properties>
30+
2631
<dependencies>
2732
<dependency>
2833
<groupId>org.apache.ratis</groupId>

ratis-common/src/main/java/org/apache/ratis/conf/ConfUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.ratis.conf;
1919

2020
import org.apache.ratis.security.TlsConf;
21-
import org.apache.ratis.thirdparty.com.google.common.base.Objects;
2221
import org.apache.ratis.util.NetUtils;
2322
import org.apache.ratis.util.SizeInBytes;
2423
import org.apache.ratis.util.TimeDuration;
@@ -33,6 +32,7 @@
3332
import java.net.InetSocketAddress;
3433
import java.util.Arrays;
3534
import java.util.List;
35+
import java.util.Objects;
3636
import java.util.concurrent.ConcurrentHashMap;
3737
import java.util.concurrent.ConcurrentMap;
3838
import java.util.function.BiConsumer;
@@ -60,7 +60,7 @@ private static <T> boolean isNew(String key, T value) {
6060
static <T> void logGet(String key, T value, T defaultValue, Consumer<String> logger) {
6161
if (logger != null && Utils.isNew(key, value)) {
6262
logger.accept(String.format("%s = %s (%s)", key, value,
63-
Objects.equal(value, defaultValue)? "default": "custom"));
63+
Objects.equals(value, defaultValue)? "default": "custom"));
6464
}
6565
}
6666

ratis-common/src/test/java/org/apache/ratis/BaseTest.java

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.ratis;
1919

2020
import org.apache.ratis.conf.ConfUtils;
21-
import org.apache.ratis.protocol.RaftPeer;
2221
import org.apache.ratis.util.ExitUtils;
2322
import org.apache.ratis.util.FileUtils;
2423
import org.apache.ratis.util.JavaUtils;
@@ -28,6 +27,7 @@
2827
import org.apache.ratis.util.TimeDuration;
2928
import org.apache.ratis.util.function.CheckedRunnable;
3029
import org.junit.After;
30+
import org.junit.Before;
3131
import org.junit.Rule;
3232
import org.junit.jupiter.api.AfterEach;
3333
import org.junit.jupiter.api.Assertions;
@@ -42,8 +42,7 @@
4242

4343
import java.io.File;
4444
import java.io.IOException;
45-
import java.util.ArrayList;
46-
import java.util.List;
45+
import java.lang.reflect.Method;
4746
import java.util.Objects;
4847
import java.util.concurrent.CompletableFuture;
4948
import java.util.concurrent.Future;
@@ -75,33 +74,30 @@ public void setFirstException(Throwable e) {
7574
}
7675
}
7776

78-
public List<RaftPeer> getPeersWithPriority(List<RaftPeer> peers, RaftPeer suggestedLeader) {
79-
List<RaftPeer> peersWithPriority = new ArrayList<>();
80-
for (int i = 0; i < peers.size(); i++) {
81-
RaftPeer peer = peers.get(i);
82-
final int priority = peer.equals(suggestedLeader)? 2: 1;
83-
peersWithPriority.add(
84-
RaftPeer.newBuilder(peer).setPriority(priority).build());
85-
}
86-
return peersWithPriority;
87-
}
88-
89-
90-
/*
91-
* Junit 4 reference will be removed and the code will be refactored once
92-
* all the unit tests are migrated to Junit 5.
93-
*/
77+
// TODO: Junit 4 reference should be removed once all the unit tests are migrated to Junit 5.
9478

9579
private String testCaseName;
9680

9781
@BeforeEach
9882
public void setup(TestInfo testInfo) {
99-
testCaseName = testInfo.getTestMethod()
100-
.orElseThrow(() -> new RuntimeException("Exception while getting test name."))
101-
.getName();
83+
checkAssumptions();
10284

85+
final Method method = testInfo.getTestMethod().orElse(null);
86+
testCaseName = testInfo.getTestClass().orElse(getClass()).getSimpleName()
87+
+ "." + (method == null? null : method.getName());
88+
}
89+
90+
// @Before annotation is retained to support junit 4 tests.
91+
@Before
92+
public void checkAssumptions() {
10393
final int leaks = ReferenceCountedLeakDetector.getLeakDetector().getLeakCount();
10494
Assumptions.assumeFalse(0 < leaks, () -> "numLeaks " + leaks + " > 0");
95+
96+
final Throwable first = firstException.get();
97+
Assumptions.assumeTrue(first == null, () -> "Already failed with " + first);
98+
99+
final Throwable exited = ExitUtils.getFirstExitException();
100+
Assumptions.assumeTrue(exited == null, () -> "Already exited with " + exited);
105101
}
106102

107103
// @After annotation is retained to support junit 4 tests.
@@ -116,19 +112,10 @@ public void assertNoFailures() {
116112
ExitUtils.assertNotTerminated();
117113
}
118114

119-
// Retained to support junit 4 tests.
120-
@Rule
121-
public final org.junit.rules.Timeout globalTimeout = new org.junit.rules.Timeout(
122-
getGlobalTimeoutSeconds(), TimeUnit.SECONDS );
123-
124115
// Retained to support junit 4 tests.
125116
@Rule
126117
public final TestName testName = new TestName();
127118

128-
public int getGlobalTimeoutSeconds() {
129-
return 100;
130-
}
131-
132119
private static final Supplier<File> ROOT_TEST_DIR = JavaUtils.memoize(
133120
() -> JavaUtils.callAsUnchecked(() -> {
134121
final File dir = new File(System.getProperty("test.build.data", "target/test/data"),
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.ratis;
19+
20+
import org.apache.ratis.util.JavaUtils;
21+
import org.junit.platform.engine.TestExecutionResult;
22+
import org.junit.platform.launcher.TestExecutionListener;
23+
import org.junit.platform.launcher.TestIdentifier;
24+
25+
import java.io.PrintStream;
26+
import java.util.concurrent.TimeoutException;
27+
28+
/**
29+
* A {@link TestExecutionListener} to dump all threads after a test timeout failure.
30+
*/
31+
public class JUnit5TestExecutionListener implements TestExecutionListener {
32+
private final PrintStream out = System.out;
33+
34+
@Override
35+
public void executionFinished(TestIdentifier id, TestExecutionResult result) {
36+
final Throwable timeoutException = getTimeoutException(result);
37+
if (timeoutException != null) {
38+
out.format("%n%s %s failed%n", JavaUtils.date(), id.getDisplayName());
39+
timeoutException.printStackTrace(out);
40+
JavaUtils.dumpAllThreads(out::println);
41+
}
42+
}
43+
44+
private static Throwable getTimeoutException(TestExecutionResult result) {
45+
if (result == null) {
46+
return null;
47+
}
48+
final Throwable throwable = result.getThrowable().orElse(null);
49+
return throwable instanceof TimeoutException? throwable : null;
50+
}
51+
}

ratis-common/src/test/java/org/apache/ratis/JUnitRunListener.java

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)