forked from apache/hudi
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MINOR] Performance improvement of flink ITs with reused miniCluster (a…
…pache#7151) * implement MiniCluster extension compatible with junit5
- Loading branch information
Showing
5 changed files
with
97 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
hudi-flink-datasource/hudi-flink/src/test/java/org/apache/hudi/utils/FlinkMiniCluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF 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. | ||
*/ | ||
|
||
package org.apache.hudi.utils; | ||
|
||
import org.apache.flink.runtime.client.JobStatusMessage; | ||
import org.apache.flink.runtime.testutils.MiniClusterResourceConfiguration; | ||
import org.apache.flink.test.util.AbstractTestBase; | ||
import org.apache.flink.test.util.MiniClusterWithClientResource; | ||
|
||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.AfterEachCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Class for tests that run multiple tests and want to reuse the same Flink cluster. | ||
* Unlike {@link AbstractTestBase}, this class is designed to run with JUnit 5. | ||
*/ | ||
public class FlinkMiniCluster implements BeforeAllCallback, AfterAllCallback, AfterEachCallback { | ||
private static final Logger LOG = LoggerFactory.getLogger(FlinkMiniCluster.class); | ||
|
||
public static final int DEFAULT_PARALLELISM = 4; | ||
|
||
private static final MiniClusterWithClientResource MINI_CLUSTER_RESOURCE = | ||
new MiniClusterWithClientResource( | ||
new MiniClusterResourceConfiguration.Builder() | ||
.setNumberTaskManagers(1) | ||
.setNumberSlotsPerTaskManager(DEFAULT_PARALLELISM) | ||
.build()); | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) throws Exception { | ||
MINI_CLUSTER_RESOURCE.before(); | ||
} | ||
|
||
@Override | ||
public void afterAll(ExtensionContext context) { | ||
MINI_CLUSTER_RESOURCE.after(); | ||
} | ||
|
||
@Override | ||
public void afterEach(ExtensionContext context) throws Exception { | ||
cleanupRunningJobs(); | ||
} | ||
|
||
private void cleanupRunningJobs() throws Exception { | ||
if (!MINI_CLUSTER_RESOURCE.getMiniCluster().isRunning()) { | ||
// do nothing if the MiniCluster is not running | ||
LOG.warn("Mini cluster is not running after the test!"); | ||
return; | ||
} | ||
|
||
for (JobStatusMessage path : MINI_CLUSTER_RESOURCE.getClusterClient().listJobs().get()) { | ||
if (!path.getJobState().isTerminalState()) { | ||
try { | ||
MINI_CLUSTER_RESOURCE.getClusterClient().cancel(path.getJobId()).get(); | ||
} catch (Exception ignored) { | ||
// ignore exceptions when cancelling dangling jobs | ||
} | ||
} | ||
} | ||
} | ||
} |