valepakh commented on code in PR #6556:
URL: https://github.com/apache/ignite-3/pull/6556#discussion_r2330194215


##########
modules/code-deployment/src/testFixtures/java/org/apache/ignite/internal/deployment/UnitStatusMatchers.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.ignite.internal.deployment;
+
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentStatus;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.UnitStatuses;
+import org.apache.ignite.internal.deployunit.UnitVersionStatus;
+import org.hamcrest.Description;
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Matchers for {@link UnitStatus} and {@link UnitStatuses}.
+ */
+public class UnitStatusMatchers {
+    /**
+     * Matches replication info with a specified fst progress.
+     */
+    public static Matcher<UnitStatus> versionIs(Version version) {
+        return replicationInfoMatcher(UnitStatus::version, version, "version");
+    }
+
+    public static Matcher<UnitStatus> deploymentStatusIs(DeploymentStatus 
status) {
+        return replicationInfoMatcher(UnitStatus::status, status, "status");
+    }
+
+    /**
+     * Matcher fo
+     */
+    public static Matcher<UnitVersionStatus> unitVersionStatusIs(Version 
version, DeploymentStatus status) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("unitVersionStatus is 
").appendValue(version)
+                        .appendText(", status is ").appendValue(status);
+            }
+
+            @Override
+            protected boolean matchesSafely(UnitVersionStatus item) {
+                return item.getStatus() == status && 
Objects.equals(item.getVersion(), version);
+            }
+        };
+    }
+
+    public static Matcher<UnitStatuses> 
containsAll(Matcher<UnitVersionStatus>... unitVersionMatcher) {

Review Comment:
   Can this be replaced with `hasItems`?



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/StaticUnitDeployer.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.ignite.internal.deployunit;
+
+import static java.util.Collections.emptyList;
+import static org.apache.ignite.deployment.version.Version.parseVersion;
+import static org.apache.ignite.internal.deployunit.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.deployment.version.Version;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException;
+import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitStore;
+import org.apache.ignite.internal.deployunit.metastore.status.UnitNodeStatus;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.jetbrains.annotations.NotNull;

Review Comment:
   ```suggestion
   ```



##########
modules/code-deployment/src/testFixtures/java/org/apache/ignite/internal/deployment/UnitStatusMatchers.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.ignite.internal.deployment;
+
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentStatus;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.UnitStatuses;
+import org.apache.ignite.internal.deployunit.UnitVersionStatus;
+import org.hamcrest.Description;
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Matchers for {@link UnitStatus} and {@link UnitStatuses}.
+ */
+public class UnitStatusMatchers {
+    /**
+     * Matches replication info with a specified fst progress.
+     */
+    public static Matcher<UnitStatus> versionIs(Version version) {
+        return replicationInfoMatcher(UnitStatus::version, version, "version");
+    }
+
+    public static Matcher<UnitStatus> deploymentStatusIs(DeploymentStatus 
status) {
+        return replicationInfoMatcher(UnitStatus::status, status, "status");
+    }
+
+    /**
+     * Matcher fo
+     */
+    public static Matcher<UnitVersionStatus> unitVersionStatusIs(Version 
version, DeploymentStatus status) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("unitVersionStatus is 
").appendValue(version)
+                        .appendText(", status is ").appendValue(status);
+            }
+
+            @Override
+            protected boolean matchesSafely(UnitVersionStatus item) {
+                return item.getStatus() == status && 
Objects.equals(item.getVersion(), version);
+            }
+        };
+    }
+
+    public static Matcher<UnitStatuses> 
containsAll(Matcher<UnitVersionStatus>... unitVersionMatcher) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            protected boolean matchesSafely(UnitStatuses item) {
+                for (UnitVersionStatus versionStatus : item.versionStatuses()) 
{
+                    for (Matcher<UnitVersionStatus> unitVersionStatus : 
unitVersionMatcher) {
+                        if (unitVersionStatus.matches(versionStatus)) {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("a list containing elements matching: 
");
+                for (int i = 0; i < unitVersionMatcher.length; i++) {
+                    if (i > 0) {
+                        description.appendText(", ");
+                    }
+                    unitVersionMatcher[i].describeTo(description);
+                }
+            }
+        };
+    }
+
+    private static <T> Matcher<UnitStatus> replicationInfoMatcher(

Review Comment:
   This is definitely not a replication info matcher. The javadocs should also 
be adjusted.



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/StaticUnitDeployer.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.ignite.internal.deployunit;
+
+import static java.util.Collections.emptyList;
+import static org.apache.ignite.deployment.version.Version.parseVersion;
+import static org.apache.ignite.internal.deployunit.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.deployment.version.Version;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException;
+import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitStore;
+import org.apache.ignite.internal.deployunit.metastore.status.UnitNodeStatus;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Observes a predefined directory with statically provisioned deployment 
units and
+ * registers their presence in the deployment store.
+ *
+ * <p>The observer scans the {@code deploymentUnitsRoot} directory, expecting 
the following structure:
+ * {@code <unitId>/<version>/}
+ * For every discovered {@code unitId}-{@code version} pair that is not yet 
registered for this node,
+ * the observer creates (or reuses) a cluster status and then creates the node 
status marked as
+ * {@link DeploymentStatus#DEPLOYED}.
+ */
+public class StaticUnitDeployer {
+    private static final IgniteLogger LOG = 
Loggers.forClass(StaticUnitDeployer.class);
+
+    private final DeploymentUnitStore deploymentUnitStore;
+
+    private final String nodeName;
+
+    private final Path deploymentUnitsRoot;
+
+    /**
+     * Constructor.
+     */
+    public StaticUnitDeployer(
+            DeploymentUnitStore deploymentUnitStore,
+            String nodeName,
+            Path deploymentUnitsRoot
+    ) {
+        this.deploymentUnitStore = deploymentUnitStore;
+        this.nodeName = nodeName;
+        this.deploymentUnitsRoot = deploymentUnitsRoot;
+    }
+
+    /**
+     * Scans the filesystem for statically deployed units and registers their 
cluster and node statuses
+     * if they are not yet present in the store.
+     *
+     * <p>Already registered unit versions for this node are skipped. New ones 
are registered as DEPLOYED.
+     */
+    public CompletableFuture<Void> searchAndDeployStaticUnits() {
+        LOG.info("Start search static deployment units.");
+        Map<String, List<Version>> allUnits = collectStaticUnits();
+
+        return 
deploymentUnitStore.getNodeStatuses(nodeName).thenCompose(statuses -> {
+            List<CompletableFuture<?>> futures = new ArrayList<>();
+
+            for (UnitNodeStatus status : statuses) {
+                allUnits.get(status.id()).remove(status.version());
+                if (allUnits.get(status.id()).isEmpty()) {
+                    allUnits.remove(status.id());
+                }
+            }
+
+            allUnits.forEach((id, versions) -> {
+                versions.forEach(version -> {
+                    LOG.info("Start processing unit {}:{}", id, version);
+                    CompletableFuture<Boolean> future = 
deploymentUnitStore.createClusterStatus(id, version, Set.of(nodeName))
+                            .thenCompose(status -> {
+                                if (status == null) {
+                                    return 
deploymentUnitStore.getClusterStatus(id, version).thenCompose(it ->
+                                            
deploymentUnitStore.createNodeStatus(nodeName, id, version, it.opId(), DEPLOYED)
+                                    );
+                                } else {
+                                    return 
deploymentUnitStore.createNodeStatus(nodeName, id, version, status.opId(), 
DEPLOYED);
+                                }
+                            })
+                            .whenComplete((result, t) ->
+                                    LOG.info("Finished static status creating 
{}:{} with result {}", t, id, version, result)
+                            );
+                    futures.add(future);
+                });
+            });
+
+            return allOf(futures);
+        });
+    }
+
+    private Map<String, List<Version>> collectStaticUnits() {
+        Map<String, List<Version>> units = new HashMap<>();
+        List<Path> unitFolders = allSubdirectories(deploymentUnitsRoot);
+        for (Path unitFolder : unitFolders) {
+            List<Path> versions = allSubdirectories(unitFolder);
+            units.put(
+                    unitFolder.getFileName().toString(),
+                    versions.stream()
+                            .map(versionFolder -> 
parseVersion(versionFolder.getFileName().toString()))
+                            .collect(
+                                    ArrayList::new,
+                                    ArrayList::add,
+                                    ArrayList::addAll
+                            )
+            );
+        }
+        return units;
+    }
+
+    private static List<Path> allSubdirectories(Path folder) {
+        List<Path> subfolders = new ArrayList<>();
+        if (Files.notExists(folder)) {
+            return emptyList();
+        }
+        try {
+            Files.walkFileTree(folder, Set.of(), 1, new SimpleFileVisitor<>() {
+                @Override
+                public @NotNull FileVisitResult visitFile(@NotNull Path file, 
@NotNull BasicFileAttributes attrs) throws IOException {

Review Comment:
   ```suggestion
                   public FileVisitResult visitFile(Path file, 
BasicFileAttributes attrs) throws IOException {
   ```



##########
modules/code-deployment/src/testFixtures/java/org/apache/ignite/internal/deployment/UnitStatusMatchers.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.ignite.internal.deployment;
+
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentStatus;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.UnitStatuses;
+import org.apache.ignite.internal.deployunit.UnitVersionStatus;
+import org.hamcrest.Description;
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Matchers for {@link UnitStatus} and {@link UnitStatuses}.
+ */
+public class UnitStatusMatchers {
+    /**
+     * Matches replication info with a specified fst progress.
+     */
+    public static Matcher<UnitStatus> versionIs(Version version) {
+        return replicationInfoMatcher(UnitStatus::version, version, "version");
+    }
+
+    public static Matcher<UnitStatus> deploymentStatusIs(DeploymentStatus 
status) {
+        return replicationInfoMatcher(UnitStatus::status, status, "status");
+    }
+
+    /**
+     * Matcher fo
+     */
+    public static Matcher<UnitVersionStatus> unitVersionStatusIs(Version 
version, DeploymentStatus status) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("unitVersionStatus is 
").appendValue(version)
+                        .appendText(", status is ").appendValue(status);
+            }
+
+            @Override
+            protected boolean matchesSafely(UnitVersionStatus item) {
+                return item.getStatus() == status && 
Objects.equals(item.getVersion(), version);
+            }
+        };
+    }
+
+    public static Matcher<UnitStatuses> 
containsAll(Matcher<UnitVersionStatus>... unitVersionMatcher) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            protected boolean matchesSafely(UnitStatuses item) {
+                for (UnitVersionStatus versionStatus : item.versionStatuses()) 
{
+                    for (Matcher<UnitVersionStatus> unitVersionStatus : 
unitVersionMatcher) {
+                        if (unitVersionStatus.matches(versionStatus)) {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("a list containing elements matching: 
");
+                for (int i = 0; i < unitVersionMatcher.length; i++) {
+                    if (i > 0) {
+                        description.appendText(", ");
+                    }
+                    unitVersionMatcher[i].describeTo(description);
+                }
+            }
+        };
+    }
+
+    private static <T> Matcher<UnitStatus> replicationInfoMatcher(
+            Function<UnitStatus, T> extractor,
+            T actual,
+            String featureName
+    ) {
+        return new FeatureMatcher<>(is(actual), "unit status with " + 
featureName, featureName) {
+            @Override
+            protected T featureValueOf(UnitStatus actual) {
+                return extractor.apply(actual);
+            }
+        };
+    }
+
+    /**
+     * Matches that any item from list match with all provided matchers.
+     */
+    public static <T extends UnitStatus> Matcher<List<T>> 
any(Matcher<UnitStatus>... matchers) {

Review Comment:
   I wonder why this is needed, `hasItems` does basically the same?



##########
modules/code-deployment/src/main/java/org/apache/ignite/internal/deployunit/StaticUnitDeployer.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.ignite.internal.deployunit;
+
+import static java.util.Collections.emptyList;
+import static org.apache.ignite.deployment.version.Version.parseVersion;
+import static org.apache.ignite.internal.deployunit.DeploymentStatus.DEPLOYED;
+import static org.apache.ignite.internal.util.CompletableFutures.allOf;
+
+import java.io.IOException;
+import java.nio.file.FileVisitResult;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.deployment.version.Version;
+import 
org.apache.ignite.internal.deployunit.exception.DeploymentUnitReadException;
+import org.apache.ignite.internal.deployunit.metastore.DeploymentUnitStore;
+import org.apache.ignite.internal.deployunit.metastore.status.UnitNodeStatus;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Observes a predefined directory with statically provisioned deployment 
units and
+ * registers their presence in the deployment store.
+ *
+ * <p>The observer scans the {@code deploymentUnitsRoot} directory, expecting 
the following structure:
+ * {@code <unitId>/<version>/}
+ * For every discovered {@code unitId}-{@code version} pair that is not yet 
registered for this node,
+ * the observer creates (or reuses) a cluster status and then creates the node 
status marked as
+ * {@link DeploymentStatus#DEPLOYED}.
+ */
+public class StaticUnitDeployer {
+    private static final IgniteLogger LOG = 
Loggers.forClass(StaticUnitDeployer.class);
+
+    private final DeploymentUnitStore deploymentUnitStore;
+
+    private final String nodeName;
+
+    private final Path deploymentUnitsRoot;
+
+    /**
+     * Constructor.
+     */
+    public StaticUnitDeployer(
+            DeploymentUnitStore deploymentUnitStore,
+            String nodeName,
+            Path deploymentUnitsRoot
+    ) {
+        this.deploymentUnitStore = deploymentUnitStore;
+        this.nodeName = nodeName;
+        this.deploymentUnitsRoot = deploymentUnitsRoot;
+    }
+
+    /**
+     * Scans the filesystem for statically deployed units and registers their 
cluster and node statuses
+     * if they are not yet present in the store.
+     *
+     * <p>Already registered unit versions for this node are skipped. New ones 
are registered as DEPLOYED.
+     */
+    public CompletableFuture<Void> searchAndDeployStaticUnits() {
+        LOG.info("Start search static deployment units.");
+        Map<String, List<Version>> allUnits = collectStaticUnits();
+
+        return 
deploymentUnitStore.getNodeStatuses(nodeName).thenCompose(statuses -> {
+            List<CompletableFuture<?>> futures = new ArrayList<>();
+
+            for (UnitNodeStatus status : statuses) {
+                allUnits.get(status.id()).remove(status.version());
+                if (allUnits.get(status.id()).isEmpty()) {
+                    allUnits.remove(status.id());
+                }
+            }
+
+            allUnits.forEach((id, versions) -> {
+                versions.forEach(version -> {
+                    LOG.info("Start processing unit {}:{}", id, version);
+                    CompletableFuture<Boolean> future = 
deploymentUnitStore.createClusterStatus(id, version, Set.of(nodeName))
+                            .thenCompose(status -> {
+                                if (status == null) {
+                                    return 
deploymentUnitStore.getClusterStatus(id, version).thenCompose(it ->
+                                            
deploymentUnitStore.createNodeStatus(nodeName, id, version, it.opId(), DEPLOYED)
+                                    );
+                                } else {
+                                    return 
deploymentUnitStore.createNodeStatus(nodeName, id, version, status.opId(), 
DEPLOYED);
+                                }
+                            })
+                            .whenComplete((result, t) ->
+                                    LOG.info("Finished static status creating 
{}:{} with result {}", t, id, version, result)
+                            );
+                    futures.add(future);
+                });
+            });
+
+            return allOf(futures);
+        });
+    }
+
+    private Map<String, List<Version>> collectStaticUnits() {
+        Map<String, List<Version>> units = new HashMap<>();
+        List<Path> unitFolders = allSubdirectories(deploymentUnitsRoot);
+        for (Path unitFolder : unitFolders) {
+            List<Path> versions = allSubdirectories(unitFolder);
+            units.put(
+                    unitFolder.getFileName().toString(),
+                    versions.stream()
+                            .map(versionFolder -> 
parseVersion(versionFolder.getFileName().toString()))
+                            .collect(
+                                    ArrayList::new,
+                                    ArrayList::add,
+                                    ArrayList::addAll
+                            )

Review Comment:
   ```suggestion
                               .collect(Collectors.toCollection(ArrayList::new))
   ```
   But I still think that checking in the loop in the caller is a better idea



##########
modules/code-deployment/src/testFixtures/java/org/apache/ignite/internal/deployment/UnitStatusMatchers.java:
##########
@@ -0,0 +1,170 @@
+/*
+ * 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.ignite.internal.deployment;
+
+import static org.hamcrest.Matchers.is;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+import org.apache.ignite.deployment.version.Version;
+import org.apache.ignite.internal.deployunit.DeploymentStatus;
+import org.apache.ignite.internal.deployunit.UnitStatus;
+import org.apache.ignite.internal.deployunit.UnitStatuses;
+import org.apache.ignite.internal.deployunit.UnitVersionStatus;
+import org.hamcrest.Description;
+import org.hamcrest.FeatureMatcher;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+
+/**
+ * Matchers for {@link UnitStatus} and {@link UnitStatuses}.
+ */
+public class UnitStatusMatchers {
+    /**
+     * Matches replication info with a specified fst progress.
+     */
+    public static Matcher<UnitStatus> versionIs(Version version) {
+        return replicationInfoMatcher(UnitStatus::version, version, "version");
+    }
+
+    public static Matcher<UnitStatus> deploymentStatusIs(DeploymentStatus 
status) {
+        return replicationInfoMatcher(UnitStatus::status, status, "status");
+    }
+
+    /**
+     * Matcher fo
+     */
+    public static Matcher<UnitVersionStatus> unitVersionStatusIs(Version 
version, DeploymentStatus status) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("unitVersionStatus is 
").appendValue(version)
+                        .appendText(", status is ").appendValue(status);
+            }
+
+            @Override
+            protected boolean matchesSafely(UnitVersionStatus item) {
+                return item.getStatus() == status && 
Objects.equals(item.getVersion(), version);
+            }
+        };
+    }
+
+    public static Matcher<UnitStatuses> 
containsAll(Matcher<UnitVersionStatus>... unitVersionMatcher) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            protected boolean matchesSafely(UnitStatuses item) {
+                for (UnitVersionStatus versionStatus : item.versionStatuses()) 
{
+                    for (Matcher<UnitVersionStatus> unitVersionStatus : 
unitVersionMatcher) {
+                        if (unitVersionStatus.matches(versionStatus)) {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("a list containing elements matching: 
");
+                for (int i = 0; i < unitVersionMatcher.length; i++) {
+                    if (i > 0) {
+                        description.appendText(", ");
+                    }
+                    unitVersionMatcher[i].describeTo(description);
+                }
+            }
+        };
+    }
+
+    private static <T> Matcher<UnitStatus> replicationInfoMatcher(
+            Function<UnitStatus, T> extractor,
+            T actual,
+            String featureName
+    ) {
+        return new FeatureMatcher<>(is(actual), "unit status with " + 
featureName, featureName) {
+            @Override
+            protected T featureValueOf(UnitStatus actual) {
+                return extractor.apply(actual);
+            }
+        };
+    }
+
+    /**
+     * Matches that any item from list match with all provided matchers.
+     */
+    public static <T extends UnitStatus> Matcher<List<T>> 
any(Matcher<UnitStatus>... matchers) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("a list containing elements matching: 
");
+                for (int i = 0; i < matchers.length; i++) {
+                    if (i > 0) {
+                        description.appendText(", ");
+                    }
+                    matchers[i].describeTo(description);
+                }
+            }
+
+            @Override
+            protected boolean matchesSafely(List<T> item) {
+                for (Matcher<UnitStatus> matcher : matchers) {
+                    for (UnitStatus info : item) {
+                        if (matcher.matches(info)) {
+                            return true;
+                        }
+                    }
+                }
+
+                return false;
+            }
+        };
+    }
+
+    /**
+     * Matches that all items from list match with all provided matchers.
+     */
+    public static <T extends UnitStatus> Matcher<List<T>> 
all(Matcher<UnitStatus>... matchers) {

Review Comment:
   This looks like hamcrest `contains`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to