Skip to content

Commit 282b792

Browse files
Savonitarrkhachatryan
authored andcommitted
[FLINK-37401] Migrate JobMasterTriggerSavepointITCase from JUnit4 to JUnit5 and Jupiter
1 parent 8d09491 commit 282b792

File tree

1 file changed

+58
-35
lines changed

1 file changed

+58
-35
lines changed

flink-tests/src/test/java/org/apache/flink/runtime/jobmaster/JobMasterTriggerSavepointITCase.java

+58-35
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
package org.apache.flink.runtime.jobmaster;
2020

2121
import org.apache.flink.api.common.JobStatus;
22+
import org.apache.flink.client.program.ClusterClient;
2223
import org.apache.flink.client.program.MiniClusterClient;
24+
import org.apache.flink.configuration.Configuration;
25+
import org.apache.flink.configuration.JobManagerOptions;
2326
import org.apache.flink.core.execution.SavepointFormatType;
2427
import org.apache.flink.runtime.checkpoint.CheckpointException;
2528
import org.apache.flink.runtime.checkpoint.CheckpointMetaData;
@@ -36,16 +39,19 @@
3639
import org.apache.flink.runtime.jobgraph.tasks.AbstractInvokable;
3740
import org.apache.flink.runtime.jobgraph.tasks.CheckpointCoordinatorConfiguration;
3841
import org.apache.flink.runtime.jobgraph.tasks.JobCheckpointingSettings;
39-
import org.apache.flink.test.util.AbstractTestBaseJUnit4;
40-
import org.apache.flink.testutils.junit.FailsInGHAContainerWithRootUser;
42+
import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration;
43+
import org.apache.flink.test.junit5.InjectClusterClient;
44+
import org.apache.flink.test.junit5.MiniClusterExtension;
4145
import org.apache.flink.util.ExceptionUtils;
4246

43-
import org.junit.Assume;
44-
import org.junit.Rule;
45-
import org.junit.Test;
46-
import org.junit.experimental.categories.Category;
47-
import org.junit.rules.TemporaryFolder;
47+
import org.junit.jupiter.api.Assertions;
48+
import org.junit.jupiter.api.Assumptions;
49+
import org.junit.jupiter.api.Tag;
50+
import org.junit.jupiter.api.Test;
51+
import org.junit.jupiter.api.extension.RegisterExtension;
52+
import org.junit.jupiter.api.io.TempDir;
4853

54+
import java.io.File;
4955
import java.io.IOException;
5056
import java.nio.file.Files;
5157
import java.nio.file.Path;
@@ -61,40 +67,53 @@
6167
import java.util.stream.Collectors;
6268
import java.util.stream.Stream;
6369

70+
import static org.apache.flink.configuration.JobManagerOptions.SCHEDULER;
6471
import static org.hamcrest.MatcherAssert.assertThat;
6572
import static org.hamcrest.Matchers.equalTo;
6673
import static org.hamcrest.Matchers.hasItem;
6774
import static org.hamcrest.Matchers.isOneOf;
68-
import static org.junit.Assert.assertTrue;
6975

