-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Deflake PreCommit Java watchForNewFiles #38320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Abacn
wants to merge
1
commit into
apache:master
Choose a base branch
from
Abacn:deflake
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−40
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -273,7 +273,7 @@ public void processElement(ProcessContext context, @StateId("count") ValueState< | |
|
|
||
| @Test | ||
| @Category({NeedsRunner.class, UsesUnboundedSplittableParDo.class}) | ||
| public void testMatchWatchForNewFiles() throws IOException, InterruptedException { | ||
| public void testMatchWatchForNewFiles() throws IOException { | ||
| // Write some files to a "source" directory. | ||
| final Path sourcePath = tmpFolder.getRoot().toPath().resolve("source"); | ||
| sourcePath.toFile().mkdir(); | ||
|
|
@@ -292,23 +292,7 @@ public void testMatchWatchForNewFiles() throws IOException, InterruptedException | |
| .continuously( | ||
| Duration.millis(100), | ||
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)))); | ||
| PCollection<MatchResult.Metadata> matchAllMetadata = | ||
| p.apply("create for matchAll new files", Create.of(watchPath.resolve("*").toString())) | ||
| .apply( | ||
| "match filename through matchAll", | ||
| FileIO.matchAll() | ||
| .continuously( | ||
| Duration.millis(100), | ||
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)))); | ||
| PCollection<MatchResult.Metadata> matchUpdatedMetadata = | ||
| p.apply( | ||
| "match updated", | ||
| FileIO.match() | ||
| .filepattern(watchPath.resolve("first").toString()) | ||
| .continuously( | ||
| Duration.millis(100), | ||
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)), | ||
| true)); | ||
|
|
||
| PCollection<MatchResult.Metadata> matchAllUpdatedMetadata = | ||
| p.apply("create for matchAll updated files", Create.of(watchPath.resolve("*").toString())) | ||
| .apply( | ||
|
|
@@ -319,7 +303,7 @@ public void testMatchWatchForNewFiles() throws IOException, InterruptedException | |
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)), | ||
| true)); | ||
|
|
||
| // write one file at the beginning. This will trigger the first output for matchAll | ||
| // write one file at the beginning. This will trigger the first output for matchMetadata | ||
| Files.copy( | ||
| sourcePath.resolve("first"), | ||
| watchPath.resolve("first"), | ||
|
|
@@ -337,8 +321,6 @@ public void testMatchWatchForNewFiles() throws IOException, InterruptedException | |
| .apply(ParDo.of(new CopyFilesFn(sourcePath, watchPath))); | ||
|
|
||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchMetadata.isBounded()); | ||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchAllMetadata.isBounded()); | ||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchUpdatedMetadata.isBounded()); | ||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchAllUpdatedMetadata.isBounded()); | ||
|
|
||
| // We fetch lastModifiedTime from the files in the "source" directory to avoid a race condition | ||
|
|
@@ -352,15 +334,6 @@ public void testMatchWatchForNewFiles() throws IOException, InterruptedException | |
| metadata( | ||
| watchPath.resolve("third"), 99, lastModifiedMillis(sourcePath.resolve("third")))); | ||
| PAssert.that(matchMetadata).containsInAnyOrder(expectedMatchNew); | ||
| PAssert.that(matchAllMetadata).containsInAnyOrder(expectedMatchNew); | ||
|
|
||
| List<String> expectedMatchUpdated = Arrays.asList("first", "first", "first"); | ||
| PCollection<String> matchUpdatedCount = | ||
| matchUpdatedMetadata.apply( | ||
| "pick up match file name", | ||
| MapElements.into(TypeDescriptors.strings()) | ||
| .via((metadata) -> metadata.resourceId().getFilename())); | ||
| PAssert.that(matchUpdatedCount).containsInAnyOrder(expectedMatchUpdated); | ||
|
|
||
| // Check watch for file updates. Compare only filename since modified time of copied files are | ||
| // uncontrolled. | ||
|
|
@@ -376,6 +349,35 @@ public void testMatchWatchForNewFiles() throws IOException, InterruptedException | |
| p.run(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMatchWatchForNewFiles_UnboundedPCollection() { | ||
| // Additional scenarios for testMatchWatchForNewFiles. Only construct the pipeline and check | ||
| // output pcoll | ||
| final Path watchPath = tmpFolder.getRoot().toPath().resolve("watch"); | ||
|
|
||
| PCollection<MatchResult.Metadata> matchAllMetadata = | ||
| p.apply("create for matchAll new files", Create.of(watchPath + "/*")) | ||
| .apply( | ||
| "match filename through matchAll", | ||
| FileIO.matchAll() | ||
| .continuously( | ||
| Duration.millis(100), | ||
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)))); | ||
|
|
||
| PCollection<MatchResult.Metadata> matchUpdatedMetadata = | ||
| p.apply( | ||
| "match updated", | ||
| FileIO.match() | ||
| .filepattern(watchPath.resolve("first").toString()) | ||
| .continuously( | ||
| Duration.millis(100), | ||
| Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)), | ||
| true)); | ||
|
|
||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchAllMetadata.isBounded()); | ||
| assertEquals(PCollection.IsBounded.UNBOUNDED, matchUpdatedMetadata.isBounded()); | ||
| } | ||
|
Comment on lines
+353
to
+379
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new test method has two significant issues:
Here is the corrected method: public void testMatchWatchForNewFiles_UnboundedPCollection() {
// Additional scenarios for testMatchWatchForNewFiles. Only construct the pipeline and check
// output pcoll
p.enableAbandonedNodeEnforcement(false);
final Path watchPath = tmpFolder.getRoot().toPath().resolve("watch");
PCollection<MatchResult.Metadata> matchAllMetadata =
p.apply("create for matchAll new files", Create.of(watchPath.resolve("*").toString()))
.apply(
"match filename through matchAll",
FileIO.matchAll()
.continuously(
Duration.millis(100),
Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1))));
PCollection<MatchResult.Metadata> matchUpdatedMetadata =
p.apply(
"match updated",
FileIO.match()
.filepattern(watchPath.resolve("first").toString())
.continuously(
Duration.millis(100),
Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(1)),
true));
assertEquals(PCollection.IsBounded.UNBOUNDED, matchAllMetadata.isBounded());
assertEquals(PCollection.IsBounded.UNBOUNDED, matchUpdatedMetadata.isBounded());
} |
||
|
|
||
| @Test | ||
| @Category(NeedsRunner.class) | ||
| public void testRead() throws IOException { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.