This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch feat/WW-5864-struts-maven-plugin-watch in repository https://gitbox.apache.org/repos/asf/struts.git
commit 4ae6d976eb9d83182a7c35a7f96496dcbc930a88 Author: Lukasz Lenart <[email protected]> AuthorDate: Sat Nov 14 08:40:44 2026 +0100 WW-5864 feat(tools): scan resource roots and debounce changes Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --- .../org/apache/struts2/maven/watch/FileStamp.java | 22 +++ .../apache/struts2/maven/watch/ResourcePusher.java | 28 +++ .../struts2/maven/watch/ResourceScanner.java | 61 +++++++ .../struts2/maven/watch/ResourceWatcher.java | 141 +++++++++++++++ .../org/apache/struts2/maven/watch/SourceFile.java | 22 +++ .../apache/struts2/maven/watch/WatchedRoot.java | 37 ++++ .../struts2/maven/watch/ResourceScannerTest.java | 98 +++++++++++ .../struts2/maven/watch/ResourceWatcherTest.java | 194 +++++++++++++++++++++ 8 files changed, 603 insertions(+) diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/FileStamp.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/FileStamp.java new file mode 100644 index 000000000..d8aa7196f --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/FileStamp.java @@ -0,0 +1,22 @@ +/* + * 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.struts2.maven.watch; + +public record FileStamp(long lastModified, long size) { +} diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcePusher.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcePusher.java new file mode 100644 index 000000000..132860705 --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourcePusher.java @@ -0,0 +1,28 @@ +/* + * 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.struts2.maven.watch; + +import java.io.IOException; + +public interface ResourcePusher { + + void push(SourceFile file) throws IOException; + + void delete(SourceFile file) throws IOException; +} diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceScanner.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceScanner.java new file mode 100644 index 000000000..7d84ce612 --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceScanner.java @@ -0,0 +1,61 @@ +/* + * 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.struts2.maven.watch; + +import org.codehaus.plexus.util.DirectoryScanner; + +import java.io.File; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class ResourceScanner { + + private final List<WatchedRoot> roots; + private final boolean addDefaultExcludes; + + public ResourceScanner(List<WatchedRoot> roots, boolean addDefaultExcludes) { + this.roots = List.copyOf(roots); + this.addDefaultExcludes = addDefaultExcludes; + } + + public Map<SourceFile, FileStamp> scan() { + Map<SourceFile, FileStamp> result = new LinkedHashMap<>(); + for (WatchedRoot root : roots) { + File directory = root.directory().toFile(); + if (!directory.isDirectory()) { + continue; + } + DirectoryScanner scanner = new DirectoryScanner(); + scanner.setBasedir(directory); + scanner.setIncludes(root.includes().isEmpty() ? new String[]{"**/**"} + : root.includes().toArray(new String[0])); + scanner.setExcludes(root.excludes().toArray(new String[0])); + if (addDefaultExcludes) { + scanner.addDefaultExcludes(); + } + scanner.scan(); + for (String relativePath : scanner.getIncludedFiles()) { + File file = new File(directory, relativePath); + result.put(new SourceFile(root, relativePath), new FileStamp(file.lastModified(), file.length())); + } + } + return result; + } +} diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceWatcher.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceWatcher.java new file mode 100644 index 000000000..49c33d85c --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/ResourceWatcher.java @@ -0,0 +1,141 @@ +/* + * 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.struts2.maven.watch; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.function.BooleanSupplier; +import java.util.function.Consumer; + +public class ResourceWatcher { + + private final ResourceScanner scanner; + private final ResourcePusher pusher; + private final List<Path> filterFiles; + private final Consumer<String> info; + private final BiConsumer<String, Exception> error; + + private Map<SourceFile, FileStamp> previous = Map.of(); + private Map<SourceFile, FileStamp> acted = Map.of(); + private Map<Path, FileStamp> previousFilterStamps = Map.of(); + private Map<Path, FileStamp> actedFilterStamps = Map.of(); + + public ResourceWatcher(ResourceScanner scanner, ResourcePusher pusher, List<Path> filterFiles, + Consumer<String> info, BiConsumer<String, Exception> error) { + this.scanner = scanner; + this.pusher = pusher; + this.filterFiles = List.copyOf(filterFiles); + this.info = info; + this.error = error; + } + + public void start() { + previous = scanner.scan(); + acted = previous; + previousFilterStamps = filterStamps(); + actedFilterStamps = previousFilterStamps; + } + + public void pollOnce() { + Map<SourceFile, FileStamp> current = scanner.scan(); + Map<Path, FileStamp> currentFilterStamps = filterStamps(); + Set<SourceFile> handled = new HashSet<>(); + + Set<SourceFile> paths = new HashSet<>(current.keySet()); + paths.addAll(previous.keySet()); + paths.addAll(acted.keySet()); + Map<SourceFile, FileStamp> nextActed = new HashMap<>(acted); + for (SourceFile file : paths) { + FileStamp now = current.get(file); + if (Objects.equals(now, previous.get(file)) && !Objects.equals(now, acted.get(file))) { + if (now == null) { + nextActed.remove(file); + delete(file); + } else { + nextActed.put(file, now); + push(file); + handled.add(file); + } + } + } + + if (currentFilterStamps.equals(previousFilterStamps) && !currentFilterStamps.equals(actedFilterStamps)) { + actedFilterStamps = currentFilterStamps; + for (SourceFile file : current.keySet()) { + if (file.root().filtering() && !handled.contains(file)) { + push(file); + } + } + } + + acted = nextActed; + previous = current; + previousFilterStamps = currentFilterStamps; + } + + public void run(Duration interval, BooleanSupplier keepRunning) { + while (keepRunning.getAsBoolean()) { + pollOnce(); + try { + Thread.sleep(interval.toMillis()); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return; + } + } + } + + private void push(SourceFile file) { + try { + pusher.push(file); + info.accept("Pushed " + file.relativePath()); + } catch (IOException | RuntimeException e) { + error.accept("Failed to push " + file.relativePath(), e); + } + } + + private void delete(SourceFile file) { + try { + pusher.delete(file); + info.accept("Deleted " + file.relativePath()); + } catch (IOException | RuntimeException e) { + error.accept("Failed to delete " + file.relativePath(), e); + } + } + + private Map<Path, FileStamp> filterStamps() { + Map<Path, FileStamp> stamps = new HashMap<>(); + for (Path path : filterFiles) { + File file = path.toFile(); + if (file.isFile()) { + stamps.put(path, new FileStamp(file.lastModified(), file.length())); + } + } + return stamps; + } +} diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/SourceFile.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/SourceFile.java new file mode 100644 index 000000000..16b95b1c6 --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/SourceFile.java @@ -0,0 +1,22 @@ +/* + * 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.struts2.maven.watch; + +public record SourceFile(WatchedRoot root, String relativePath) { +} diff --git a/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchedRoot.java b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchedRoot.java new file mode 100644 index 000000000..68b8194ab --- /dev/null +++ b/tools/struts-maven-plugin/src/main/java/org/apache/struts2/maven/watch/WatchedRoot.java @@ -0,0 +1,37 @@ +/* + * 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.struts2.maven.watch; + +import org.apache.maven.model.Resource; + +import java.nio.file.Path; +import java.util.List; + +public record WatchedRoot(Path directory, List<String> includes, List<String> excludes, String targetPath, + boolean filtering) { + + public static WatchedRoot of(Resource resource, Path basedir) { + return new WatchedRoot( + basedir.resolve(resource.getDirectory()), + List.copyOf(resource.getIncludes()), + List.copyOf(resource.getExcludes()), + resource.getTargetPath(), + resource.isFiltering()); + } +} diff --git a/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceScannerTest.java b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceScannerTest.java new file mode 100644 index 000000000..93d9a734e --- /dev/null +++ b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceScannerTest.java @@ -0,0 +1,98 @@ +/* + * 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.struts2.maven.watch; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ResourceScannerTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + private WatchedRoot root(Path dir, List<String> includes, List<String> excludes) { + return new WatchedRoot(dir, includes, excludes, null, false); + } + + private Set<String> paths(Map<SourceFile, FileStamp> scan) { + return scan.keySet().stream().map(SourceFile::relativePath) + .map(p -> p.replace(File.separatorChar, '/')).collect(Collectors.toSet()); + } + + @Test + public void listsFilesHonouringIncludesAndExcludes() throws Exception { + Path dir = temp.newFolder("res").toPath(); + Files.createDirectories(dir.resolve("sub")); + Files.writeString(dir.resolve("a.properties"), "a=1"); + Files.writeString(dir.resolve("sub/b.properties"), "b=1"); + Files.writeString(dir.resolve("c.txt"), "c"); + Files.writeString(dir.resolve("sub/skip.properties"), "s"); + + ResourceScanner scanner = new ResourceScanner( + List.of(root(dir, List.of("**/*.properties"), List.of("**/skip.*"))), true); + + Map<SourceFile, FileStamp> scan = scanner.scan(); + + assertThat(paths(scan)).containsExactlyInAnyOrder("a.properties", "sub/b.properties"); + assertThat(scan.get(new SourceFile(root(dir, List.of("**/*.properties"), List.of("**/skip.*")), "a.properties")).size()) + .isEqualTo(3); + } + + @Test + public void emptyIncludesMeansEverything() throws Exception { + Path dir = temp.newFolder("res").toPath(); + Files.writeString(dir.resolve("a.txt"), "a"); + Files.writeString(dir.resolve("b.xml"), "b"); + + ResourceScanner scanner = new ResourceScanner(List.of(root(dir, List.of(), List.of())), true); + + assertThat(paths(scanner.scan())).containsExactlyInAnyOrder("a.txt", "b.xml"); + } + + @Test + public void skipsDefaultExcludesWhenEnabled() throws Exception { + Path dir = temp.newFolder("res").toPath(); + Files.writeString(dir.resolve("a.txt"), "a"); + Files.writeString(dir.resolve(".DS_Store"), "x"); + Files.writeString(dir.resolve("a.txt~"), "x"); + + assertThat(paths(new ResourceScanner(List.of(root(dir, List.of(), List.of())), true).scan())) + .containsExactly("a.txt"); + assertThat(paths(new ResourceScanner(List.of(root(dir, List.of(), List.of())), false).scan())) + .contains("a.txt", ".DS_Store", "a.txt~"); + } + + @Test + public void missingRootDirectoryYieldsNoFiles() { + Path dir = temp.getRoot().toPath().resolve("absent"); + + assertThat(new ResourceScanner(List.of(root(dir, List.of(), List.of())), true).scan()).isEmpty(); + } +} diff --git a/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceWatcherTest.java b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceWatcherTest.java new file mode 100644 index 000000000..36f7d2af9 --- /dev/null +++ b/tools/struts-maven-plugin/src/test/java/org/apache/struts2/maven/watch/ResourceWatcherTest.java @@ -0,0 +1,194 @@ +/* + * 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.struts2.maven.watch; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.Duration; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ResourceWatcherTest { + + @Rule + public TemporaryFolder temp = new TemporaryFolder(); + + private final WatchedRoot plain = new WatchedRoot(Path.of("plain"), List.of(), List.of(), null, false); + private final WatchedRoot filtered = new WatchedRoot(Path.of("filtered"), List.of(), List.of(), null, true); + + private final List<String> pushed = new ArrayList<>(); + private final List<String> deleted = new ArrayList<>(); + private final List<String> errors = new ArrayList<>(); + private final List<String> failOn = new ArrayList<>(); + + private final ResourcePusher pusher = new ResourcePusher() { + @Override + public void push(SourceFile file) throws IOException { + if (failOn.contains(file.relativePath())) { + throw new IOException("boom " + file.relativePath()); + } + pushed.add(file.relativePath()); + } + + @Override + public void delete(SourceFile file) { + deleted.add(file.relativePath()); + } + }; + + private static class FakeScanner extends ResourceScanner { + private final Deque<Map<SourceFile, FileStamp>> scans = new ArrayDeque<>(); + + FakeScanner() { + super(List.of(), true); + } + + FakeScanner add(Map<SourceFile, FileStamp> scan) { + scans.add(scan); + return this; + } + + @Override + public Map<SourceFile, FileStamp> scan() { + return scans.size() > 1 ? scans.poll() : scans.peek(); + } + } + + private Map<SourceFile, FileStamp> scan(WatchedRoot root, Object... pathAndStamp) { + Map<SourceFile, FileStamp> result = new LinkedHashMap<>(); + for (int i = 0; i < pathAndStamp.length; i += 2) { + result.put(new SourceFile(root, (String) pathAndStamp[i]), + new FileStamp(((Number) pathAndStamp[i + 1]).longValue(), 1)); + } + return result; + } + + private ResourceWatcher watcher(FakeScanner scanner, List<Path> filterFiles) { + return new ResourceWatcher(scanner, pusher, filterFiles, m -> { }, (m, e) -> errors.add(m)); + } + + private void drive(ResourceWatcher watcher, int polls) { + watcher.start(); + for (int i = 0; i < polls; i++) { + watcher.pollOnce(); + } + } + + @Test + public void changeIsPushedOnceAfterTwoStableScans() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)).add(scan(plain, "a", 2)); + drive(watcher(scanner, List.of()), 3); + + assertThat(pushed).containsExactly("a"); + assertThat(deleted).isEmpty(); + } + + @Test + public void changeIsNotPushedAfterOnlyOneScan() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)).add(scan(plain, "a", 2)); + drive(watcher(scanner, List.of()), 1); + + assertThat(pushed).isEmpty(); + } + + @Test + public void deletionIsMirroredAfterTwoStableScans() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)).add(scan(plain)); + drive(watcher(scanner, List.of()), 2); + + assertThat(deleted).containsExactly("a"); + assertThat(pushed).isEmpty(); + } + + @Test + public void deleteFollowedByRecreateBeforeStableIsAPushNotADelete() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)).add(scan(plain)) + .add(scan(plain, "a", 2)); + drive(watcher(scanner, List.of()), 3); + + assertThat(deleted).isEmpty(); + assertThat(pushed).containsExactly("a"); + } + + @Test + public void unchangedFilesAreNeverPushed() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)); + drive(watcher(scanner, List.of()), 3); + + assertThat(pushed).isEmpty(); + assertThat(deleted).isEmpty(); + } + + @Test + public void filterFileChangeRepushesFilteredResourcesOnly() throws Exception { + Path filterFile = temp.newFile("filter.properties").toPath(); + Files.writeString(filterFile, "k=v"); + Map<SourceFile, FileStamp> files = scan(filtered, "f", 1); + files.putAll(scan(plain, "u", 1)); + FakeScanner scanner = new FakeScanner().add(files); + ResourceWatcher watcher = watcher(scanner, List.of(filterFile)); + watcher.start(); + + Files.writeString(filterFile, "k=changed-longer"); + watcher.pollOnce(); + assertThat(pushed).isEmpty(); + watcher.pollOnce(); + + assertThat(pushed).containsExactly("f"); + watcher.pollOnce(); + assertThat(pushed).containsExactly("f"); + } + + @Test + public void pusherFailureIsReportedAndWatchingContinues() { + failOn.add("a"); + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1, "b", 1)) + .add(scan(plain, "a", 2, "b", 1)).add(scan(plain, "a", 2, "b", 2)) + .add(scan(plain, "a", 2, "b", 2)); + drive(watcher(scanner, List.of()), 3); + + assertThat(errors).hasSize(1); + assertThat(errors.get(0)).contains("a"); + assertThat(pushed).containsExactly("b"); + } + + @Test + public void runStopsWhenKeepRunningTurnsFalse() { + FakeScanner scanner = new FakeScanner().add(scan(plain, "a", 1)); + ResourceWatcher watcher = watcher(scanner, List.of()); + AtomicInteger remaining = new AtomicInteger(3); + watcher.start(); + + watcher.run(Duration.ofMillis(10), () -> remaining.decrementAndGet() >= 0); + + assertThat(remaining.get()).isNegative(); + } +}
