|
23 | 23 | import static org.junit.Assert.assertFalse; |
24 | 24 | import static org.junit.Assert.assertTrue; |
25 | 25 | import static org.junit.Assume.assumeFalse; |
26 | | -import static org.mockito.ArgumentMatchers.any; |
27 | | -import static org.mockito.ArgumentMatchers.eq; |
28 | 26 | import static org.mockito.Mockito.doThrow; |
29 | 27 | import static org.mockito.Mockito.mock; |
30 | | -import static org.mockito.Mockito.never; |
31 | 28 | import static org.mockito.Mockito.verify; |
32 | 29 | import static org.mockito.Mockito.when; |
33 | 30 |
|
|
38 | 35 | import java.nio.file.NoSuchFileException; |
39 | 36 | import java.nio.file.Path; |
40 | 37 | import java.nio.file.Paths; |
41 | | -import java.util.ArrayList; |
42 | 38 | import java.util.List; |
43 | | -import org.apache.beam.sdk.io.FileSystem.LineageLevel; |
44 | 39 | import org.apache.beam.sdk.io.fs.CreateOptions; |
45 | 40 | import org.apache.beam.sdk.io.fs.MatchResult; |
46 | 41 | import org.apache.beam.sdk.io.fs.MoveOptions; |
|
59 | 54 | import org.junit.rules.TemporaryFolder; |
60 | 55 | import org.junit.runner.RunWith; |
61 | 56 | import org.junit.runners.JUnit4; |
62 | | -import org.mockito.MockedStatic; |
63 | | -import org.mockito.Mockito; |
64 | 57 |
|
65 | 58 | /** Tests for {@link FileSystems}. */ |
66 | 59 | @RunWith(JUnit4.class) |
@@ -344,97 +337,6 @@ public void testMatchNewDirectory() { |
344 | 337 | } |
345 | 338 | } |
346 | 339 |
|
347 | | - @Test |
348 | | - public void testReportSourceLineageFewFiles() { |
349 | | - List<ResourceId> resources = new ArrayList<>(); |
350 | | - for (int i = 0; i < 5; i++) { |
351 | | - resources.add(mockResourceId("/dir/file" + i, "/dir/")); |
352 | | - } |
353 | | - |
354 | | - try (MockedStatic<FileSystems> mocked = |
355 | | - Mockito.mockStatic(FileSystems.class, Mockito.CALLS_REAL_METHODS)) { |
356 | | - mocked |
357 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class))) |
358 | | - .thenAnswer(inv -> null); |
359 | | - mocked |
360 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class), any())) |
361 | | - .thenAnswer(inv -> null); |
362 | | - |
363 | | - FileSystems.reportSourceLineage(resources); |
364 | | - |
365 | | - for (ResourceId r : resources) { |
366 | | - mocked.verify(() -> FileSystems.reportSourceLineage(r)); |
367 | | - } |
368 | | - } |
369 | | - } |
370 | | - |
371 | | - @Test |
372 | | - public void testReportSourceLineageManyFilesFewDirs() { |
373 | | - ResourceId dir = mockResourceId("/dir/", null); |
374 | | - List<ResourceId> resources = new ArrayList<>(); |
375 | | - for (int i = 0; i < 150; i++) { |
376 | | - resources.add(mockResourceId("/dir/file" + i, dir)); |
377 | | - } |
378 | | - |
379 | | - try (MockedStatic<FileSystems> mocked = |
380 | | - Mockito.mockStatic(FileSystems.class, Mockito.CALLS_REAL_METHODS)) { |
381 | | - mocked |
382 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class))) |
383 | | - .thenAnswer(inv -> null); |
384 | | - mocked |
385 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class), any())) |
386 | | - .thenAnswer(inv -> null); |
387 | | - |
388 | | - FileSystems.reportSourceLineage(resources); |
389 | | - |
390 | | - // Should report the unique directory, not individual files |
391 | | - mocked.verify(() -> FileSystems.reportSourceLineage(dir)); |
392 | | - mocked.verify( |
393 | | - () -> FileSystems.reportSourceLineage(any(ResourceId.class), any(LineageLevel.class)), |
394 | | - never()); |
395 | | - } |
396 | | - } |
397 | | - |
398 | | - @Test |
399 | | - public void testReportSourceLineageManyFilesManyDirs() { |
400 | | - List<ResourceId> resources = new ArrayList<>(); |
401 | | - for (int i = 0; i < 150; i++) { |
402 | | - ResourceId dir = mockResourceId("/dir" + i + "/", null); |
403 | | - resources.add(mockResourceId("/dir" + i + "/file", dir)); |
404 | | - } |
405 | | - |
406 | | - try (MockedStatic<FileSystems> mocked = |
407 | | - Mockito.mockStatic(FileSystems.class, Mockito.CALLS_REAL_METHODS)) { |
408 | | - mocked |
409 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class))) |
410 | | - .thenAnswer(inv -> null); |
411 | | - mocked |
412 | | - .when(() -> FileSystems.reportSourceLineage(any(ResourceId.class), any())) |
413 | | - .thenAnswer(inv -> null); |
414 | | - |
415 | | - FileSystems.reportSourceLineage(resources); |
416 | | - |
417 | | - // Should fall back to TOP_LEVEL reporting |
418 | | - mocked.verify( |
419 | | - () -> FileSystems.reportSourceLineage(any(ResourceId.class), eq(LineageLevel.TOP_LEVEL))); |
420 | | - // Should not report individual files or directories at FILE level |
421 | | - mocked.verify(() -> FileSystems.reportSourceLineage(any(ResourceId.class)), never()); |
422 | | - } |
423 | | - } |
424 | | - |
425 | | - private ResourceId mockResourceId(String path, Object dir) { |
426 | | - ResourceId resourceId = mock(ResourceId.class); |
427 | | - when(resourceId.toString()).thenReturn(path); |
428 | | - if (dir instanceof String) { |
429 | | - ResourceId dirId = mock(ResourceId.class); |
430 | | - when(dirId.toString()).thenReturn((String) dir); |
431 | | - when(resourceId.getCurrentDirectory()).thenReturn(dirId); |
432 | | - } else if (dir instanceof ResourceId) { |
433 | | - when(resourceId.getCurrentDirectory()).thenReturn((ResourceId) dir); |
434 | | - } |
435 | | - return resourceId; |
436 | | - } |
437 | | - |
438 | 340 | private static List<ResourceId> toResourceIds(List<Path> paths, final boolean isDirectory) { |
439 | 341 | return FluentIterable.from(paths) |
440 | 342 | .transform(path -> (ResourceId) LocalResourceId.fromPath(path, isDirectory)) |
|
0 commit comments