7076
/**
7177
* Tests for {@link org.apache.flink.runtime.jobmaster.JobMaster#triggerSavepoint(String, boolean,
7278
* Duration)}.
7379
*
7480
* @see org.apache.flink.runtime.jobmaster.JobMaster
7581
*/
76-
public class JobMasterTriggerSavepointITCase extends AbstractTestBaseJUnit4 {
82+
public class JobMasterTriggerSavepointITCase {
7783

7884
private static CountDownLatch invokeLatch;
7985

8086
private static volatile CountDownLatch triggerCheckpointLatch;
8187

82-
@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
88+
@TempDir protected File temporaryFolder;
89+
90+
@RegisterExtension
91+
public static MiniClusterExtension miniClusterResource =
92+
new MiniClusterExtension(
93+
new MiniClusterResourceConfiguration.Builder()
94+
.setConfiguration(getConfiguration())
95+
.setNumberTaskManagers(1)
96+
.setNumberSlotsPerTaskManager(4)
97+
.build());
98+
99+
private static Configuration getConfiguration() {
100+
Configuration configuration = new Configuration();
101+
configuration.set(SCHEDULER, JobManagerOptions.SchedulerType.Adaptive);
102+
return configuration;
103+
}
83104

84105
private Path savepointDirectory;
85-
private MiniClusterClient clusterClient;
86106
private JobGraph jobGraph;
87107

88-
private void setUpWithCheckpointInterval(long checkpointInterval) throws Exception {
108+
private void setUpWithCheckpointInterval(
109+
long checkpointInterval, ClusterClient<?> clusterClient) throws Exception {
89110
invokeLatch = new CountDownLatch(1);
90111
triggerCheckpointLatch = new CountDownLatch(1);
91-
savepointDirectory = temporaryFolder.newFolder().toPath();
92-
93-
Assume.assumeTrue(
94-
"ClusterClient is not an instance of MiniClusterClient",
95-
MINI_CLUSTER_RESOURCE.getClusterClient() instanceof MiniClusterClient);
112+
savepointDirectory = temporaryFolder.toPath();
96113

97-
clusterClient = (MiniClusterClient) MINI_CLUSTER_RESOURCE.getClusterClient();
114+
Assumptions.assumeTrue(
115+
clusterClient instanceof MiniClusterClient,
116+
"ClusterClient is not an instance of MiniClusterClient");
98117

99118
final JobVertex vertex = new JobVertex("testVertex");
100119
vertex.setInvokableClass(NoOpBlockingInvokable.class);
@@ -121,15 +140,16 @@ private void setUpWithCheckpointInterval(long checkpointInterval) throws Excepti
121140
.build();
122141

123142
clusterClient.submitJob(jobGraph).get();
124-
assertTrue(invokeLatch.await(60, TimeUnit.SECONDS));
125-
waitForJob();
143+
Assertions.assertTrue(invokeLatch.await(60, TimeUnit.SECONDS));
144+
waitForJob(clusterClient);
126145
}
127146

128147
@Test
129-
public void testStopJobAfterSavepoint() throws Exception {
130-
setUpWithCheckpointInterval(10L);
148+
public void testStopJobAfterSavepoint(@InjectClusterClient ClusterClient<?> clusterClient)
149+
throws Exception {
150+
setUpWithCheckpointInterval(10L, clusterClient);
131151

132-
final String savepointLocation = cancelWithSavepoint();
152+
final String savepointLocation = cancelWithSavepoint(clusterClient);
133153
final JobStatus jobStatus = clusterClient.getJobStatus(jobGraph.getJobID()).get();
134154

135155
assertThat(jobStatus, isOneOf(JobStatus.CANCELED, JobStatus.CANCELLING));
@@ -142,11 +162,12 @@ public void testStopJobAfterSavepoint() throws Exception {
142162
}
143163

144164
@Test
145-
public void testStopJobAfterSavepointWithDeactivatedPeriodicCheckpointing() throws Exception {
165+
public void testStopJobAfterSavepointWithDeactivatedPeriodicCheckpointing(
166+
@InjectClusterClient ClusterClient<?> clusterClient) throws Exception {
146167
// set checkpointInterval to Long.MAX_VALUE, which means deactivated checkpointing
147-
setUpWithCheckpointInterval(Long.MAX_VALUE);
168+
setUpWithCheckpointInterval(Long.MAX_VALUE, clusterClient);
148169

149-
final String savepointLocation = cancelWithSavepoint();
170+
final String savepointLocation = cancelWithSavepoint(clusterClient);
150171
final JobStatus jobStatus =
151172
clusterClient.getJobStatus(jobGraph.getJobID()).get(60, TimeUnit.SECONDS);
152173

@@ -160,18 +181,19 @@ public void testStopJobAfterSavepointWithDeactivatedPeriodicCheckpointing() thro
160181
}
161182

162183
@Test
163-
@Category(FailsInGHAContainerWithRootUser.class)
164-
public void testDoNotCancelJobIfSavepointFails() throws Exception {
165-
setUpWithCheckpointInterval(10L);
184+
@Tag("org.apache.flink.testutils.junit.FailsInGHAContainerWithRootUser")
185+
public void testDoNotCancelJobIfSavepointFails(
186+
@InjectClusterClient ClusterClient<?> clusterClient) throws Exception {
187+
setUpWithCheckpointInterval(10L, clusterClient);
166188

167189
try {
168190
Files.setPosixFilePermissions(savepointDirectory, Collections.emptySet());
169191
} catch (IOException e) {
170-
Assume.assumeNoException(e);
192+
Assumptions.assumeTrue(e == null);
171193
}
172194

173195
try {
174-
cancelWithSavepoint();
196+
cancelWithSavepoint(clusterClient);
175197
} catch (Exception e) {
176198
assertThat(
177199
ExceptionUtils.findThrowable(e, CheckpointException.class).isPresent(),
@@ -192,8 +214,9 @@ public void testDoNotCancelJobIfSavepointFails() throws Exception {
192214
* with a meaningful exception message.
193215
*/
194216
@Test
195-
public void testCancelWithSavepointWithoutConfiguredSavepointDirectory() throws Exception {
196-
setUpWithCheckpointInterval(10L);
217+
public void testCancelWithSavepointWithoutConfiguredSavepointDirectory(
218+
@InjectClusterClient ClusterClient<?> clusterClient) throws Exception {
219+
setUpWithCheckpointInterval(10L, clusterClient);
197220

198221
try {
199222
clusterClient
@@ -206,7 +229,7 @@ public void testCancelWithSavepointWithoutConfiguredSavepointDirectory() throws
206229
}
207230
}
208231

209-
private void waitForJob() throws Exception {
232+
private void waitForJob(ClusterClient<?> clusterClient) throws Exception {
210233
for (int i = 0; i < 60; i++) {
211234
try {
212235
final JobStatus jobStatus =
@@ -275,7 +298,7 @@ public Future<Void> notifyCheckpointAbortAsync(
275298
}
276299
}
277300

278-
private String cancelWithSavepoint() throws Exception {
301+
private String cancelWithSavepoint(ClusterClient<?> clusterClient) throws Exception {
279302
return clusterClient
280303
.cancelWithSavepoint(
281304
jobGraph.getJobID(),

0 commit comments

Comments
 (0)