Skip to content

Commit 26436ac

Browse files
SamBarkerafedulov
authored andcommitted
[FLINK-35512][tests] Do not depend on the flink-clients jar actually existing in ArtifactFetchManagerTest
1 parent cb030c2 commit 26436ac

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

flink-clients/src/test/java/org/apache/flink/client/program/artifact/ArtifactFetchManagerTest.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,12 @@ void testFileSystemFetchWithoutAdditionalUri() throws Exception {
9595
}
9696

9797
@Test
98-
void testFileSystemFetchWithAdditionalUri() throws Exception {
98+
void testFileSystemFetchWithAdditionalUri(@TempDir Path pseudoJarDir) throws Exception {
9999
File sourceFile = TestingUtils.getClassFile(getClass());
100100
String uriStr = "file://" + sourceFile.toURI().getPath();
101-
File additionalSrcFile = getFlinkClientsJar();
101+
File additionalSrcFile =
102+
Files.createTempFile(pseudoJarDir, "testFileSystemFetchWithAdditionalUri", ".jar")
103+
.toFile();
102104
String additionalUriStr = "file://" + additionalSrcFile.toURI().getPath();
103105

104106
ArtifactFetchManager fetchMgr = new ArtifactFetchManager(configuration);
@@ -112,12 +114,12 @@ void testFileSystemFetchWithAdditionalUri() throws Exception {
112114
}
113115

114116
@Test
115-
void testHttpFetch() throws Exception {
117+
void testHttpFetch(@TempDir Path pseudoJarDir) throws Exception {
116118
configuration.set(ArtifactFetchOptions.RAW_HTTP_ENABLED, true);
117119
HttpServer httpServer = null;
118120
try {
119121
httpServer = startHttpServer();
120-
File sourceFile = getFlinkClientsJar();
122+
File sourceFile = Files.createTempFile(pseudoJarDir, "testHttpFetch", ".jar").toFile();
121123
httpServer.createContext(
122124
"/download/" + sourceFile.getName(), new DummyHttpDownloadHandler(sourceFile));
123125
String uriStr =
@@ -138,10 +140,11 @@ void testHttpFetch() throws Exception {
138140
}
139141

140142
@Test
141-
void testMixedArtifactFetch() throws Exception {
143+
void testMixedArtifactFetch(@TempDir Path pseudoJarDir) throws Exception {
142144
File sourceFile = TestingUtils.getClassFile(getClass());
143145
String uriStr = "file://" + sourceFile.toURI().getPath();
144-
File sourceFile2 = getFlinkClientsJar();
146+
File sourceFile2 =
147+
Files.createTempFile(pseudoJarDir, "testMixedArtifactFetch", ".jar").toFile();
145148
String uriStr2 = "file://" + sourceFile2.toURI().getPath();
146149

147150
ArtifactFetchManager fetchMgr = new ArtifactFetchManager(configuration);
@@ -230,15 +233,6 @@ private HttpServer startHttpServer() throws IOException {
230233
return httpServer;
231234
}
232235

233-
private File getFlinkClientsJar() throws IOException {
234-
return TestingUtils.getFileFromTargetDir(
235-
ArtifactFetchManager.class,
236-
p ->
237-
org.apache.flink.util.FileUtils.isJarFile(p)
238-
&& p.toFile().getName().startsWith("flink-clients")
239-
&& !p.toFile().getName().contains("test-utils"));
240-
}
241-
242236
private static class DummyHttpDownloadHandler implements HttpHandler {
243237

244238
final File file;

flink-core/src/test/java/org/apache/flink/testutils/TestingUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public static File getFileFromTargetDir(Class<?> cls, Predicate<Path> fileFilter
8080

8181
final Collection<Path> jarPaths =
8282
org.apache.flink.util.FileUtils.listFilesInDirectory(mvnTargetDir, fileFilter);
83-
assertThat(jarPaths).isNotEmpty();
83+
assertThat(jarPaths)
84+
.describedAs("Could not find any matching files in %s", mvnTargetDir)
85+
.isNotEmpty();
8486

8587
return jarPaths.iterator().next().toFile();
8688
}

0 commit comments

Comments
 (0)